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
52 lines (37 loc) · 1.5 KB
/
debug.py
File metadata and controls
52 lines (37 loc) · 1.5 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
51
52
#!/usr/bin/env python3
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from models import Base, Company, Dev, Freebie
# Creates an engine
engine = create_engine('sqlite:///freebies.db')
# Creates a configured "Session" class
Session = sessionmaker(bind=engine)
# Creates a session instance
session = Session()
# Creates the database and tables
Base.metadata.create_all(engine)
# Creates some sample data
company1 = Company(name="Tech Corp", founding_year=2000)
dev1 = Dev(name="Alice")
dev2 = Dev(name="Bob")
# Adds companies and devs to session and commit
session.add(company1)
session.add(dev1)
session.add(dev2)
session.commit()
import ipdb; ipdb.set_trace()
# Creates freebies using the give_freebie method
freebie1 = company1.give_freebie(dev1, "T-shirt", 10)
freebie2 = company1.give_freebie(dev1, "Mug", 5)
freebie3 = company1.give_freebie(dev2, "Sticker", 1)
# Prints details of freebies
print(freebie1.print_details()) # Should print: Alice owns a T-shirt from Tech Corp.
print(freebie2.print_details()) # Should print: Alice owns a Mug from Tech Corp.
print(freebie3.print_details()) # Should print: Bob owns a Sticker from Tech Corp.
# Tests the received_one method
print(dev1.received_one("T-shirt")) # Should return True
print(dev2.received_one("Mug")) # Should return False
# Tests the oldest_company method
oldest_company = Company.oldest_company(session)
print(f"The oldest company is {oldest_company.name} founded in {oldest_company.founding_year}.")
session.close()