114 lines
3.1 KiB
Python
Executable File
114 lines
3.1 KiB
Python
Executable File
# Python library imports
|
|
from datetime import datetime
|
|
|
|
# Library imports
|
|
from flask import Flask
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
# Import accounts blueprint
|
|
from accounts import accounts
|
|
|
|
# Import db
|
|
from accounts.models import db
|
|
|
|
# Import db models
|
|
from accounts.models.dog import Dog
|
|
from accounts.models.dog.breed_size import BreedSize
|
|
from accounts.models.user import User
|
|
from accounts.models.visit import Visit
|
|
from accounts.models.visit.visit_type import VisitType
|
|
|
|
def create_app():
|
|
# Initialize flask app
|
|
accounts_app = Flask(__name__, template_folder='templates')
|
|
accounts_app.register_blueprint(accounts)
|
|
accounts_app.config.from_pyfile('config.py')
|
|
|
|
# Initialize db with flask app
|
|
db.init_app(accounts_app)
|
|
|
|
with accounts_app.app_context():
|
|
# Create db tables
|
|
db.create_all()
|
|
|
|
# Add test data to db session
|
|
add_test_data(db)
|
|
|
|
# Commit test data to db
|
|
db.session.commit()
|
|
|
|
return accounts_app
|
|
|
|
def add_test_data(db):
|
|
# Create test users
|
|
man_man = User(name='Man Man',
|
|
username='mamanman',
|
|
email='man_man@email.com',
|
|
address='123 Home Ln. City, AA 11223',
|
|
password='manword')
|
|
|
|
real_person = User(name='Real Person',
|
|
username='imarealperson',
|
|
email='real_person@email.com',
|
|
address='113 Park St. City, AA 13433',
|
|
password='realpassword')
|
|
|
|
# Add test users to db session
|
|
db.session.add(man_man)
|
|
db.session.add(real_person)
|
|
|
|
# Commit test users to db
|
|
db.session.commit()
|
|
|
|
# Create test dogs
|
|
lassey = Dog(name='Lassey',
|
|
breed_size=BreedSize.LARGE,
|
|
owner_id=man_man.id)
|
|
|
|
rufus = Dog(name='Rufus',
|
|
breed_size=BreedSize.SMALL,
|
|
owner_id=man_man.id)
|
|
|
|
air_bud = Dog(name='Air Bud',
|
|
owner_id=real_person.id)
|
|
|
|
# Add test dogs to db session
|
|
db.session.add(lassey)
|
|
db.session.add(rufus)
|
|
db.session.add(air_bud)
|
|
|
|
# Commit test dogs to db
|
|
db.session.commit()
|
|
|
|
# Create test visits
|
|
|
|
# Visit with the date in the past
|
|
test_visit1 = Visit(date_time=datetime(2023,12,5,10,30),
|
|
owner_id=man_man.id,
|
|
dog_id=rufus.id)
|
|
|
|
# Visit with the date in the future
|
|
test_visit2 = Visit(date_time=datetime(2034,12,5,10,30),
|
|
owner_id=man_man.id,
|
|
dog_id=lassey.id)
|
|
|
|
# Visit with non-default visit type
|
|
test_visit3 = Visit(date_time=datetime(2034,12,5,10,30),
|
|
owner_id=real_person.id,
|
|
visit_type=VisitType.HOUSE_SITTING,
|
|
dog_id=air_bud.id)
|
|
|
|
# Visit with more than one dog
|
|
#test_visit3 = Visit(date_time=datetime(2034,12,5,10,30),
|
|
# owner_id=man_man.id,
|
|
# dog_id=[lassey.id, rufus.id])
|
|
|
|
# Add test visits to db session
|
|
db.session.add(test_visit1)
|
|
db.session.add(test_visit2)
|
|
db.session.add(test_visit3)
|
|
|
|
# Commit test visits to db
|
|
db.session.commit()
|
|
|