def database(app): with app.app_context(): db.init_app(app) db.create_all() yield app db.session.close() db.drop_all()
def test_creating_bucketlist(self): """Tests successfully creating a bucketlist""" # this test would conflict with bucketlist defined in the setup # clear everythin before running it db.drop_all() db.create_all() # Instantiating a bucketlist object bucketlist = Bucketlist("Cook") # save the object to database db.session.add(bucketlist) db.session.commit() # asssert the attributes self.assertEqual(bucketlist.id, 1) self.assertEqual(bucketlist.name, "Cook") self.assertEqual(bucketlist.created_by, None) year = str(datetime.today().year) self.assertIn(year, str(bucketlist.date_created)) self.assertIn(year, str(bucketlist.date_modified)) self.assertEqual(len(bucketlist.items), 0) # test querying bucketlists bucketlist_query = Bucketlist.query.all() self.assertIn("<Bucketlist 'Cook'>", str(bucketlist_query)) self.assertFalse("<Bucketlist 'Random'>" in str(bucketlist_query))
def test_creating_bucketlist_with_a_missing_name(self): """Tests successfully creating a bucketlist""" # this test would conflict with bucketlist defined in the setup # clear everythin before running it db.drop_all() db.create_all() with self.assertRaises(Exception) as context: # Instantiating a bucketlist object bucketlist = Bucketlist() # save the object to database db.session.add(bucketlist) db.session.commit() self.assertEqual('kjfdjkgf', 'nndnnv')
def reset_db(): db.drop_all() db.create_all()
def init_db(): db.drop_all() db.create_all()
def tearDown(self): db.session.remove() db.drop_all()
def tearDown(self): db.drop_all()