Skip to content

Commit d991d48

Browse files
committed
converting post to post_request layer refactoring post_tests to use the layer
1 parent 6136c08 commit d991d48

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

api_tests/posts_service.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from api_tests.globals import ApiHttpConstants
2+
3+
class post_requests():
4+
def get_all_posts(self,api):
5+
response = api.get("posts")
6+
return response
7+
8+
def get_post_by_number(self,api,post_number):
9+
response = api.get("posts/"+post_number)
10+
return response
11+
def create_post(self,api,payload):
12+
response = api.post("posts", data=payload)
13+
return response
14+
15+
def update_post(self,api,payload):
16+
response = api.put("posts/1", data=payload)
17+
return response
18+
19+
def delete_post(self,api,post_number):
20+
response = api.delete("posts/"+post_number)
21+
return response

api_tests/test_posts.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
from api_tests.globals import ApiHttpConstants
2+
from api_tests.posts_service import post_requests
23

34

45
def test_get_posts_count(api):
5-
response = api.get("posts")
6+
pr=post_requests()
7+
response = pr.get_all_posts(api)
68
assert response.status_code == ApiHttpConstants.OK
79
data = response.json()
810
assert len(data) == 100
911

1012
def test_get_post_number1(api):
11-
response = api.get("posts/1")
13+
pr = post_requests()
14+
response = pr.get_post_by_number(api,"1")
1215
assert response.status_code == ApiHttpConstants.OK
1316
data = response.json()
1417
assert data['userId'] == 1,"error in user id,expected 1"
@@ -22,7 +25,8 @@ def test_create_post(api):
2225
"title": "New test post",
2326
"body": "This is a body of the test post"
2427
}
25-
response = api.post("posts", data=payload)
28+
pr = post_requests()
29+
response = pr.create_post(api, payload)
2630
assert response.status_code == ApiHttpConstants.CREATED
2731
data = response.json()
2832
assert data["title"] == payload["title"],"data <> payload!"
@@ -34,10 +38,12 @@ def test_update_post(api):
3438
"body": "Updated body",
3539
"userId": 1
3640
}
37-
response = api.put("posts/1", data=payload)
41+
pr = post_requests()
42+
response = pr.update_post(api, payload)
3843
assert response.status_code == ApiHttpConstants.OK
3944
assert response.json()["title"] == "Updated title"
4045

41-
def test_delete_post(api):
42-
response = api.delete("posts/1")
46+
def test_delete_post_by_number(api):
47+
pr = post_requests()
48+
response = pr.delete_post(api,"1")
4349
assert response.status_code == ApiHttpConstants.OK

0 commit comments

Comments
 (0)