diff --git a/extensions.py b/extensions.py index 2e1eeb6..f0b13d6 100644 --- a/extensions.py +++ b/extensions.py @@ -1,3 +1,3 @@ from flask_sqlalchemy import SQLAlchemy -db = SQLAlchemy() \ No newline at end of file +db = SQLAlchemy() diff --git a/models.py b/models.py index 94419e7..22061bc 100644 --- a/models.py +++ b/models.py @@ -1,4 +1,3 @@ -# creates SQLALCHEMY object import jwt from flask import json from flask_bcrypt import generate_password_hash @@ -62,7 +61,6 @@ def password(self, plaintext): class Product(db.Model, SerializerMixin): serialize_rules = ('-products.user',) - # serialize_rules = ('-products.user', '-seller') id = db.Column(db.Integer, primary_key=True) amount_available = db.Column(db.Integer) diff --git a/test_fill_database.py b/test_fill_database.py index 26c8f3d..4d234e3 100644 --- a/test_fill_database.py +++ b/test_fill_database.py @@ -1,5 +1,5 @@ import sqlalchemy -from models import User +from models import User, Product, Role from extensions import db from main import create_app @@ -12,7 +12,6 @@ def create_tables(db): def fill_db_test(db): - from models import User, Product, Role user1 = User(username='user1', password='pass1') user2 = User(username='user2', password='pass2') @@ -45,8 +44,6 @@ def test_cost_constraint(): of 5. Will throw an IntegrityError. """ - from models import db, Product - user = db.session.query(User).all()[0] user.products.append(Product(productName='p1', amountAvailable=10, cost=6, sellerID=user)) @@ -57,8 +54,9 @@ def test_cost_constraint(): logger.info("Test passed, cost can only be multiples of 5.") -app = create_app() -db.init_app(app) -with app.app_context(): - create_tables(db) - fill_db_test(db) +if __name__ == '__main__': + app = create_app() + db.init_app(app) + with app.app_context(): + create_tables(db) + fill_db_test(db)