Skip to content

Commit

Permalink
separate responses for different GitHub repo settings (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
beliaev-maksim authored Dec 17, 2024
1 parent d0380ae commit 7305729
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 16 deletions.
38 changes: 31 additions & 7 deletions tests/unit/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def test_comment_created_by_user(signature_mock):
responses._add_from_file(
UNITTESTS_DIR / "url_responses" / "issue_labeled_correct_for_existing_ticket.yaml"
)
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "auth_github_responses.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_auth.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_settings_with_labels.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "jira_auth_responses.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "jira_comment_created.yaml")
response = client.post(
Expand All @@ -62,7 +63,8 @@ def test_comment_created_by_user(signature_mock):
@responses.activate(assert_all_requests_are_fired=True)
def test_issue_labeled_correct(signature_mock):
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "issue_labeled_correct.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "auth_github_responses.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_auth.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_settings_with_labels.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "jira_auth_responses.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "jira_create_issue.yaml")
response = client.post(
Expand All @@ -87,7 +89,8 @@ def test_issue_created_with_label(signature_mock):
6. Validate via JQL that this issue does not exist in Jira
7. Create new issue in Jira
"""
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "auth_github_responses.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_auth.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_settings_with_labels.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "jira_auth_responses.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "issue_labeled_correct.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "jira_create_issue.yaml")
Expand Down Expand Up @@ -117,7 +120,8 @@ def test_issue_created_with_label_for_existing_ticket(signature_mock):
responses._add_from_file(
UNITTESTS_DIR / "url_responses" / "issue_labeled_correct_for_existing_ticket.yaml"
)
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "auth_github_responses.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_auth.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_settings_with_labels.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "jira_auth_responses.yaml")
response = client.post(
"/",
Expand All @@ -131,7 +135,25 @@ def test_issue_created_with_label_for_existing_ticket(signature_mock):
@responses.activate(assert_all_requests_are_fired=True)
def test_issue_created_without_label(signature_mock):
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "issue_created_without_label.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "auth_github_responses.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_auth.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_settings_with_labels.yaml")
response = client.post(
"/",
json=_get_json("issue_created_without_label.json"),
)

assert response.status_code == 200
assert response.json() == {"msg": "Issue is not labeled with the specified label"}


@responses.activate(assert_all_requests_are_fired=True)
def test_issue_created_without_label_and_no_config(signature_mock):
"""Test when issue is created without a label and repo config doesn't require one."""
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "issue_created_without_label.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_auth.yaml")
responses._add_from_file(
UNITTESTS_DIR / "url_responses" / "github_settings_without_labels.yaml"
)
response = client.post(
"/",
json=_get_json("issue_created_without_label.json"),
Expand All @@ -146,7 +168,8 @@ def test_issue_closed_as_completed(signature_mock):
responses._add_from_file(
UNITTESTS_DIR / "url_responses" / "issue_labeled_correct_for_existing_ticket.yaml"
)
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "auth_github_responses.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_auth.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_settings_with_labels.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "jira_auth_responses.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "jira_transition_issue.yaml")
response = client.post(
Expand All @@ -163,7 +186,8 @@ def test_issue_closed_as_not_planned(signature_mock):
responses._add_from_file(
UNITTESTS_DIR / "url_responses" / "issue_labeled_correct_for_existing_ticket.yaml"
)
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "auth_github_responses.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_auth.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "github_settings_with_labels.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "jira_auth_responses.yaml")
responses._add_from_file(UNITTESTS_DIR / "url_responses" / "jira_transition_issue.yaml")
response = client.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,3 @@ responses:
method: GET
status: 200
url: https://api.github.com:443/repos/beliaev-maksim/test-ci

# get content of .jira_sync_config.yaml to load the settings for the repo
- response:
auto_calculate_content_length: false
body: '{"name":".jira_sync_config.yaml","path":".github/.jira_sync_config.yaml","sha":"a1a8aab6de92fc3eed4211350200ada4a2405b9c","size":297,"url":"https://api.github.com/repos/beliaev-maksim/test-ci/contents/.github/.jira_sync_config.yaml?ref=master","html_url":"https://github.com/beliaev-maksim/test-ci/blob/master/.github/.jira_sync_config.yaml","git_url":"https://api.github.com/repos/beliaev-maksim/test-ci/git/blobs/a1a8aab6de92fc3eed4211350200ada4a2405b9c","download_url":"https://raw.githubusercontent.com/beliaev-maksim/test-ci/master/.github/.jira_sync_config.yaml","type":"file","content":"c2V0dGluZ3M6CiAgY29tcG9uZW50czoKICAgIC0gSW9UCiAgICAtIERBQ0ggVFQKICBsYWJlbHM6CiAgICAtIGJ1ZwogICAgLSBjdXN0b20KICBhZGRfZ2hfY29tbWVudDogZmFsc2UKICBzeW5jX2Rlc2NyaXB0aW9uOiB0cnVlCiAgc3luY19jb21tZW50czogdHJ1ZQogIGVwaWNfa2V5OiAiTVRDLTI5NiIKICBqaXJhX3Byb2plY3Rfa2V5OiAiTVRDIgogIHN0YXR1c19tYXBwaW5nOgogICAgb3BlbmVkOiBVbnRyaWFnZWQKICAgIGNsb3NlZDogZG9uZSAKICBsYWJlbF9tYXBwaW5nOgogICAgZW5oYW5jZW1lbnQ6IFN0b3J5Cg==","encoding":"base64","_links":{"self":"https://api.github.com/repos/beliaev-maksim/test-ci/contents/.github/.jira_sync_config.yaml?ref=master","git":"https://api.github.com/repos/beliaev-maksim/test-ci/git/blobs/a1a8aab6de92fc3eed4211350200ada4a2405b9c","html":"https://github.com/beliaev-maksim/test-ci/blob/master/.github/.jira_sync_config.yaml"}}'
content_type: text/plain
method: GET
status: 200
url: https://api.github.com:443/repos/beliaev-maksim/test-ci/contents/.github/.jira_sync_config.yaml
29 changes: 29 additions & 0 deletions tests/unit/url_responses/github_settings_with_labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# get content of .jira_sync_config.yaml to load the settings for the repo
responses:
- response:
auto_calculate_content_length: false
body: '{"name":".jira_sync_config.yaml","path":".github/.jira_sync_config.yaml","sha":"a1a8aab6de92fc3eed4211350200ada4a2405b9c","size":297,"url":"https://api.github.com/repos/beliaev-maksim/test-ci/contents/.github/.jira_sync_config.yaml?ref=master","html_url":"https://github.com/beliaev-maksim/test-ci/blob/master/.github/.jira_sync_config.yaml","git_url":"https://api.github.com/repos/beliaev-maksim/test-ci/git/blobs/a1a8aab6de92fc3eed4211350200ada4a2405b9c","download_url":"https://raw.githubusercontent.com/beliaev-maksim/test-ci/master/.github/.jira_sync_config.yaml","type":"file","content":"c2V0dGluZ3M6CiAgY29tcG9uZW50czoKICAgIC0gSW9UCiAgICAtIERBQ0ggVFQKICBsYWJlbHM6CiAgICAtIGJ1ZwogICAgLSBjdXN0b20KICBhZGRfZ2hfY29tbWVudDogZmFsc2UKICBzeW5jX2Rlc2NyaXB0aW9uOiB0cnVlCiAgc3luY19jb21tZW50czogdHJ1ZQogIGVwaWNfa2V5OiAiTVRDLTI5NiIKICBqaXJhX3Byb2plY3Rfa2V5OiAiTVRDIgogIHN0YXR1c19tYXBwaW5nOgogICAgb3BlbmVkOiBVbnRyaWFnZWQKICAgIGNsb3NlZDogZG9uZSAKICBsYWJlbF9tYXBwaW5nOgogICAgZW5oYW5jZW1lbnQ6IFN0b3J5Cg==","encoding":"base64","_links":{"self":"https://api.github.com/repos/beliaev-maksim/test-ci/contents/.github/.jira_sync_config.yaml?ref=master","git":"https://api.github.com/repos/beliaev-maksim/test-ci/git/blobs/a1a8aab6de92fc3eed4211350200ada4a2405b9c","html":"https://github.com/beliaev-maksim/test-ci/blob/master/.github/.jira_sync_config.yaml"}}'
content_type: text/plain
method: GET
status: 200
url: https://api.github.com:443/repos/beliaev-maksim/test-ci/contents/.github/.jira_sync_config.yaml


# That is the base64 encoded content
#settings:
# components:
# - IoT
# - DACH TT
# labels:
# - bug
# - custom
# add_gh_comment: false
# sync_description: true
# sync_comments: true
# epic_key: "MTC-296"
# jira_project_key: "MTC"
# status_mapping:
# opened: Untriaged
# closed: done
# label_mapping:
# enhancement: Story
27 changes: 27 additions & 0 deletions tests/unit/url_responses/github_settings_without_labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# get content of .jira_sync_config.yaml to load the settings for the repo
responses:
- response:
auto_calculate_content_length: false
body: '{"name":".jira_sync_config.yaml","path":".github/.jira_sync_config.yaml","sha":"a1a8aab6de92fc3eed4211350200ada4a2405b9c","size":297,"url":"https://api.github.com/repos/beliaev-maksim/test-ci/contents/.github/.jira_sync_config.yaml?ref=master","html_url":"https://github.com/beliaev-maksim/test-ci/blob/master/.github/.jira_sync_config.yaml","git_url":"https://api.github.com/repos/beliaev-maksim/test-ci/git/blobs/a1a8aab6de92fc3eed4211350200ada4a2405b9c","download_url":"https://raw.githubusercontent.com/beliaev-maksim/test-ci/master/.github/.jira_sync_config.yaml","type":"file","content":"c2V0dGluZ3M6CiAgY29tcG9uZW50czoKICAgIC0gSW9UCiAgICAtIERBQ0ggVFQKCiAgYWRkX2doX2NvbW1lbnQ6IGZhbHNlCiAgc3luY19kZXNjcmlwdGlvbjogdHJ1ZQogIHN5bmNfY29tbWVudHM6IHRydWUKICBlcGljX2tleTogIk1UQy0yOTYiCiAgamlyYV9wcm9qZWN0X2tleTogIk1UQyIKICBzdGF0dXNfbWFwcGluZzoKICAgIG9wZW5lZDogVW50cmlhZ2VkCiAgICBjbG9zZWQ6IGRvbmUgCiAgbGFiZWxfbWFwcGluZzoKICAgIGVuaGFuY2VtZW50OiBTdG9yeQo=","encoding":"base64","_links":{"self":"https://api.github.com/repos/beliaev-maksim/test-ci/contents/.github/.jira_sync_config.yaml?ref=master","git":"https://api.github.com/repos/beliaev-maksim/test-ci/git/blobs/a1a8aab6de92fc3eed4211350200ada4a2405b9c","html":"https://github.com/beliaev-maksim/test-ci/blob/master/.github/.jira_sync_config.yaml"}}'
content_type: text/plain
method: GET
status: 200
url: https://api.github.com:443/repos/beliaev-maksim/test-ci/contents/.github/.jira_sync_config.yaml


# That is the base64 encoded content
#settings:
# components:
# - IoT
# - DACH TT
#
# add_gh_comment: false
# sync_description: true
# sync_comments: true
# epic_key: "MTC-296"
# jira_project_key: "MTC"
# status_mapping:
# opened: Untriaged
# closed: done
# label_mapping:
# enhancement: Story

0 comments on commit 7305729

Please sign in to comment.