forked from keeppythonweird/catinabox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_cattery_service.py
58 lines (46 loc) · 1.99 KB
/
test_cattery_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
class TestCatteryService(object):
def test__empty_cattery(self, cattery_client):
# Returns no cats
result = cattery_client.get('cats')
assert False
def test__adding_a_cat(self, cattery_client):
# Add the cat
result = cattery_client.post('cats',
data=json.dumps({"name": "Theodora"}))
assert False
def test__removing_a_cat(self, cattery_client):
# Add a cat
cattery_client.post('cats', data=json.dumps({"name": "Theodora"}))
# Remove the cat
result = cattery_client.delete('cats',
data=json.dumps({"name": "Theodora"}))
assert result.status_code == 204
# Make sure the cat is gone
result = cattery_client.get('cats')
assert result.json() == []
def test__feeding_cats(self, cattery_client):
# Add two cats
cattery_client.post('cats', data=json.dumps({"name": "Theodora"}))
cattery_client.post('cats', data=json.dumps({"name": "Bronson"}))
# Put food in the pantry
result = cattery_client.patch('pantry',
data=json.dumps([("burger", 1),
("cheezburger", 4)]))
assert result.status_code == 204
# Feed the cats
result = cattery_client.post('cats/dishes')
assert result.status_code == 204
# Verify the cats were fed
result = cattery_client.get('cats')
assert result.status_code == 200
assert result.json() == [
{"name": "Theodora", "food_eaten": ["burger"]},
{"name": "Bronson",
"food_eaten": ["cheezburger"]}]
# Verify the pantry has food left
result = cattery_client.get('pantry')
assert result.status_code == 200
assert result.json() == ["cheezburger",
"cheezburger",
"cheezburger"]