From 02a56e67b162ab4fa3a98be6ac1ef5fd9dce5827 Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 02:02:31 -0400 Subject: [PATCH 01/14] feat(dependencies): add requirements.txt; --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..de1887b --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pytest==7.4.2 \ No newline at end of file From 2362524e9e50e514b9ab6075d32e00bae60b6c1f Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 02:07:30 -0400 Subject: [PATCH 02/14] feat(dependencies): upgrade pip in action file before test(s) execution; --- .github/workflows/deploy-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index e7a5566..af93aca 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -18,6 +18,7 @@ jobs: - name: Install Pip run: | + pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt fi From e38ee8d1894578ec92cb15fee06ee75a603562f4 Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 02:13:53 -0400 Subject: [PATCH 03/14] feat(dependencies): add requests to requirements.txt; test(deploy-test):remove pip upgrade; --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index de1887b..d4d0c34 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -pytest==7.4.2 \ No newline at end of file +pytest==7.4.2 +requests==2.31.0 \ No newline at end of file From 33c6d201829ad266e93224784e88f47521c441fd Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 02:14:30 -0400 Subject: [PATCH 04/14] feat(dependencies): add requests to requirements.txt; test(deploy-test):remove pip upgrade; --- .github/workflows/deploy-test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index af93aca..e7a5566 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -18,7 +18,6 @@ jobs: - name: Install Pip run: | - pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt fi From 5d617c235a2dc284a7d2831aa72088a969364b52 Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 13:16:23 -0400 Subject: [PATCH 05/14] test(deploy-test): add env target; --- .github/workflows/deploy-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index e7a5566..2a6ecd8 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -8,6 +8,7 @@ on: jobs: unit_test: + environment: DEVELOPMENT runs-on: ubuntu-latest steps: - name: Checkout From b28c243e78bbf5b4fbdfae64a43dfed916474c56 Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 13:22:42 -0400 Subject: [PATCH 06/14] test(deploy-test): add env vars for action file to pass to test(s); update teardown method to class cleanup stub; --- .github/workflows/deploy-test.yml | 6 +++++- src/tests/test_issue.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index 2a6ecd8..65c37df 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -8,7 +8,7 @@ on: jobs: unit_test: - environment: DEVELOPMENT +# environment: DEVELOPMENT runs-on: ubuntu-latest steps: - name: Checkout @@ -24,5 +24,9 @@ jobs: fi - name: Execute Tests + env: + JIRA_URL: ${{ vars.JIRA_URL }} + JIRA_AUTH_EMAIL: ${{ vars.JIRA_AUTH_EMAIL }} + JIRA_API_KEY: $ {{ secrets.JIRA_API_KEY }} run: | python -m pytest -s src/tests diff --git a/src/tests/test_issue.py b/src/tests/test_issue.py index 08719c2..6cec69b 100644 --- a/src/tests/test_issue.py +++ b/src/tests/test_issue.py @@ -20,7 +20,7 @@ def setUp(self): "Content-Type": "application/json", } - def tearDown(self) -> None: + def doClassCleanups(self) -> None: # clean up board after all tests # clean up after create # clean up after read From ae75c7827b77c18a9d754ff31378fda4adc34193 Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 15:33:22 -0400 Subject: [PATCH 07/14] feat(build-tools): create conftest.py; update tests to use conftest; remove usage of unittest library; add pytest files to gitignore; --- .gitignore | 2 + src/tests/conftest.py | 29 +++++ src/tests/test_issue.py | 252 ++++++++++++++++++---------------------- 3 files changed, 144 insertions(+), 139 deletions(-) create mode 100644 src/tests/conftest.py diff --git a/.gitignore b/.gitignore index 07cf801..b77d318 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +**/.benchmarks/ +**/.pytest_cache/ resources/ \ No newline at end of file diff --git a/src/tests/conftest.py b/src/tests/conftest.py new file mode 100644 index 0000000..f69b79d --- /dev/null +++ b/src/tests/conftest.py @@ -0,0 +1,29 @@ +import json +import os + +import pytest +from requests.auth import HTTPBasicAuth + + +@pytest.fixture(scope='session') +def headers(): + return { + "Content-Type": "application/json", + } + + +@pytest.fixture(scope='session') +def url(): + return os.environ.get("JIRA_URL") if os.environ.get( + "JIRA_URL") else f"{json.load(open('../../resources/jira-credentials.json'))['jira_url']}/rest/api/2/issue/" + + +@pytest.fixture(scope='session') +def basic_auth(): + auth_email = os.environ.get("JIRA_AUTH_EMAIL") if os.environ.get("JIRA_AUTH_EMAIL") else \ + json.load(open('../../resources/jira-credentials.json'))['jira_auth_email'] + + token = os.environ.get("JIRA_API_KEY") if os.environ.get("JIRA_API_KEY") else \ + json.load(open('../../resources/jira-credentials.json'))['jira_api_key'] + + return HTTPBasicAuth(auth_email, token) diff --git a/src/tests/test_issue.py b/src/tests/test_issue.py index 6cec69b..fd6bccd 100644 --- a/src/tests/test_issue.py +++ b/src/tests/test_issue.py @@ -1,154 +1,128 @@ -import json -import os -import unittest - -from requests.auth import HTTPBasicAuth - from src.main import issue -class IssueTest(unittest.TestCase): - def setUp(self): - self.jira_auth_email = os.environ.get("JIRA_AUTH_EMAIL") if os.environ.get("JIRA_AUTH_EMAIL") else \ - json.load(open('../../resources/jira-credentials.json'))['jira_auth_email'] - self.token = os.environ.get("JIRA_API_KEY") if os.environ.get("JIRA_API_KEY") else \ - json.load(open('../../resources/jira-credentials.json'))['jira_api_key'] - self.url = os.environ.get("JIRA_URL") if os.environ.get( - "JIRA_URL") else f"{json.load(open('../../resources/jira-credentials.json'))['jira_url']}/rest/api/2/issue/" - self.basic_auth = HTTPBasicAuth(self.jira_auth_email, self.token) - self.headers = { - "Content-Type": "application/json", - } - - def doClassCleanups(self) -> None: - # clean up board after all tests - # clean up after create - # clean up after read - # clean up after update - pass - - def test_create_issue(self): - # create story - # create bug - # create epic - # create subtask - - # given - data = { - "fields": { - "project": { - "key": "SAGC" - }, - "summary": "Test Issue - Create_for_Read_Test", - "description": "This issue is created to be read, then deleted.", - "issuetype": { - "name": "Story" # case-sensitive - } +def test_create_issue(url, headers, basic_auth): + # create story + # create bug + # create epic + # create subtask + + # given + data = { + "fields": { + "project": { + "key": "SAGC" + }, + "summary": "Test Issue - Create", + "description": "This issue is created to unit test issue.create_issue.", + "issuetype": { + "name": "Story" # case-sensitive } } - - # when - response = issue.create_issue(self.url, self.headers, self.basic_auth, data).json() - - # then - self.assertTrue(response.get('id')) - self.assertTrue(response.get('key')) - self.assertTrue(response.get('self')) - - def test_read_issue(self): - # positive test for when issue exists - # given - data = { - "fields": { - "project": { - "key": "SAGC" - }, - "summary": "Issue summary2", - "description": "Issue description", - "issuetype": { - "name": "Story" - } + } + + # when + response = issue.create_issue(url, headers, basic_auth, data).json() + + # then + assert response.get('id') + assert response.get('key') + + +def test_read_issue(url, headers, basic_auth): + # positive test for when issue exists + # given + data = { + "fields": { + "project": { + "key": "SAGC" + }, + "summary": "Test Issue - Create_for_Read_Test", + "description": "This issue is created to be read, then deleted.", + "issuetype": { + "name": "Story" # case-sensitive } } - - # when - response = issue.create_issue(self.url, self.headers, self.basic_auth, data).json() - issue_key = response.get('key') - response = issue.read_issue(self.url, self.headers, self.basic_auth, issue_key).json() - - # then - self.assertEqual('Story', response.get('fields').get('issuetype').get('name')) - self.assertIn(data.get('fields').get('project').get('key'), response.get('key')) - - # negative test for when issue does not exist - # TODO - - def test_update_issue(self): - # positive test for when issue exists - # given - start = { - "fields": { - "project": { - "key": "SAGC" - }, - "summary": "Test Issue - Updated - Start", - "description": "This is the description when the issue is first created", - "issuetype": { - "name": "Story" - } + } + expected = data.get('fields').get('project').get('key') + + # when + response = issue.create_issue(url, headers, basic_auth, data).json() + issue_key = response.get('key') + response = issue.read_issue(url, headers, basic_auth, issue_key).json() + + # then + actual = response.get('key') + assert 'Story' == response.get('fields').get('issuetype').get('name') + assert expected in actual, f"Expected {expected}, but got {actual}" + + # negative test for when issue does not exist + # TODO + + +def test_update_issue(url, headers, basic_auth): + # positive test for when issue exists + # given + start = { + "fields": { + "project": { + "key": "SAGC" + }, + "summary": "Test Issue - Updated - Start", + "description": "This is the description when the issue is first created", + "issuetype": { + "name": "Story" } } - end = { - "fields": { - "project": { - "key": "SAGC" - }, - "summary": "Test Issue - Updated - End", - "description": "This is the description after the issue has been updated.", - "issuetype": { - "name": "Bug" - } + } + end = { + "fields": { + "project": { + "key": "SAGC" + }, + "summary": "Test Issue - Updated - End", + "description": "This is the description after the issue has been updated.", + "issuetype": { + "name": "Bug" } } - - # when - issue_key = issue.create_issue(self.url, self.headers, self.basic_auth, start).json().get('key') - issue.update_issue(self.url, self.headers, self.basic_auth, issue_key, end) - updated_issue_json = issue.read_issue(self.url, self.headers, self.basic_auth, issue_key).json() - - # then - self.assertEqual(end.get('description'), updated_issue_json.get('description'), - f"Expected {end.get('description')}, but got {updated_issue_json.get('description')}") - - # negative test for when issue does not exist - # TODO - - def test_delete_issue(self): - # positive test for when issue exists - # given - data = { - "fields": { - "project": { - "key": "SAGC" - }, - "summary": "Test Issue - to be deleted", - "description": "This is the description of an issue you will never see.", - "issuetype": { - "name": "Story" - } + } + expected = end.get('description') + + # when + issue_key = issue.create_issue(url, headers, basic_auth, start).json().get('key') + issue.update_issue(url, headers, basic_auth, issue_key, end) + updated_issue_json = issue.read_issue(url, headers, basic_auth, issue_key).json() + actual = updated_issue_json.get('description') + + # then + assert expected == actual, f"Expected {expected}, but got {actual}" + + # negative test for when issue does not exist + # TODO + +def test_delete_issue(url, headers, basic_auth): + # positive test for when issue exists + # given + data = { + "fields": { + "project": { + "key": "SAGC" + }, + "summary": "Test Issue - to be deleted", + "description": "This is the description of an issue you will never see.", + "issuetype": { + "name": "Story" } } + } - # when - response = issue.create_issue(self.url, self.headers, self.basic_auth, data).json() - issue_key = response.get('key') - delete_response = issue.delete_issue(self.url, self.headers, self.basic_auth, issue_key) - error_json = issue.read_issue(self.url, self.headers, self.basic_auth, issue_key).json() - - # then - assert delete_response.status_code == 204 - assert 'Issue does not exist or you do not have permission to see it.' in error_json.get('errorMessages') - + # when + response = issue.create_issue(url, headers, basic_auth, data).json() + issue_key = response.get('key') + delete_response = issue.delete_issue(url, headers, basic_auth, issue_key) + error_json = issue.read_issue(url, headers, basic_auth, issue_key).json() -if __name__ == "__main__": - unittest.main() + # then + assert delete_response.status_code == 204 + assert 'Issue does not exist or you do not have permission to see it.' in error_json.get('errorMessages') From fcb8206cd9d263301e03732498c97994b4aef1bb Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 16:05:00 -0400 Subject: [PATCH 08/14] test(deploy-test): use environment without explict env var delcration during test step; --- .github/workflows/deploy-test.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index 65c37df..2a6ecd8 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -8,7 +8,7 @@ on: jobs: unit_test: -# environment: DEVELOPMENT + environment: DEVELOPMENT runs-on: ubuntu-latest steps: - name: Checkout @@ -24,9 +24,5 @@ jobs: fi - name: Execute Tests - env: - JIRA_URL: ${{ vars.JIRA_URL }} - JIRA_AUTH_EMAIL: ${{ vars.JIRA_AUTH_EMAIL }} - JIRA_API_KEY: $ {{ secrets.JIRA_API_KEY }} run: | python -m pytest -s src/tests From 7fe1a724770b630d530b5a5b48f1cba529419d2d Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 16:12:42 -0400 Subject: [PATCH 09/14] test(deploy-test): upgrade pip; add debugging; --- .github/workflows/deploy-test.yml | 1 + src/tests/conftest.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index 2a6ecd8..d1df368 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -19,6 +19,7 @@ jobs: - name: Install Pip run: | + pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt fi diff --git a/src/tests/conftest.py b/src/tests/conftest.py index f69b79d..4fcfcf2 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -14,6 +14,10 @@ def headers(): @pytest.fixture(scope='session') def url(): + if os.environ.get("JIRA_URL"): + print(os.environ.get("JIRA_URL")) + else: + print("No environment variable found for URL") return os.environ.get("JIRA_URL") if os.environ.get( "JIRA_URL") else f"{json.load(open('../../resources/jira-credentials.json'))['jira_url']}/rest/api/2/issue/" From 3f8cb6d8e37948af4580815b3722263312991b69 Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 16:14:11 -0400 Subject: [PATCH 10/14] test(deploy-test): add debugging; --- src/tests/conftest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tests/conftest.py b/src/tests/conftest.py index 4fcfcf2..8090373 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -27,6 +27,8 @@ def basic_auth(): auth_email = os.environ.get("JIRA_AUTH_EMAIL") if os.environ.get("JIRA_AUTH_EMAIL") else \ json.load(open('../../resources/jira-credentials.json'))['jira_auth_email'] + print(auth_email) + token = os.environ.get("JIRA_API_KEY") if os.environ.get("JIRA_API_KEY") else \ json.load(open('../../resources/jira-credentials.json'))['jira_api_key'] From 37dd95225a11a8b5b8ed0b15d45a50dd77ee6a56 Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 20:12:15 -0400 Subject: [PATCH 11/14] test(deploy-test): remove second option in conftest.py; --- src/tests/conftest.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/tests/conftest.py b/src/tests/conftest.py index 8090373..e857ab3 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -14,22 +14,13 @@ def headers(): @pytest.fixture(scope='session') def url(): - if os.environ.get("JIRA_URL"): - print(os.environ.get("JIRA_URL")) - else: - print("No environment variable found for URL") - return os.environ.get("JIRA_URL") if os.environ.get( - "JIRA_URL") else f"{json.load(open('../../resources/jira-credentials.json'))['jira_url']}/rest/api/2/issue/" + return os.environ.get("JIRA_URL") @pytest.fixture(scope='session') def basic_auth(): - auth_email = os.environ.get("JIRA_AUTH_EMAIL") if os.environ.get("JIRA_AUTH_EMAIL") else \ - json.load(open('../../resources/jira-credentials.json'))['jira_auth_email'] + auth_email = os.environ.get("JIRA_AUTH_EMAIL") - print(auth_email) - - token = os.environ.get("JIRA_API_KEY") if os.environ.get("JIRA_API_KEY") else \ - json.load(open('../../resources/jira-credentials.json'))['jira_api_key'] + token = os.environ.get("JIRA_API_KEY") return HTTPBasicAuth(auth_email, token) From 27e534a096eb7b5d856a7cb7c944c90e852af77d Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 20:18:34 -0400 Subject: [PATCH 12/14] test(deploy-test): create local env vars to action file; --- .github/workflows/deploy-test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index d1df368..bd050f3 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -25,5 +25,9 @@ jobs: fi - name: Execute Tests + env: + JIRA_URL: ${{ vars.JIRA_URL }} + JIRA_AUTH_EMAIL: ${{ vars.JIRA_AUTH_EMAIL }} + JIRA_API_KEY: $ {{ secrets.JIRA_API_KEY }} run: | python -m pytest -s src/tests From a8d924792cf9d416dddf3d214b6cdcc183c9dd0c Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 20:25:50 -0400 Subject: [PATCH 13/14] test(deploy-test): add second option to conftest.py; --- .github/workflows/deploy-test.yml | 2 +- src/tests/conftest.py | 9 ++++++--- src/tests/test_issue.py | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index bd050f3..8a5ea25 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -28,6 +28,6 @@ jobs: env: JIRA_URL: ${{ vars.JIRA_URL }} JIRA_AUTH_EMAIL: ${{ vars.JIRA_AUTH_EMAIL }} - JIRA_API_KEY: $ {{ secrets.JIRA_API_KEY }} + JIRA_API_KEY: ${{ secrets.JIRA_API_KEY }} run: | python -m pytest -s src/tests diff --git a/src/tests/conftest.py b/src/tests/conftest.py index e857ab3..f69b79d 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -14,13 +14,16 @@ def headers(): @pytest.fixture(scope='session') def url(): - return os.environ.get("JIRA_URL") + return os.environ.get("JIRA_URL") if os.environ.get( + "JIRA_URL") else f"{json.load(open('../../resources/jira-credentials.json'))['jira_url']}/rest/api/2/issue/" @pytest.fixture(scope='session') def basic_auth(): - auth_email = os.environ.get("JIRA_AUTH_EMAIL") + auth_email = os.environ.get("JIRA_AUTH_EMAIL") if os.environ.get("JIRA_AUTH_EMAIL") else \ + json.load(open('../../resources/jira-credentials.json'))['jira_auth_email'] - token = os.environ.get("JIRA_API_KEY") + token = os.environ.get("JIRA_API_KEY") if os.environ.get("JIRA_API_KEY") else \ + json.load(open('../../resources/jira-credentials.json'))['jira_api_key'] return HTTPBasicAuth(auth_email, token) diff --git a/src/tests/test_issue.py b/src/tests/test_issue.py index fd6bccd..6cd2ce8 100644 --- a/src/tests/test_issue.py +++ b/src/tests/test_issue.py @@ -101,6 +101,7 @@ def test_update_issue(url, headers, basic_auth): # negative test for when issue does not exist # TODO + def test_delete_issue(url, headers, basic_auth): # positive test for when issue exists # given From cea29028d8b5006e0c85586b77075ae5a9a80f46 Mon Sep 17 00:00:00 2001 From: "Montaniz.Stills" Date: Sun, 17 Sep 2023 20:36:27 -0400 Subject: [PATCH 14/14] test(deploy-test): fix url; --- src/tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/conftest.py b/src/tests/conftest.py index f69b79d..d900ded 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -14,7 +14,7 @@ def headers(): @pytest.fixture(scope='session') def url(): - return os.environ.get("JIRA_URL") if os.environ.get( + return f'{os.environ.get("JIRA_URL")}/rest/api/2/issue/' if os.environ.get( "JIRA_URL") else f"{json.load(open('../../resources/jira-credentials.json'))['jira_url']}/rest/api/2/issue/"