def fresh_database(): engine = create_engine("sqlite:///:memory:") with patch.object(Session, "__init__", return_value=None), \ patch.object(Session, "session_class", side_effect=sessionmaker(bind=engine)),\ patch("database.engine", return_value=engine): create_schema(engine_=engine) yield
def setUp(self): create_schema() self.user = User(email = "*****@*****.**", display_name = "First Last") self.another_user = User(email = "*****@*****.**", display_name = "Yet another User") db.session.add(self.user) db.session.add(self.another_user) db.session.commit() self.sender = Sender() self.sender._send_email = Mock()
def setUp(self): create_schema() self.sender = Mock() self.trader = Trader(self.sender) self.buyer = User(email = "*****@*****.**", display_name = "Buyer") self.seller = User(email = "*****@*****.**", display_name = "Seller") db.session.add(self.buyer) db.session.add(self.seller) db.session.commit()
def setUp(self): create_schema() self.user = User(email="*****@*****.**", display_name="First Last") self.another_user = User(email="*****@*****.**", display_name="Yet another User") db.session.add(self.user) db.session.add(self.another_user) db.session.commit() self.sender = Sender() self.sender._send_email = Mock()
def client(): app.config['TESTING'] = True database.engine = create_engine("sqlite:///") with app.test_client() as client: database.create_schema() with database.Session() as s: s.add(Person(id=ID, name=NAME, age=AGE, address=ADDRESS, work=WORK)) yield client
def setUp(self): create_schema() self.user = User(email = "*****@*****.**", display_name = "First Last") self.another_user = User(email = "*****@*****.**", display_name = "Yet another user") self.email = Email(purpose = "verify") self.user.active_emails.append(self.email) db.session.add(self.user) db.session.add(self.another_user) db.session.commit() self.sender = Mock() self.trader = Mock() self.responder = Responder(self.sender, self.trader)
def setUp(self): create_schema() self.user = User(email="*****@*****.**", display_name="First Last") self.another_user = User(email="*****@*****.**", display_name="Yet another user") self.email = Email(purpose="verify") self.user.active_emails.append(self.email) db.session.add(self.user) db.session.add(self.another_user) db.session.commit() self.sender = Mock() self.trader = Mock() self.responder = Responder(self.sender, self.trader)
def main(): try: db.create_pool() with db.get_connection() as conn: db.create_schema(conn) if settings.WEBHOOK_ENABLED: start_webhook( dispatcher=dp, webhook_path=settings.WEBHOOK_PATH, skip_updates=True, on_startup=bot_startup, host=settings.WEBAPP_HOST, port=settings.WEBAPP_PORT, ) else: executor.start_polling(dp, on_startup=bot_startup, on_shutdown=bot_shutdown) finally: db.close_pool()
def start_master(): logger.debug("Launching master daemon") database.setup_db() database.create_schema() if config.insert_inital_data: database.insert_initial_data() # Start celery worker to consume results fn = get_user_demote() if fn is None: process = Popen([ "celery", "worker", "--app=celerycontrol", "-l", "info", "-Q", "results" ]) else: process = Popen([ "celery", "worker", "--app=celerycontrol", "-l", "info", "-Q", "results" ], preexec_fn=fn) master_api.setup.run()
def scrape_websites(): data_sets = [] possible_data_sets = [ scrape_best_colleges(), scrape_niche(), scrape_us_news(), scrape_college_raptor(), scrape_best_schools() ] for ds in possible_data_sets: if isinstance(ds, dict): data_sets.append(ds) else: print ds + " is broken" # the broken url is returned from scraper in the case of failure school_list = combine_data_sets(data_sets) if school_list is None: print "Data set is broken" sys.exit(1) proper_names = parse_school_names(school_list) final_list = calculate_average_rank_and_location(proper_names) database.delete_tables() database.create_schema() con = database.connect_db() cursor = con.cursor() for name, info in final_list.iteritems(): if not info[0]: continue database.add_school(name, info, con, cursor) cursor.close() con.close()
import database as db db.create_schema()
def setup_module(module): conn = connect(DB) create_schema(conn)
def request_delete_order(order_uid): """ Вернуть заказ """ with database.Session() as s: order = s.query(Order).filter( Order.order_uid == order_uid).one_or_none() if not order: return {"message": "Order not found"}, 404 if not requests.get( f"http://{WAREHOUSE_SERVICE_URL}/manage/health").ok: return {"message": "Warehouse sevice unavailable"}, 422 warehouse_service_response = requests.delete( f"http://{WAREHOUSE_SERVICE_URL}{ROOT_PATH}/warehouse/{order.item_uid}", ) if not warehouse_service_response.ok: return {"message": "Order not found on warehouse"}, 422 s.delete(order) return '', 204 if __name__ == '__main__': PORT = os.environ.get("PORT", 7777) print("LISTENING ON PORT:", PORT, "($PORT)") database.create_schema() app.url_map.strict_slashes = False app.run("0.0.0.0", PORT)
url = safe_url % (db_pass[0][1]) os.environ["OZAUR_DB_URL"] = url vpc = boto.vpc.connect_to_region("us-west-2") print "Allowing us to talk to DB" group_id = db_security_groups[0] args = { "group_id": db_security_groups[0], "ip_protocol": "tcp", "cidr_ip": requests.get("http://ip.42.pl/raw").text + "/32", "to_port": instance["Endpoint"]["Port"], "from_port": instance["Endpoint"]["Port"], } response = vpc.authorize_security_group(**args) assert response, "Can't authorize RDS to talk with me" import database print "Deleting DB schema" database.delete_schema() print "Creating DB schema" database.create_schema() print "Removing us from being able to talk to DB" response = vpc.revoke_security_group(**args) assert response, "Can't revoke RDS to talk with me"
def setUpClass(cls) -> None: """Create the expected schema in the test database""" drop_all_user_databases() database_name = "database_name" query_list = list( create_database(database_name, "Latin1_General_CS_AS")) schema_name = "schema_name" query_list.extend(create_schema(database_name, schema_name)) table_name = "table_name" fields = [{ 'pk': { 'sql-datatype': 'int', 'selected-by-default': True, 'inclusion': 'automatic' } }, { 'column_name': { 'sql-datatype': 'int', 'selected-by-default': True, 'inclusion': 'available' } }] schema = { 'type': 'object', 'properties': { 'column_name': { 'type': ['integer', 'null'], 'minimum': -2147483648, 'maximum': 2147483647, 'inclusion': 'available', 'selected': True }, 'pk': { 'type': ['integer'], 'minimum': -2147483648, 'maximum': 2147483647, 'inclusion': 'automatic', 'selected': True } }, 'selected': True } cls.EXPECTED_METADATA = { '{}_{}_{}'.format(database_name, schema_name, table_name): { 'is-view': False, 'schema-name': schema_name, 'row-count': 0, 'values': [(0, 1), (1, 2)], 'table-key-properties': {'pk'}, 'selected': None, 'database-name': database_name, 'stream_name': table_name, 'fields': fields, 'schema': schema }, } column_name = ["pk", "column_name"] column_type = ["int", "int"] primary_key = {"pk"} column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend( create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) query_list.extend( insert( database_name, schema_name, table_name, cls.EXPECTED_METADATA['{}_{}_{}'.format( database_name, schema_name, table_name)]["values"])) table_name = "TABLE_NAME" cls.EXPECTED_METADATA['{}_{}_{}'.format(database_name, schema_name, table_name)] = { 'is-view': False, 'schema-name': schema_name, 'row-count': 0, 'values': [(0, 3), (1, 4)], 'table-key-properties': {'pk'}, 'selected': None, 'database-name': database_name, 'stream_name': table_name, 'fields': fields, 'schema': schema } column_name = ["pk", "column_name"] column_type = ["int", "int"] primary_key = {"pk"} column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend( create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) query_list.extend( insert( database_name, schema_name, table_name, cls.EXPECTED_METADATA['{}_{}_{}'.format( database_name, schema_name, table_name)]["values"])) schema_name = "SCHEMA_NAME" query_list.extend(create_schema(database_name, schema_name)) table_name = "table_name" cls.EXPECTED_METADATA['{}_{}_{}'.format(database_name, schema_name, table_name)] = { 'is-view': False, 'schema-name': schema_name, 'row-count': 0, 'values': [(0, 5), (1, 6)], 'table-key-properties': {'pk'}, 'selected': None, 'database-name': database_name, 'stream_name': table_name, 'fields': fields, 'schema': schema } column_name = ["pk", "column_name"] column_type = ["int", "int"] primary_key = {"pk"} column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend( create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) query_list.extend( insert( database_name, schema_name, table_name, cls.EXPECTED_METADATA['{}_{}_{}'.format( database_name, schema_name, table_name)]["values"])) table_name = "TABLE_NAME" cls.EXPECTED_METADATA['{}_{}_{}'.format(database_name, schema_name, table_name)] = { 'is-view': False, 'schema-name': schema_name, 'row-count': 0, 'values': [(0, 7), (1, 8)], 'table-key-properties': {'pk'}, 'selected': None, 'database-name': database_name, 'stream_name': table_name, 'fields': fields, 'schema': schema } column_name = ["pk", "column_name"] column_type = ["int", "int"] primary_key = {"pk"} column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend( create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) query_list.extend( insert( database_name, schema_name, table_name, cls.EXPECTED_METADATA['{}_{}_{}'.format( database_name, schema_name, table_name)]["values"])) database_name = "DATABASE_NAME_NO_COLLISION" query_list.extend( create_database(database_name, "Latin1_General_CS_AS")) schema_name = "schema_name" query_list.extend(create_schema(database_name, schema_name)) table_name = "table_name" cls.EXPECTED_METADATA['{}_{}_{}'.format(database_name, schema_name, table_name)] = { 'is-view': False, 'schema-name': schema_name, 'row-count': 0, 'values': [(0, 9), (1, 10)], 'table-key-properties': {'pk'}, 'selected': None, 'database-name': database_name, 'stream_name': table_name, 'fields': fields, 'schema': schema } column_name = ["pk", "column_name"] column_type = ["int", "int"] primary_key = {"pk"} column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend( create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) query_list.extend( insert( database_name, schema_name, table_name, cls.EXPECTED_METADATA['{}_{}_{}'.format( database_name, schema_name, table_name)]["values"])) table_name = "TABLE_NAME" cls.EXPECTED_METADATA['{}_{}_{}'.format(database_name, schema_name, table_name)] = { 'is-view': False, 'schema-name': schema_name, 'row-count': 0, 'values': [(0, 11), (1, 12)], 'table-key-properties': {'pk'}, 'selected': None, 'database-name': database_name, 'stream_name': table_name, 'fields': fields, 'schema': schema } column_name = ["pk", "column_name"] column_type = ["int", "int"] primary_key = {"pk"} column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend( create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) query_list.extend( insert( database_name, schema_name, table_name, cls.EXPECTED_METADATA['{}_{}_{}'.format( database_name, schema_name, table_name)]["values"])) schema_name = "SCHEMA_NAME" query_list.extend(create_schema(database_name, schema_name)) table_name = "table_name" cls.EXPECTED_METADATA['{}_{}_{}'.format(database_name, schema_name, table_name)] = { 'is-view': False, 'schema-name': schema_name, 'row-count': 0, 'values': [(0, 13), (1, 14)], 'table-key-properties': {'pk'}, 'selected': None, 'database-name': database_name, 'stream_name': table_name, 'fields': fields, 'schema': schema } column_name = ["pk", "column_name"] column_type = ["int", "int"] primary_key = {"pk"} column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend( create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) query_list.extend( insert( database_name, schema_name, table_name, cls.EXPECTED_METADATA['{}_{}_{}'.format( database_name, schema_name, table_name)]["values"])) table_name = "TABLE_NAME" cls.EXPECTED_METADATA['{}_{}_{}'.format(database_name, schema_name, table_name)] = { 'is-view': False, 'schema-name': schema_name, 'row-count': 0, 'values': [(0, 15), (1, 16)], 'table-key-properties': {'pk'}, 'selected': None, 'database-name': database_name, 'stream_name': table_name, 'fields': fields, 'schema': schema } column_name = ["pk", "column_name"] column_type = ["int", "int"] primary_key = {"pk"} column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend( create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) query_list.extend( insert( database_name, schema_name, table_name, cls.EXPECTED_METADATA['{}_{}_{}'.format( database_name, schema_name, table_name)]["values"])) mssql_cursor_context_manager(*query_list) cls.expected_metadata = cls.discovery_expected_metadata
return "BlogPost(%r, %r, %r)" % (self.headline, self.body, self.author) class Keyword(Base): __tablename__ = 'keywords' id = Column(Integer, primary_key=True) keyword = Column(String(50), nullable=False, unique=True) def __init__(self, keyword): self.keyword = keyword BlogPost.author = relationship('User', backref=backref('posts', lazy='dynamic')) ''' create_schema() session = create_session() manager = Position(name='manager', description='manager') senior_manager = Position(name='senior manager', description='senior manager') session.add(manager) session.add(senior_manager) group1 = Group(name='group1', description='group1') group2 = Group(name='group2', description='group2') department1 = Department(name='accounting', description='department of accounting') department2 = Department(name='marine', description='school of marine science')
def setUpClass(cls) -> None: """Create the expected schema in the test database""" drop_all_user_databases() database_name = "database_name" query_list = list(create_database(database_name, "Latin1_General_CS_AS")) schema_name = "schema_name" query_list.extend(create_schema(database_name, schema_name)) table_name = "table_name" column_name = ["column_name"] column_type = ["int"] primary_key = set() column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend(create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) cls.add_expected_metadata(cls, database_name, schema_name, table_name, column_name, column_type, primary_key) table_name = "TABLE_NAME" column_name = ["column_name"] column_type = ["int"] primary_key = set() column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend(create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) cls.add_expected_metadata(cls, database_name, schema_name, table_name, column_name, column_type, primary_key) schema_name = "SCHEMA_NAME" query_list.extend(create_schema(database_name, schema_name)) table_name = "table_name" column_name = ["column_name"] column_type = ["int"] primary_key = set() column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend(create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) cls.add_expected_metadata(cls, database_name, schema_name, table_name, column_name, column_type, primary_key) table_name = "TABLE_NAME" column_name = ["column_name"] column_type = ["int"] primary_key = set() column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend(create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) cls.add_expected_metadata(cls, database_name, schema_name, table_name, column_name, column_type, primary_key) database_name = "DATABASE_NAME_NO_COLLISION" query_list.extend(create_database(database_name, "Latin1_General_CS_AS")) schema_name = "schema_name" query_list.extend(create_schema(database_name, schema_name)) table_name = "table_name" column_name = ["column_name"] column_type = ["int"] primary_key = set() column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend(create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) cls.add_expected_metadata(cls, database_name, schema_name, table_name, column_name, column_type, primary_key) table_name = "TABLE_NAME" column_name = ["column_name"] column_type = ["int"] primary_key = set() column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend(create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) cls.add_expected_metadata(cls, database_name, schema_name, table_name, column_name, column_type, primary_key) schema_name = "SCHEMA_NAME" query_list.extend(create_schema(database_name, schema_name)) table_name = "table_name" column_name = ["column_name"] column_type = ["int"] primary_key = set() column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend(create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) cls.add_expected_metadata(cls, database_name, schema_name, table_name, column_name, column_type, primary_key) table_name = "TABLE_NAME" column_name = ["column_name"] column_type = ["int"] primary_key = set() column_def = [" ".join(x) for x in list(zip(column_name, column_type))] query_list.extend(create_table(database_name, schema_name, table_name, column_def, primary_key=primary_key)) cls.add_expected_metadata(cls, database_name, schema_name, table_name, column_name, column_type, primary_key) mssql_cursor_context_manager(*query_list) cls.expected_metadata = cls.discovery_expected_metadata