@@ -18,65 +18,73 @@ def teardown_function(function):
1818def test_root ():
1919 c = Client (App ())
2020
21- response = c .get ('/' )
21+ response = c .get ("/" )
2222 assert response .json == {"collection" : "http://localhost/animals" }
2323
2424
2525def test_zoo ():
2626 c = Client (App ())
27- response = c .get ('/animals' )
28- zoo = {"animals" : [
29- {"@id" : "http://localhost/animals/0" ,
30- "name" : "Bob" , "species" : "snake" },
31- {"@id" : "http://localhost/animals/1" ,
32- "name" : "Fred" , "species" : "snake" },
33- {"@id" : "http://localhost/animals/2" ,
34- "name" : "Anna" , "species" : "elephant" },
35- {"@id" : "http://localhost/animals/3" ,
36- "name" : "Kate" , "species" : "tiger" }
37- ]}
27+ response = c .get ("/animals" )
28+ zoo = {
29+ "animals" : [
30+ {"@id" : "http://localhost/animals/0" , "name" : "Bob" , "species" : "snake" },
31+ {"@id" : "http://localhost/animals/1" , "name" : "Fred" , "species" : "snake" },
32+ {
33+ "@id" : "http://localhost/animals/2" ,
34+ "name" : "Anna" ,
35+ "species" : "elephant" ,
36+ },
37+ {"@id" : "http://localhost/animals/3" , "name" : "Kate" , "species" : "tiger" },
38+ ]
39+ }
3840 assert response .json == zoo
3941
4042
4143def test_animal ():
4244 c = Client (App ())
43- response = c .get ('/animals/0' )
44- assert response .json == {"@id" : "http://localhost/animals/0" ,
45- "name" : "Bob" , "species" : "snake" }
45+ response = c .get ("/animals/0" )
46+ assert response .json == {
47+ "@id" : "http://localhost/animals/0" ,
48+ "name" : "Bob" ,
49+ "species" : "snake" ,
50+ }
4651
4752
4853def test_add_animal ():
4954 c = Client (App ())
5055
5156 new_animal_json = json .dumps ({"name" : "Lupus" , "species" : "wolf" })
52- response = c .post ('/animals' , new_animal_json )
53- new_animal_response = {"@id" : "http://localhost/animals/4" ,
54- "name" : "Lupus" , "species" : "wolf" }
57+ response = c .post ("/animals" , new_animal_json )
58+ new_animal_response = {
59+ "@id" : "http://localhost/animals/4" ,
60+ "name" : "Lupus" ,
61+ "species" : "wolf" ,
62+ }
5563 assert response .json == new_animal_response
5664
5765
5866def test_delete_animal ():
5967 c = Client (App ())
6068
61- response = c .delete ('/animals/2' )
62- zoo = {"animals" : [
63- {"@id" : "http://localhost/animals/0" ,
64- "name" : "Bob" , "species" : "snake" },
65- {"@id" : "http://localhost/animals/1" ,
66- "name" : "Fred" , "species" : "snake" },
67- {"@id" : "http://localhost/animals/3" ,
68- "name" : "Kate" , "species" : "tiger" }
69- ]}
69+ response = c .delete ("/animals/2" )
70+ zoo = {
71+ "animals" : [
72+ {"@id" : "http://localhost/animals/0" , "name" : "Bob" , "species" : "snake" },
73+ {"@id" : "http://localhost/animals/1" , "name" : "Fred" , "species" : "snake" },
74+ {"@id" : "http://localhost/animals/3" , "name" : "Kate" , "species" : "tiger" },
75+ ]
76+ }
7077 assert response .json == zoo
7178
7279
7380def test_change_animal ():
7481 c = Client (App ())
7582
76- changed_animal_json = json .dumps (
77- {"name" : "Changed Fred" , "species" : "fish" }
78- )
79- response = c .put ('/animals/1' , changed_animal_json )
80- changed_animal_response = {"@id" : "http://localhost/animals/1" ,
81- "name" : "Changed Fred" , "species" : "fish" }
83+ changed_animal_json = json .dumps ({"name" : "Changed Fred" , "species" : "fish" })
84+ response = c .put ("/animals/1" , changed_animal_json )
85+ changed_animal_response = {
86+ "@id" : "http://localhost/animals/1" ,
87+ "name" : "Changed Fred" ,
88+ "species" : "fish" ,
89+ }
8290 assert response .json == changed_animal_response
0 commit comments