Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09caa48

Browse files
author
Gaurav Singh
committed
Added test to show use of POST method to create a new person and assert if it is present in get requests
1 parent edc7e8a commit 09caa48

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/people_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import requests
22
from assertpy.assertpy import assert_that
33

4+
from json import dumps
45
from config import BASE_URI
56
from utils.print_helpers import pretty_print
7+
from uuid import uuid4
68

79

810
def test_read_all_has_kent():
@@ -13,3 +15,23 @@ def test_read_all_has_kent():
1315
assert_that(response.status_code).is_equal_to(200)
1416
first_names = [people['fname'] for people in response_text]
1517
assert_that(first_names).contains('Kent')
18+
19+
20+
def test_new_person_can_be_added():
21+
unique_last_name = f'User {str(uuid4())}'
22+
payload = dumps({
23+
'fname': 'New',
24+
'lname': unique_last_name
25+
})
26+
27+
headers = {
28+
'Content-Type': 'application/json',
29+
'Accept': 'application/json'
30+
}
31+
32+
response = requests.post(url=BASE_URI, data=payload, headers=headers)
33+
assert_that(response.status_code).is_equal_to(204)
34+
35+
people = requests.get(BASE_URI).json()
36+
is_new_user_created = filter(lambda person: person['lname'] == unique_last_name, people)
37+
assert_that(is_new_user_created).is_true()

0 commit comments

Comments
 (0)