def seed_db(): global test_driver_id global cust1_id global cust2_id global test_note_text db.drop_all() db.create_all() test_driver = User(email="*****@*****.**", token="testToken", api_id='demo') cust1 = Customer(**cust1_data) cust2 = Customer(**cust2_data) db.session.add(cust1) db.session.add(cust2) db.session.add(test_driver) db.session.commit() test_note_text = "HELLO THERE!" note = Note(driver_id=test_driver.id, cust_id=cust1.id, note=test_note_text) db.session.add(note) db.session.commit() # variables to reference test_driver_id = test_driver.id cust1_id = cust1.id cust2_id = cust2.id test_note_text = test_note_text
def seed_db(): global test_driver_id global cust1_id global cust2_id db.session.rollback() db.drop_all() db.create_all() test_driver = User(email="*****@*****.**", token="testToken", api_id='demo') cust1 = Customer(**cust1_data) cust2 = Customer(**cust2_data) db.session.add(cust1) db.session.add(cust2) db.session.add(test_driver) db.session.commit() # global variables test_driver_id = test_driver.id cust1_id = cust1.id cust2_id = cust2.id
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + TEST_DB self.app = app.test_client() db.drop_all() db.create_all()
def seed_the_db(): global user_id db.session.rollback() db.drop_all() db.create_all() test_user = User(**user_data) db.session.add(test_user) db.session.commit() # variables to reference user_id = test_user.id
def seed_db(): db.session.rollback() global test_driver_id global test_cust_id global test_delivery_id global test_order_id global order_data db.drop_all() db.create_all() user_data = {"email": "*****@*****.**", "token": "testToken", api_id='demo'} cust_data = {"id": '1', "name": "testuser1", "address": "Some Address", "phone": "203-881-7843"} test_driver = User(**user_data) test_cust = Customer(**cust_data) db.session.add(test_cust) db.session.add(test_driver) db.session.commit() delivery_data = {"driver_id": test_driver.id} test_delivery = Delivery(**delivery_data) db.session.add(test_delivery) db.session.commit() order_data = {"num": 112, "cust_id": test_cust.id, "del_id": test_delivery.id, "driver_id": test_driver.id, "date": datetime.date(2021, 4, 19)} test_order = Order(**order_data) db.session.add(test_order) db.session.commit() test_driver_id = test_driver.id test_cust_id = test_cust.id test_delivery_id = test_delivery.id test_order_id = (test_order.num, test_order.date)
# BEFORE we import our app, let's set an environmental variable # to use a different database for tests (we need to do this # before we import our app, since that will have already # connected to the database os.environ['DATABASE_URL'] = "postgresql:///warbler-test" # Now we can import app from app import CURR_USER_KEY, app # Create our tables (we do this here, so we only create the tables # once for all tests --- in each test, we'll delete the data # and create fresh new clean test data db.create_all() # Don't have WTForms use CSRF at all, since it's a pain to test app.config['WTF_CSRF_ENABLED'] = False class MessageViewTestCase(TestCase): """Test views for messages.""" def setUp(self): """Create test client, add sample data.""" User.query.delete() Message.query.delete() self.client = app.test_client()
def create_db(): db.drop_all() db.create_all() db.session.commit()