File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 1
1
BASE_URI = 'http://0.0.0.0:5000/api/people'
2
- COVID_TRACKER_HOST = 'http://127.0.0.1:5000 '
2
+ COVID_TRACKER_HOST = 'http://127.0.0.1:3000 '
Original file line number Diff line number Diff line change @@ -11,7 +11,27 @@ def test_covid_cases_have_crossed_a_million():
11
11
pretty_print (response .headers )
12
12
13
13
response_xml = response .text
14
- tree = etree .fromstring (bytes (response_xml , encoding = 'utf8' ))
15
- total_cases = tree .xpath ("//data/summary/total_cases" )[0 ].text
14
+ xml_tree = etree .fromstring (bytes (response_xml , encoding = 'utf8' ))
16
15
16
+ # use .xpath on xml_tree object to evaluate the expression
17
+ total_cases = xml_tree .xpath ("//data/summary/total_cases" )[0 ].text
17
18
assert_that (int (total_cases )).is_greater_than (1000000 )
19
+
20
+
21
+ def test_overall_covid_cases_match_sum_of_total_cases_by_country ():
22
+ response = requests .get (f'{ COVID_TRACKER_HOST } /api/v1/summary/latest' )
23
+ pretty_print (response .headers )
24
+
25
+ response_xml = response .text
26
+ xml_tree = etree .fromstring (bytes (response_xml , encoding = 'utf8' ))
27
+
28
+ overall_cases = int (xml_tree .xpath ("//data/summary/total_cases" )[0 ].text )
29
+ # Another way to specify XPath first and then use to evaluate
30
+ # on an XML tree
31
+ search_for = etree .XPath ("//data//regions//total_cases" )
32
+ cases_by_country = 0
33
+ for region in search_for (xml_tree ):
34
+ cases_by_country += int (region .text )
35
+
36
+ assert_that (overall_cases ).is_greater_than (cases_by_country )
37
+
You can’t perform that action at this time.
0 commit comments