1
1
from json import dumps
2
2
from uuid import uuid4
3
-
4
3
import requests
5
4
from assertpy .assertpy import assert_that , soft_assertions
6
-
7
5
from config import BASE_URI
8
6
9
7
@@ -14,20 +12,18 @@ def test_read_all_has_kent():
14
12
# stop the Test script's execution). It will Collect all the failed tests, consolidate all of them with the errors
15
13
# and return all the failed test failures in last with the failure messages.
16
14
with soft_assertions ():
17
- # response from requests has many useful properties
15
+ # response from requests has many useful properties.
18
16
# we can assert on the response status code
19
17
assert_that (response .status_code ).is_equal_to (requests .codes .ok )
20
- # We can get python dict as response by using .json() method
18
+ # We can convert the JSON to --> Python Dictionary as response by using .json() method
21
19
response_content = response .json ()
22
-
23
20
# Use assertpy's fluent assertions to extract all fnames and then see the result is non-empty and has
24
- # Kent in it.
21
+ # ' Kent' user in it.
25
22
assert_that (response_content ).extracting ('fname' ).is_not_empty ().contains ('Kent' )
26
23
27
24
28
25
def test_new_person_can_be_added ():
29
26
unique_last_name = create_new_person ()
30
-
31
27
# After user is created, we read all the users and then use filter expression to find if the
32
28
# created user is present in the response list
33
29
peoples = requests .get (BASE_URI ).json ()
@@ -37,10 +33,8 @@ def test_new_person_can_be_added():
37
33
38
34
def test_created_person_can_be_deleted ():
39
35
persons_last_name = create_new_person ()
40
-
41
36
peoples = requests .get (BASE_URI ).json ()
42
37
newly_created_user = search_created_user_in (peoples , persons_last_name )[0 ]
43
-
44
38
delete_url = f'{ BASE_URI } /{ newly_created_user ["person_id" ]} '
45
39
response = requests .delete (delete_url )
46
40
assert_that (response .status_code ).is_equal_to (requests .codes .ok )
@@ -54,15 +48,12 @@ def create_new_person():
54
48
'fname' : 'New' ,
55
49
'lname' : unique_last_name
56
50
})
57
-
58
- # Setting default headers to show that the client accepts json
59
- # And will send json in the headers
51
+ # Setting default headers to show that the client accepts json and will send the json in the headers
60
52
headers = {
61
53
'Content-Type' : 'application/json' ,
62
54
'Accept' : 'application/json'
63
55
}
64
-
65
- # We use requests.post method with keyword params to make the request more readable
56
+ # We use requests.post() method with keyword params to make the request more readable
66
57
response = requests .post (url = BASE_URI , data = payload , headers = headers )
67
58
assert_that (response .status_code , description = 'Person not created' ).is_equal_to (requests .codes .no_content )
68
59
return unique_last_name
0 commit comments