|
| 1 | +import pytest |
| 2 | +from src.jira_api import * |
| 3 | + |
| 4 | +api = JiraApi() |
| 5 | + |
| 6 | + |
| 7 | +class TestSuite: |
| 8 | + |
| 9 | + @allure.tag('api') |
| 10 | + @allure.title("Login via API") |
| 11 | + @pytest.mark.api |
| 12 | + @pytest.mark.parametrize("response,expected", [ |
| 13 | + (api.login("OlegAverkin", "fake"), [401, "AUTHENTICATED_FAILED"]), |
| 14 | + (api.login("fake", "OlegAverkin"), [401, "AUTHENTICATED_FAILED"]), |
| 15 | + (api.login("OlegAverkin", "OlegAverkin"), [200, "OK"]), ]) |
| 16 | + def test_login_to_jira(self, response, expected): |
| 17 | + assert response == expected |
| 18 | + |
| 19 | + @allure.tag('api') |
| 20 | + @allure.title("Post issue") |
| 21 | + @pytest.mark.api |
| 22 | + def test_post_issue(self): |
| 23 | + response = api.post_issue("OA API Issue001", "OlegAverkin", "Low") |
| 24 | + assert response.status_code == 201 |
| 25 | + |
| 26 | + @allure.tag('api') |
| 27 | + @allure.title("Update issue") |
| 28 | + @pytest.mark.api |
| 29 | + def test_update_issue(self): |
| 30 | + response = api.post_issue("OA API Issue002 ", "OlegAverkin", "Medium") |
| 31 | + issue_id = response.json().get('id') |
| 32 | + response_update = api.update_issue(issue_id, "OA API Issue002 Updated", "OlegAverkin", "Low") |
| 33 | + assert response_update.status_code == 204 |
| 34 | + |
| 35 | + @allure.tag('api') |
| 36 | + @allure.title("Post multiple issues") |
| 37 | + @pytest.mark.api |
| 38 | + @pytest.mark.parametrize("response,expected", [ |
| 39 | + (api.post_issue("OA API Issue003", "OlegAverkin", "Low"), 201), |
| 40 | + (api.post_issue("OA API Issue004", "OlegAverkin", "Low"), 201), |
| 41 | + (api.post_issue("OA API Issue005", "OlegAverkin", "Low"), 201), |
| 42 | + (api.post_issue("OA API Issue006", "OlegAverkin", "Low"), 201)]) |
| 43 | + def test_post_issues(self, response, expected): |
| 44 | + assert response.status_code == expected |
| 45 | + |
| 46 | + @allure.tag('api') |
| 47 | + @allure.title("Missing required fields") |
| 48 | + @pytest.mark.api |
| 49 | + def test_post_issue_missing_fields(self): |
| 50 | + response = api.post_issue("", "OlegAverkin", "Low") |
| 51 | + assert response.status_code == 400 |
| 52 | + assert response.json().get('errors').get('summary') == "You must specify a summary of the issue." |
| 53 | + |
| 54 | + @allure.tag('api') |
| 55 | + @allure.title("Long summary") |
| 56 | + @pytest.mark.api |
| 57 | + def test_post_issue_long_summary(self): |
| 58 | + response = api.post_issue("AO" * 256, "OlegAverkin", "Low") |
| 59 | + assert response.status_code == 400 |
| 60 | + assert response.json().get('errors').get('summary') == "Summary must be less than 255 characters." |
| 61 | + |
| 62 | + @allure.tag('api') |
| 63 | + @allure.title("Test search issue") |
| 64 | + @pytest.mark.api |
| 65 | + def test_search_1_issue(self): |
| 66 | + response = api.search_issue("Issue001") |
| 67 | + assert response.status_code == 200 |
| 68 | + assert response.json().get('total') == 1 |
| 69 | + |
| 70 | + @allure.tag('api') |
| 71 | + @allure.title("Test five issue") |
| 72 | + @pytest.mark.api |
| 73 | + def test_search_5_issues(self): |
| 74 | + response = api.search_issue("OA") |
| 75 | + assert response.status_code == 200 |
| 76 | + assert response.json().get('total') == 6 |
| 77 | + |
| 78 | + @allure.tag('api') |
| 79 | + @allure.title("Test search unknown issue") |
| 80 | + @pytest.mark.api |
| 81 | + def test_search_none_issue(self): |
| 82 | + response = api.search_issue("somethingwrong") |
| 83 | + assert response.status_code == 200 |
| 84 | + assert response.json().get('total') == 0 |
| 85 | + |
| 86 | + @allure.tag('api') |
| 87 | + @allure.title("Delete all issues") |
| 88 | + @pytest.mark.api |
| 89 | + def test_delete_all_issues(self): |
| 90 | + response = api.delete_all_issues() |
| 91 | + assert len(response) == 6 |
0 commit comments