forked from learn-co-curriculum/python-p3-freebie-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.py
More file actions
43 lines (30 loc) · 1.23 KB
/
debug.py
File metadata and controls
43 lines (30 loc) · 1.23 KB
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
#!/usr/bin/env python3
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from models import Company, Dev, Freebie, Base
if __name__ == '__main__':
engine = create_engine('sqlite:///freebies.db')
Session = sessionmaker(bind=engine)
session = Session()
# Test relationships
rick = session.query(Dev).filter_by(name="Rick").first()
print("Rick's freebies:", rick.freebies)
print("Rick's companies:", rick.companies)
google = session.query(Company).filter_by(name="Google").first()
print("Google's freebies:", google.freebies)
print("Google's devs:", google.devs)
freebie = session.query(Freebie).first()
print("Freebie details:", freebie.print_details())
print("Oldest company:", Company.oldest_company())
print("Rick received MacBook:", rick.received_one("MacBook"))
# Test give_freebie
new_freebie = google.give_freebie(rick, "Laptop", 2000)
session.add(new_freebie)
session.commit()
print("Rick's freebies after give_freebie:", rick.freebies)
# Test give_away
rick.give_away(morty, new_freebie)
session.add(new_freebie)
session.commit()
print("Morty received Laptop:", morty.received_one("Laptop"))
session.close()