Skip to content

Commit 3aa6753

Browse files
config file : updated the url for windows platform from :
'http://0.0.0.0:5000/api/people' to 'http://127.0.0.1:5000/api/people' people_test file : printed few values to get the values and understand the code. Pipfile : updated the Python version
1 parent 3f9fc63 commit 3aa6753

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ pytest = "*"
1111
assertpy = "*"
1212

1313
[requires]
14-
python_version = "3.8"
14+
python_version = "3.9"

config.py

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

tests/people_test.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@
55
from assertpy.assertpy import assert_that
66

77
from config import BASE_URI
8+
from utils.print_helpers import pretty_print
89

910

1011
def test_read_all_has_kent():
1112
# We use requests.get() with url to make a get request
1213
response = requests.get(BASE_URI)
1314
# response from requests has many useful properties
1415
# we can assert on the response status code
16+
print(response.status_code)
17+
print(requests.codes.ok)
1518
assert_that(response.status_code).is_equal_to(requests.codes.ok)
1619
# We can get python dict as response by using .json() method
17-
response_text = response.json()
18-
first_names = [people['fname'] for people in response_text]
20+
peoples = response.json()
21+
# pretty_print() is a module from python that indents the json response in a more readable way.
22+
pretty_print(peoples)
23+
first_names = [people['fname'] for people in peoples]
24+
pretty_print(first_names)
1925
assert_that(first_names).contains('Kent')
2026

2127

2228
def test_new_person_can_be_added():
2329
unique_last_name = create_new_person()
24-
2530
# After user is created, we read all the users and then use filter expression to find if the
2631
# created user is present in the response list
2732
peoples = requests.get(BASE_URI).json()
@@ -44,6 +49,8 @@ def create_new_person():
4449
# Ensure a user with a unique last name is created everytime the test runs
4550
# Note: json.dumps() is used to convert python dict to json string
4651
unique_last_name = f'User {str(uuid4())}'
52+
print(str(uuid4()))
53+
# dumps() is a method that takes the python dictionary and converts it into json string
4754
payload = dumps({
4855
'fname': 'New',
4956
'lname': unique_last_name
@@ -58,9 +65,11 @@ def create_new_person():
5865

5966
# We use requests.post method with keyword params to make the request more readable
6067
response = requests.post(url=BASE_URI, data=payload, headers=headers)
68+
print(response.status_code)
6169
assert_that(response.status_code, description='Person not created').is_equal_to(requests.codes.no_content)
70+
print(unique_last_name)
6271
return unique_last_name
6372

6473

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

0 commit comments

Comments
 (0)