-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from montanizstills/feat/build-tools
Issue CRUD
- Loading branch information
Showing
5 changed files
with
153 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
**/.benchmarks/ | ||
**/.pytest_cache/ | ||
resources/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pytest==7.4.2 | ||
requests==2.31.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 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/" | ||
|
||
|
||
@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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,154 +1,129 @@ | ||
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 tearDown(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') |