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
39 lines (30 loc) · 1.32 KB
/
debug.py
File metadata and controls
39 lines (30 loc) · 1.32 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
#!/usr/bin/env python3
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from models import Company, Dev, Freebie
if __name__ == '__main__':
engine = create_engine('sqlite:///freebies.db')
Session = sessionmaker(bind=engine)
session = Session()
# Creating sample data
company1 = Company(name="Company A", founding_year=1990)
company2 = Company(name="Company B", founding_year=2000)
dev1 = Dev(name="Dev X")
dev2 = Dev(name="Dev Y")
# Add companies and devs to the session
session.add_all([company1, company2, dev1, dev2])
session.commit()
# Test the give_freebie method
freebie1 = company1.give_freebie(dev1, "T-shirt", 10)
freebie2 = company2.give_freebie(dev2, "Sticker", 5)
# Test the print_details method
print(freebie1.print_details()) # Should print: Dev X owns a T-shirt from Company A
# Test the oldest_company method
oldest = Company.oldest_company(session)
print(f"The oldest company is: {oldest.name}") # Should print: The oldest company is: Company A
# Test the received_one method
print(dev1.received_one("T-shirt")) # Should print: True
print(dev2.received_one("T-shirt")) # Should print: False
# Test the give_away method
dev1.give_away(dev2, freebie1)
print(freebie1.dev.name) # Should print: Dev Y