diff --git a/tests/unit/test_server.py b/tests/unit/test_server.py index b2c6300..fa3edd0 100644 --- a/tests/unit/test_server.py +++ b/tests/unit/test_server.py @@ -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( @@ -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( @@ -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") @@ -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( "/", @@ -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"), @@ -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( @@ -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( diff --git a/tests/unit/url_responses/auth_github_responses.yaml b/tests/unit/url_responses/github_auth.yaml similarity index 82% rename from tests/unit/url_responses/auth_github_responses.yaml rename to tests/unit/url_responses/github_auth.yaml index 563f841..601fbdb 100644 --- a/tests/unit/url_responses/auth_github_responses.yaml +++ b/tests/unit/url_responses/github_auth.yaml @@ -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 \ No newline at end of file diff --git a/tests/unit/url_responses/github_settings_with_labels.yaml b/tests/unit/url_responses/github_settings_with_labels.yaml new file mode 100644 index 0000000..d7f22d4 --- /dev/null +++ b/tests/unit/url_responses/github_settings_with_labels.yaml @@ -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 \ No newline at end of file diff --git a/tests/unit/url_responses/github_settings_without_labels.yaml b/tests/unit/url_responses/github_settings_without_labels.yaml new file mode 100644 index 0000000..1c19175 --- /dev/null +++ b/tests/unit/url_responses/github_settings_without_labels.yaml @@ -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 \ No newline at end of file