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 (31 loc) · 1.41 KB
/
debug.py
File metadata and controls
39 lines (31 loc) · 1.41 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, Base
if __name__ == '__main__':
engine = create_engine('sqlite:///freebies.db')
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
# querying data from my db (seed data)
first_company = session.query(Company).first()
first_dev = session.query(Dev).first()
first_freebie = session.query(Freebie).first()
print("Testing print_details() on first freebie:")
if first_freebie:
print(first_freebie.print_details())
print("\nTesting oldest_company():")
oldest = Company.oldest_company(session)
print(oldest)
print("\nTesting received_one() on first dev with item 'Tshirts':")
if first_dev:
print(first_dev.received_one('Tshirts'))
# Testing give_away() (transfer first freebie from its current owner to another dev if possible)
second_dev = session.query(Dev).filter(Dev.id != first_dev.id).first() if first_dev else None
if first_dev and second_dev and first_freebie:
print(f"\nBefore give_away: {first_freebie.print_details()}")
success = first_dev.give_away(second_dev, first_freebie)
session.commit()
print("Give away success?", success)
print(f"After give_away: {first_freebie.print_details()}")
import ipdb; ipdb.set_trace()