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
50 lines (39 loc) · 1.42 KB
/
debug.py
File metadata and controls
50 lines (39 loc) · 1.42 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
44
45
46
47
48
49
50
from lib.models import Company, Dev, Freebie, Base
from sqlalchemy.orm import sessionmaker
from lib.database import engine
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
oldest = Company.oldest_company(session)
print("Oldest company:", oldest.name if oldest else "None")
# Create tables (run once or during setup)
Base.metadata.create_all(engine)
# Create a session
Session = sessionmaker(bind=engine)
session = Session()
# Add seed data if needed
# Run this only once or protect with `if not session.query(...).first():`
# Example:
# google = Company(name="Google", founding_year=1998)
# alice = Dev(name="Alice")
# session.add_all([google, alice])
# session.commit()
# Test oldest company
print("Oldest company:", Company.oldest_company(session).name)
# Test dev received_one
dev = session.query(Dev).filter_by(name="Alice").first()
print("Alice received T-shirt?", dev.received_one("T-shirt"))
# Test print_details
freebie = session.query(Freebie).first()
print(freebie.print_details())
# Test give_freebie
company = session.query(Company).filter_by(name="Google").first()
new_freebie = company.give_freebie(dev, "Cap", 15)
session.add(new_freebie)
session.commit()
print(new_freebie.print_details())
# Test give_away
bob = session.query(Dev).filter_by(name="Bob").first()
dev.give_away(bob, new_freebie)
session.commit()
print(new_freebie.print_details()) # Should now show Bob as the owner