Skip to content

Commit 48026bc

Browse files
author
“unaisLearning”
committed
Implemented allure helper and allure title for tests
1 parent 1fcec51 commit 48026bc

6 files changed

Lines changed: 45 additions & 14 deletions

File tree

tests/test_create_user.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from utils.logger import get_logger
33
import allure
44
import pytest
5+
from utils.allure_helper import attach_payload,attach_response
56

67
@pytest.mark.api
78
@pytest.mark.regression
@@ -10,10 +11,21 @@
1011
def test_create_user(client):
1112
logger = get_logger(__name__)
1213
logger.info("Starting test_create_user")
14+
15+
1316
payload = create_user_payload()
17+
18+
attach_payload(
19+
payload,
20+
"Create User Payload"
21+
)
1422
response = client.create_user(payload)
1523
body = response.json()
16-
print(response.text)
24+
25+
attach_response(
26+
response,
27+
"Create User Response"
28+
)
1729
assert response.status_code == 201
1830

1931
assert body["name"] == payload["name"]

tests/test_update_user.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22
from utils.logger import get_logger
33
import allure
44
import pytest
5+
from utils.allure_helper import attach_response,attach_payload
56

67
@pytest.mark.api
78
@pytest.mark.regression
89
@allure.title("Successfully updated user")
910
def test_update_user(client):
1011
logger = get_logger(__name__)
1112
logger.info("Starting test_update_user")
12-
response = client.update_user(2,update_user_payload())
13-
14-
allure.attach(
15-
response.text,
16-
name="Response Body",
17-
attachment_type=allure.attachment_type.JSON
18-
)
13+
payload = update_user_payload()
14+
attach_payload(payload,"Update User Payload")
15+
response = client.update_user(2,payload)
1916

2017
assert response.status_code == 200
2118
body = response.json()
2219

20+
attach_response(response, "Update user Response")
21+
2322
assert body["name"] == "sam Updated"
2423
assert body["job"] == "QA Lead"
2524
assert "updatedAt" in body

tests/test_users.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from utils.validator import validate_json
33
import allure
44
import pytest
5+
from utils.allure_helper import attach_response
56

67
@pytest.mark.api
78
@pytest.mark.regression
@@ -12,14 +13,9 @@ def test_get_user(client):
1213
logger.info("Starting test_get_user")
1314
response = client.get_single_user(2)
1415

15-
allure.attach(
16-
response.text,
17-
name= "Response Body",
18-
attachment_type=allure.attachment_type.JSON
19-
)
20-
2116
body = response.json()
2217

18+
attach_response(response, "Users Response Body")
2319
assert response.status_code == 200
2420
assert body["data"]["id"] == 2
2521
assert body ["data"]["email"] is not None

tests/test_users_negative.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
from utils.logger import get_logger
22
import pytest
3+
from utils.allure_helper import attach_response
4+
import allure
35

46
@pytest.mark.api
57
@pytest.mark.regression
8+
@allure.title("Return 404 for non-existing user")
69
def test_non_existing_user(client):
710
logger = get_logger(__name__)
811
logger.info("Starting test_non_existing_user")
912
response = client.get_single_user(999)
1013

14+
attach_response(response,"Non-Existing User Response")
1115
assert response.status_code == 404
1216

1317
logger.info("Test passed")

tests/test_users_pagination.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
from utils.logger import get_logger
22
import pytest
3+
from utils.allure_helper import attach_response
4+
import allure
35

46
@pytest.mark.api
57
@pytest.mark.regression
8+
@allure.title("Successfully fetch users on page 2")
69
def test_get_user_page_2(client):
710
logger = get_logger(__name__)
811
logger.info("Starting test_get_user_page_2")
912
response = client.get_users_by_page(2)
1013
body = response.json()
1114

15+
attach_response(response, "Pagination Response")
1216
assert response.status_code == 200
1317
assert body["page"] == 2
1418

utils/allure_helper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import json
2+
import allure
3+
4+
def attach_payload(payload, name="Request Payload"):
5+
allure.attach(
6+
json.dumps(payload, indent=4),
7+
name=name,
8+
attachment_type=allure.attachment_type.JSON
9+
)
10+
11+
def attach_response(response, name="Response Body"):
12+
allure.attach(
13+
json.dumps(response.json(), indent=4),
14+
name=name,
15+
attachment_type=allure.attachment_type.JSON
16+
)

0 commit comments

Comments
 (0)