Skip to content

Commit 85b1456

Browse files
Updated the Comments.
1 parent 321397f commit 85b1456

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# updated the below URL from : http://0.0.0.0:5000/ to below URL to run the URL on windows machine!
1+
# updated the below URL from : http://0.0.0.0:5000/ to below URL to run the URL on Windows machine!
22
BASE_URI = 'http://127.0.0.1:5000/api/people'

tests/people_test.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from json import dumps
22
from uuid import uuid4
3-
43
import requests
54
from assertpy.assertpy import assert_that
6-
75
from config import BASE_URI
86
from utils.print_helpers import pretty_print
97

@@ -12,11 +10,10 @@ def test_read_all_has_kent():
1210
# We use requests.get() with url to make a get request
1311
response = requests.get(BASE_URI)
1412
# response from requests has many useful properties
15-
# we can assert on the response status code
1613
print(response.status_code)
1714
print(requests.codes.ok)
1815
assert_that(response.status_code).is_equal_to(requests.codes.ok)
19-
# We can get python dict as response by using .json() method
16+
# Note : To Convert the JSON data into the Python Dictionary use - json() method.
2017
peoples = response.json()
2118
# pretty_print() is a module from python that indents the json response in a more readable way.
2219
pretty_print(peoples)
@@ -36,34 +33,28 @@ def test_new_person_can_be_added():
3633

3734
def test_created_person_can_be_deleted():
3835
persons_last_name = create_new_person()
39-
4036
peoples = requests.get(BASE_URI).json()
4137
newly_created_user = search_created_user_in(peoples, persons_last_name)[0]
42-
4338
delete_url = f'{BASE_URI}/{newly_created_user["person_id"]}'
4439
response = requests.delete(delete_url)
4540
assert_that(response.status_code).is_equal_to(requests.codes.ok)
4641

4742

4843
def create_new_person():
4944
# Ensure a user with a unique last name is created everytime the test runs
50-
# Note: json.dumps() is used to convert python dict to json string
5145
unique_last_name = f'User {str(uuid4())}'
5246
print(str(uuid4()))
53-
# dumps() is a method that takes the python dictionary and converts it into json string
47+
# Note: json.dumps() or dumps() method - is used to convert the Python dictionary to JSON String
5448
payload = dumps({
5549
'fname': 'New',
5650
'lname': unique_last_name
5751
})
58-
59-
# Setting default headers to show that the client accepts json
60-
# And will send json in the headers
52+
# Setting default headers to show that the client accepts json and will send the json in the headers
6153
headers = {
6254
'Content-Type': 'application/json',
6355
'Accept': 'application/json'
6456
}
65-
66-
# We use requests.post method with keyword params to make the request more readable
57+
# We use requests.post() method with keyword params to make the request more readable
6758
response = requests.post(url=BASE_URI, data=payload, headers=headers)
6859
print(response.status_code)
6960
assert_that(response.status_code, description='Person not created').is_equal_to(requests.codes.no_content)
@@ -72,4 +63,4 @@ def create_new_person():
7263

7364

7465
def search_created_user_in(peoples, last_name):
75-
return [person for person in peoples if person['lname'] == last_name]
66+
return [person for person in peoples if person['lname'] == last_name]

0 commit comments

Comments
 (0)