forked from VelezReyes/first-quiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion5_test.py
74 lines (58 loc) · 1.9 KB
/
question5_test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pets_db as pets_db
from question5 import sql_create_favorite_foods, sql_alter_tables_with_favorite_food, sql_select_all_vegetarian_pets
FOODS = [
(1, "spinach", 1),
(2, "termites", 0),
(3, "turnips", 1),
(4, "cough drops", 1),
(5, "shrimp", 0),
]
PEOPLE_FOOD = [
(4, "scott"), # cough drops
(5, "bessie"), # shrimp
(3, "karen"), # turnips
]
ANIMALS_FOOD = [
(5, "petey"), # shrimp
(1, "leyla"), # spinach
(2, "thommy"), # termites
(4, "ricky"), # cough drops
(1, "martin"), # spinach
(3, "shannon"), # turnips
(2, "randolph"), # termites
]
def insert_foods(con):
con.executemany("INSERT INTO favorite_foods VALUES(?, ?, ?)", FOODS)
def create_favorite_foods(con):
con.execute(sql_create_favorite_foods)
def alter_people_animals_food(con):
con.executescript(sql_alter_tables_with_favorite_food);
def update_people_animals_food(con):
con.executemany("UPDATE people SET favorite_food_id = ? WHERE name = ?", PEOPLE_FOOD)
con.executemany("UPDATE animals SET favorite_food_id = ? WHERE name = ?", ANIMALS_FOOD)
def test_create_favorite_foods():
pets_db.create_db()
with pets_db.get_connection() as con:
create_favorite_foods(con)
insert_foods(con)
def test_alter_tables_with_favorite_food():
pets_db.create_db()
with pets_db.get_connection() as con:
create_favorite_foods(con)
insert_foods(con)
alter_people_animals_food(con)
update_people_animals_food(con)
def test_select_all_vegetarian_pets():
pets_db.create_db()
with pets_db.get_connection() as con:
create_favorite_foods(con)
insert_foods(con)
alter_people_animals_food(con)
update_people_animals_food(con)
res = con.execute(sql_select_all_vegetarian_pets)
rows = res.fetchall()
rows.sort()
assert rows[0] == ('leyla', 'spinach')
assert rows[1] == ('martin', 'spinach')
assert rows[2] == ('ricky', 'cough drops')
assert rows[3] == ('shannon', 'turnips')