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
6
-
7
5
from config import BASE_URI
8
6
7
+ '''
8
+ We'll learn in this section is -: How to work with XML?
9
+ Any automation framework that you create is probably incomplete without having the ability to deal with XML requests &
10
+ responses. You might need this if you're automating the SOAP Based service, you might want to use the XML as a datatype
11
+ to store your test data or work with certain pre-created test data.
12
+ So let's understand how we can work with the XML in Python.
13
+ We'll use 'lxml' library which is very popular having nice python api.
14
+ '''
15
+
9
16
10
17
def test_read_all_has_kent ():
11
18
# We use requests.get() with url to make a get request
@@ -15,15 +22,13 @@ def test_read_all_has_kent():
15
22
assert_that (response .status_code ).is_equal_to (requests .codes .ok )
16
23
# We can get python dict as response by using .json() method
17
24
response_content = response .json ()
18
-
19
25
# Use assertpy's fluent assertions to extract all fnames and then see the result is non empty and has
20
26
# Kent in it.
21
27
assert_that (response_content ).extracting ('fname' ).is_not_empty ().contains ('Kent' )
22
28
23
29
24
30
def test_new_person_can_be_added ():
25
31
unique_last_name = create_new_person ()
26
-
27
32
# After user is created, we read all the users and then use filter expression to find if the
28
33
# created user is present in the response list
29
34
peoples = requests .get (BASE_URI ).json ()
@@ -33,10 +38,8 @@ def test_new_person_can_be_added():
33
38
34
39
def test_created_person_can_be_deleted ():
35
40
persons_last_name = create_new_person ()
36
-
37
41
peoples = requests .get (BASE_URI ).json ()
38
42
newly_created_user = search_created_user_in (peoples , persons_last_name )[0 ]
39
-
40
43
delete_url = f'{ BASE_URI } /{ newly_created_user ["person_id" ]} '
41
44
response = requests .delete (delete_url )
42
45
assert_that (response .status_code ).is_equal_to (requests .codes .ok )
@@ -50,14 +53,12 @@ def create_new_person():
50
53
'fname' : 'New' ,
51
54
'lname' : unique_last_name
52
55
})
53
-
54
56
# Setting default headers to show that the client accepts json
55
57
# And will send json in the headers
56
58
headers = {
57
59
'Content-Type' : 'application/json' ,
58
60
'Accept' : 'application/json'
59
61
}
60
-
61
62
# We use requests.post method with keyword params to make the request more readable
62
63
response = requests .post (url = BASE_URI , data = payload , headers = headers )
63
64
assert_that (response .status_code , description = 'Person not created' ).is_equal_to (requests .codes .no_content )
0 commit comments