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
37 lines (29 loc) · 1.11 KB
/
debug.py
File metadata and controls
37 lines (29 loc) · 1.11 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
from models import Company, Dev, Freebie
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
# Set up the session
engine = create_engine('sqlite:///app.db')
Session = sessionmaker(bind=engine)
session = Session()
# Test - Create Devs and Company
dev1 = Dev(name="Alice")
dev2 = Dev(name="Bob")
company = Company(name="TechCorp", founding_year=2000)
session.add(dev1)
session.add(dev2)
session.add(company)
session.commit()
# Test - Give a freebie to a dev
company.give_freebie(dev1, "T-shirt", 10)
# Test - Print details of the freebie
freebie = session.query(Freebie).first()
print(freebie.print_details()) # Should print "Alice owns a T-shirt from TechCorp"
# Test - Oldest company
oldest = Company.oldest_company()
print(oldest.name) # Should print the name of the oldest company
# Test - Check if a dev received a specific freebie
print(dev1.received_one("T-shirt")) # Should return True
print(dev2.received_one("T-shirt")) # Should return False
# Test - Give away a freebie
dev1.give_away(dev2, freebie)
print(freebie.print_details()) # Should now print "Bob owns a T-shirt from TechCorp"