def drop_db(): """Drop the database.""" # db.engine.execute("SET FOREIGN_KEY_CHECKS=0;") with app.app_context(): db.drop_all() # db.engine.execute("SET FOREIGN_KEY_CHECKS=1;") print("Drop all tables.")
def setUp(self): """Setup to do before every test.""" # Get the Flask test client self.client = app.test_client() app.jinja_env.undefined = StrictUndefined app.jinja_env.filters['prettify_preference'] = prettify_preference # Show Flask errors that happen during tests app.config['TESTING'] = True # Connect to test database connect_to_db(app, db_uri="postgresql:///testdb") # start with empty db db.drop_all() # Create tables and add sample data db.create_all() # create db records for yarns, users, baskets, basket_yarns, # projects, and patterns create_example_data() # create db records for preferences and user_preferences load_preferences("test_data/preference_data.txt") load_user_preferences("test_data/user_preference_data.txt") load_group_events("test_data/group-events.csv")
def tearDown(self): """ Gets rid of everything """ db.session.close() db.drop_all() print "tear down complete"
def tearDown(self): """do at end of every test""" #import pdb; pdb.set_trace() print "tear down " db.session.close() db.drop_all()
def setUp(self): """Setup to do before every test.""" # Get the Flask test client self.client = app.test_client() app.jinja_env.undefined = StrictUndefined # secret key to allow sessions to be used app.config['SECRET_KEY'] = 'sekrit!' # Show Flask errors that happen during tests app.config['TESTING'] = True # Connect to test database connect_to_db(app, db_uri="postgresql:///testdb") # start with empty db db.drop_all() # Create tables and add sample data db.create_all() # create db records for yarns, users, baskets, basket_yarns, # projects, and patterns create_example_data() # create db records for preferences and user_preferences load_preferences("test_data/preference_data.txt") load_user_preferences("test_data/user_preference_data.txt") load_group_events("test_data/group-events.csv") with self.client as c: with c.session_transaction() as session: session['username'] = '******'
def tearDown(self): """Do this after each test.""" print('\n\n\n...tearing down...\n\n\n') db.session.remove() db.drop_all() db.engine.dispose()
def tearDown(self): """Do at end of every test.""" # (uncomment when testing database) db.session.close() db.drop_all() db.engine.dispose()
def bootstrap_db(): """Fills Database with Sample data (WARNING! THIS CLEARS OUT ALL OTHER DB DATA)""" db.drop_all() db.create_all() t = WelpTester() t.bootstrapDB() return
def tearDown(self): """ At the end of every test.""" db.session.close() db.drop_all() print "tearDown successful"
def setUp(self): connect_to_db(app, "postgresql:///testdb") db.drop_all() self.client = app.test_client() app.config['TESTING'] = True db.create_all() example_data()
def tearDown(self): # print("(tearDown ran)") db.session.remove() db.drop_all() db.engine.dispose() return
def setUp(self): """Connect to database, create tables.""" self.client = app.test_client() app.config["TESTING"] = True connect_to_db(app, config.TEST_DB_URI) db.drop_all() db.create_all() # example_data() update_pkey_seqs.update_pkey_seqs() self.repo = Repo(repo_id="2", name="Haskellyton", description="A Halloween repository", owner_id="1") repo_attributes = {"id": "2", "name": "Haskellyton", "full_name": "Haskellyton", "description": "A Halloween repository", "owner_id": "1"} self.py_repo = github.Repository.Repository(requester="", headers="", attributes=repo_attributes, completed="") py_repo = self.py_repo # Don't call the Github API: just return self.py_repo when this is called. self.holder_get_repo = github.Github.get_repo github.Github.get_repo = lambda self, repo_info: py_repo
def tearDown(self): """Things to do at end of every test""" # close the session db.session.close() # drop database db.drop_all()
def setUp(self): """Connect to database, create tables.""" self.client = app.test_client() app.config["TESTING"] = True connect_to_db(app, config.TEST_DB_URI) db.drop_all() db.create_all() # example_data() # update_pkey_seqs.update_pkey_seqs() self.user = User(user_id="4", name="Balloonicorn Doe", login="******") db.session.add(self.user) db.session.commit() user_attributes = {"id": "4", "name": "Balloonicorn Doe", "login": "******"} self.py_user = github.NamedUser.NamedUser(requester="", headers="", attributes=user_attributes, completed="") user = self.user py_user = self.py_user # Don't call the github api: just return self.py_repo when this is called. self.holder_get_user = github.Github.get_user github.Github.get_user = lambda self, login: py_user
def tearDown(self): """Do at the end of every test.""" server.yelp.search_query = self.old_get_yelp_search_results process_results.is_open_now = self._old_is_open_now db.session.close() db.drop_all()
def tearDown(self): """Code to run after every test""" db.session.remove() db.drop_all() db.engine.dispose() self.postgresql.stop()
def setUp(self): """Connect to database, create tables, generate test data.""" self.client = app.test_client() app.config["TESTING"] = True connect_to_db(app, config.TEST_DB_URI) db.drop_all() db.create_all() example_data()
def tearDown(self): """Close session, drop db.""" db.session.close() db.drop_all() utils.get_user_object_from_input = self.holder_get_user_object_from_input utils.update_user = self.holder_update_user db_utils.is_user_in_db = self.holder_is_user_in_db
def tearDown(self): """Stuff to do after every test.""" db.session.remove() # dropping old tables db.drop_all() db.engine.dispose()
def tearDown(self): """Things to do at end of every test""" # Close the session. db.session.close() # Drop the database. db.drop_all()
def init_database(client): db.create_all() load_test_data() yield db.session.close() db.drop_all()
def setUp(self): """Connect to database, create tables.""" self.client = app.test_client() app.config["TESTING"] = True connect_to_db(app, config.TEST_DB_URI) db.drop_all() db.create_all() # example_data() # update_pkey_seqs.update_pkey_seqs() self.user = User(user_id="4", name="Balloonicorn Doe", login="******") db.session.add(self.user) db.session.commit() user_attributes = {"id": "4", "name": "Balloonicorn Doe", "login": "******"} self.py_user = github.NamedUser.NamedUser(requester="", headers="", attributes=user_attributes, completed="") user = self.user py_user = self.py_user # Don't call the github api: just return self.py_repo when this is called. # github.Github.get_user = lambda self, login: py_user self.repo = Repo(repo_id="2", name="Haskell Games", description="Games in Haskell", owner_id="4") db.session.add(self.repo) db.session.commit() repo_attributes = {"id": self.repo.repo_id, "name": self.repo.name, "description": self.repo.description, "owner": py_user} self.py_repo = github.Repository.Repository(requester="", headers="", attributes=repo_attributes, completed="") repo = self.repo py_repo = self.py_repo # Don't call the github api: just return self.py_repo when this is called. self.holder_get_user_object_from_input = utils.get_user_object_from_input self.holder_update_user = utils.update_user self.holder_is_user_in_db = db_utils.is_user_in_db utils.get_user_object_from_input = lambda user_info: py_user utils.update_user = lambda repo, num: None
def tearDown(self): # We don't need to do anything here; we could just # not define this method at all, but we have a stub # here as an example. # print("(tearDown ran)") db.session.remove() db.drop_all() db.engine.dispose() return
def setUp(self): #app.config.from_object('app.config.Testing') app = Flask(__name__) app = create_app('testing') #app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) db.session.close() db.drop_all() db.create_all()
def tearDown(self): """Log the user out and delete tables from database""" db.session.close() db.drop_all() with self.client as c: with c.session_transaction() as se: se.pop('user_id') se.pop('name')
def setUp(self): self.client = app.test_client() app.config['TESTING'] = True # Connect to test database (uncomment when testing database) connect_to_db(app, "postgresql:///testdb") bcrypt = Bcrypt(app) # Create tables and add sample data (uncomment when testing database) db.drop_all() db.create_all() example_data(bcrypt)
def setUp(self): """Do at the start of every test""" self.client = app.test_client() app.config['TESTING'] = True connect_to_db(app, "postgresql:///test_questions") db.drop_all() db.create_all() example_data()
def client(app): app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://" app.config['TESTING'] = True connect_to_db(app) client = app.test_client() with app.app_context(): db.create_all() yield client db.session.remove() db.drop_all()
def setUp(self): connect_to_db(app, "postgresql:///testdb") db.drop_all() self.client = app.test_client() app.config['TESTING'] = True db.create_all() example_data() def _mock_check_password_hash(user_pw, pw): return True import server server.check_password_hash = _mock_check_password_hash
def setUp(self): """Things to do before every test""" #get flask test client self.client = app.test_client() app.config['TESTING'] = True #connect to test database connect_to_db(app, "postgresql:///testdb") db.drop_all() db.create_all() example_data()
def setUp(self): """ To do before every test.""" self.client = app.test_client() app.config['TESTING'] = True # Connect to test database connect_to_db(app, "postgresql:///ratings_test") # Create tables and add sample data db.drop_all() db.create_all() example_data() print "settup successful"
def setUp(self): """Stuff to do before every test.""" # Get the Flask test client self.client = app.test_client() app.config['TESTING'] = True # Connect to test database connect_to_db(app, "postgresql:///testdb") # Create tables and add sample data db.drop_all() db.create_all() example_data()
def setUp(self): """Flask tests that use the database.""" app.config['TESTING'] = True app.config['SECRET_KEY'] = 'ABC' self.client = app.test_client() connect_to_db(app, "postgresql:///test_questions") with self.client as c: with c.session_transaction() as sess: sess['user_id'] = 1 db.drop_all() db.create_all() example_data()
def sample_data(): """create sample data""" # In case this is run more than once, dump existing data db.drop_all() db.create_all() # Add sample Uers user1 = User(first_name='pablo', last_name='penguin', contact_num='5109266821', nvmd_code='123') db.session.add_all([user1]) db.session.commit() pablo_id = User.query.filter_by(first_name='pablo').first().user_id # Add sample friends friend1 = Friendfirst_name='pablo', last_name='penguin', contact_num='5109266821') db.session.add_all([friend1]) db.session.commit()
def setUp(self): """Setup to do before every test.""" # Get the Flask test client self.client = app.test_client() app.jinja_env.undefined = StrictUndefined # secret key to allow sessions to be used app.config['SECRET_KEY'] = 'sekrit!' # Show Flask errors that happen during tests app.config['TESTING'] = True # Connect to test database connect_to_db(app, db_uri="postgresql:///testdb") # start with empty db db.drop_all() # Create tables and add sample data db.create_all()
def setUp(self): mail.outbox[:] = [] db.session.rollback() if getattr(conf, "created_db", False): truncate_tables() else: try: db.drop_all() except Exception as e: print(e) db.create_all() conf.created_db = True clear_mem_db() self.bootstrap() self.service_nano_id = Flavor.get_service_id('Nano') self.service_micro_id = Flavor.get_service_id('Micro') self.service_small_id = Flavor.get_service_id('Small') self.service_medium_id = Flavor.get_service_id('Medium') openstack._OpenStackAuth__auth["auth_url"] = "test.should.not.connect.to.open.stack.com" openstack.change_tenant_quotas = mock.MagicMock() openstack.update_user = mock.MagicMock() openstack.stop_instances = mock.MagicMock() openstack.start_instances = mock.MagicMock() openstack.client_neutron.create_network = mock.MagicMock(side_effect=Network) openstack.client_neutron.create_subnet = mock.MagicMock(side_effect=Subnet) openstack.client_neutron.create_router = mock.MagicMock(side_effect=Router) openstack.client_neutron.add_interface_router = mock.MagicMock() openstack.client_neutron.list_floatingips = mock.MagicMock(return_value={"floatingips": []}) openstack.client_neutron.list_routers = mock.MagicMock(return_value={"routers": []}) openstack.client_neutron.list_networks = mock.MagicMock(return_value={"networks": []}) openstack.client_neutron.list_subnets = mock.MagicMock(return_value={"subnets": []}) openstack.client_neutron.list_ports = mock.MagicMock(return_value={"ports": []}) openstack.client_neutron.list_security_groups = mock.MagicMock(return_value={"security_groups": []}) openstack.client_neutron.list_vpnservices = mock.MagicMock(return_value={"vpnservices": []}) super().setUp()
def setUp(self): """Stuff to do before every test.""" # Get the Flask test client self.client = controller.app.test_client() # Show Flask errors that happen during tests controller.app.config['TESTING'] = True # Connect to test database # @todo set from environment config connect_to_db(controller.app, 'postgresql:///dogwalker') # # Create tables and add sample data db.drop_all() db.create_all() # # Populate the test data populate_business() populate_users() populate_animals() populate_people() populate_services() populate_reservations()
def tearDown(self): """Do at the end of every test.""" db.session.close() db.drop_all()
def tearDown(self): """Stub function for later.""" print "(tearDown ran)" db.session.close() db.drop_all()
def tearDown(self): """Clear db for next test.""" db.session.close() db.drop_all()
def tearDown(cls): """Do after all tests have run.""" db.session.close() db.drop_all()
def tearDown(self): """Stuff to do after each test.""" db.session.close() db.drop_all()
import sys sys.path.append("../src/") from model import db,User print("Query all users:") users = User.query.all() print(users) newusers = [] print("Copy data to new users and set their beans to 10000...") for user in users: newuser = User(user.username,user.password,user.avatar,user.nickname,user.description,user.status, user.e_mail,user.student_number,user.department,user.truename,user.tel,user.register_date, user.user_group,user.auth_method) newuser.beans = 10000 newusers.append(newuser) print("Drop all table...") db.drop_all(bind='__all__') print("Create all tables with beans...") setattr(User,'beans',db.Column(db.Integer)) db.create_all(bind='__all__') for newuser in newusers: db.session.add(newuser) db.session.commit() print("Update users table successfully!")
def setUp(self): db.drop_all() db.create_all()
def tearDown(self): """Remove testing db""" db.session.remove() db.drop_all() print "teardown ran"
def tearDown(self): """What you need to do at the end of every test.""" db.session.close() db.drop_all()
def dropall(): "Drops all database tables" if prompt_bool("Are you sure ? You will lose all your data !"): db.drop_all()
def tearDown(self): """Completes after every individual test.""" db.session.close() db.drop_all()
def load_user_chore(): """Load user chores from user_chore into database.""" seed_file = open("seed_data/user_chore") for line in seed_file: line = line.rstrip() seed_line = line.split("\t") new_user_chore = UserChore( user_id=int(seed_line[0]), chore_id=int(seed_line[1]), due_date=datetime.strptime(seed_line[2], "%w, %m/%d/%y")) db.session.add(new_user_chore) db.session.commit() if __name__ == "__main__": connect_to_db(app) db.drop_all() db.create_all() # import pdb; pdb.set_trace() load_houses() load_users() load_chore() load_house_chore() load_user_chore()
def dropTable(): try: db.drop_all() return json.dumps({'status':True}) except IntegrityError: return json.dumps({'status':False})
def tearDown(self): #: called after the test is run (close shit) db.session.remove() # REALLY IMPORTANT to do this before the one below, otherwise can't run more than one test db.drop_all() #: get rid of tables print '===> teardown: end'
def refresh_db(): with app.app_context(): db.drop_all() db.create_all() db.session.add(User(username='******', email='*****@*****.**')) db.session.commit()
def tearDown(self): db.session.remove() db.drop_all()
def tearDown(self): """Do at end of every test.""" db.drop_all()
def tearDown(self): """Do at end of every test.""" # (uncomment when testing database) db.session.close() db.drop_all()
def sample_data(): """create sample data""" # In case this is run more than once, dump existing data db.drop_all() db.create_all() # Add sample Uers user1 = User(user_name='Kelly', password='******', email='*****@*****.**') user2 = User(user_name='Kate', password='******', email='*****@*****.**') user3 = User(user_name='Jack', password='******', email='*****@*****.**') db.session.add_all([user1, user2, user3]) db.session.commit() kelly_id = User.query.filter_by(user_name='Kelly').first().user_id kate_id = User.query.filter_by(user_name='Kate').first().user_id jack_id = User.query.filter_by(user_name='Jack').first().user_id # Add sample locations location1 = Location(location_name='New York') location2 = Location(location_name='San Francisco') location3 = Location(location_name='Rome') location4 = Location(location_name='Tokyo') db.session.add_all([location1, location2, location3, location4]) db.session.commit() NY = Location.query.filter_by(location_name='New York').first().location_id SF = Location.query.filter_by(location_name='San Francisco').first().location_id RM = Location.query.filter_by(location_name='Rome').first().location_id TK = Location.query.filter_by(location_name='Tokyo').first().location_id # Add sample lists list1 = List(list_name='My New York', user_id=kelly_id, location_id=NY) list2 = List(list_name='I love SF', user_id=kate_id, location_id=SF) list3 = List(list_name='Rome yay', user_id=jack_id, location_id=RM) list4 = List(list_name='Kate NYC', user_id=kate_id, location_id=NY) list5 = List(list_name='Kelly SF', user_id=kelly_id, location_id=SF) list6 = List(list_name='Rome in Summer', user_id=kelly_id, location_id=RM) list7 = List(list_name='Tokyo with Noel', user_id=kelly_id, location_id=TK) db.session.add_all([list1, list2, list3, list4, list5, list6, list7]) db.session.commit() lst1 = List.query.filter_by(list_name='My New York').first().list_id lst2 = List.query.filter_by(list_name='I love SF').first().list_id lst3 = List.query.filter_by(list_name='Rome yay').first().list_id lst4 = List.query.filter_by(list_name='Kate NYC').first().list_id lst5 = List.query.filter_by(list_name='Kelly SF').first().list_id lst6 = List.query.filter_by(list_name='Rome in Summer').first().list_id lst7 = List.query.filter_by(list_name='Tokyo with Noel').first().list_id # Add sample categories category1 = Category(category_name='restaurant') category2 = Category(category_name='museum') category3 = Category(category_name='bar') db.session.add_all([category1, category2, category3]) db.session.commit() r1 = Category.query.filter_by(category_name='restaurant').first().category_id r2 = Category.query.filter_by(category_name='museum').first().category_id r3 = Category.query.filter_by(category_name='bar').first().category_id # Add sample items for lists item1 = Item(item_name='PickMeUp', item_comments='our favorite cafe from college', item_address='address, ny', list_id=lst1, category_id=r1) item2 = Item(item_name='Foreign Cinema', item_comments='fried chicken', item_address='address, sf', list_id=lst2, category_id=r1) item3 = Item(item_name='San Crispino', item_comments='eat all the gelato', item_address='address, rome', list_id=lst3, category_id=r1) item4 = Item(item_name='The Vatican', item_comments='Amazing assortment of tourists, all the people watching', item_address='Vatican City', list_id=lst6, category_id=r2) item5 = Item(item_name="Rocco's", item_comments='cannoli and cheesecake', item_address='400 Bleeker St, NY, NY', list_id=lst4, category_id=r1) item6 = Item(item_name='Brothers Korean BBQ', item_comments='Bi Bim Bop!', item_address='Geary at 6th St, SF, CA', list_id=lst5, category_id=r3) item7 = Item(item_name='Robot Cafe', item_comments='Robot waiters', item_address='Tokyo', list_id=lst7, category_id=r3) #Add all the data to the session db.session.add_all([ item1, item2, item3, item4, item5, item6, item7 ]) #commit data to the database db.session.commit()
def tearDown(self): db.session.close() db.drop_all()
def tearDown(self): """ Delete our testing database """ db.session.remove() db.drop_all()