Esempio n. 1
0
def initialize_db(database_name):
    os.environ['ENV'] = 'local'
    e = Environment('env')
    e.load_env()

    database_map = {
        DatabaseEnum.PET.value: DatabaseConfig.from_local_env(DatabaseEnum.PET.value)
    }

    register_databases(database_map)

    BaseDbModel.metadata.drop_all(engines.get_engine(database_name))
    BaseDbModel.metadata.create_all(engines.get_engine(database_name))
Esempio n. 2
0
    def _do_query(self, query, retries):
        if retries < 0:
            raise

        engine = engines.get_engine(self._db_name)
        connection = engine.connect()  # replace your connection
        try:
            return connection.execute(query)
        except Exception as err:  # may need more exceptions here (or trap all)
            connection.close()
            logger.error("Failed to perform query, will do retry")
            logger.error(err)
            # wait before retry
            time.sleep(5)
            self._do_query(query, retries - 1)
        finally:
            connection.close()
def setup_main_db():
    setup_db_for_tests(engines.get_engine("main"), main_metadata)
def teardown_main_db():
    tear_down_db_for_tests(engines.get_engine("main"))
def setup_pdf_db():
    setup_db_for_tests(engines.get_engine("pdf"), pdf_metadata)
def teardown_pdf_db():
    tear_down_db_for_tests(engines.get_engine("pdf"))
Esempio n. 7
0
 def __init__(self, db_name: str):
     self._engine = engines.get_engine(db_name)
     self._session_instance = self._create_session()
Esempio n. 8
0
 def tearDown(self):
     tear_down_db_for_tests(engines.get_engine("main"))
     tear_down_db_for_tests(engines.get_engine("pdf"))
Esempio n. 9
0
 def setUp(self):
     db_init()
     setup_db_for_tests(engines.get_engine("main"), main_models.metadata)
     setup_db_for_tests(engines.get_engine("pdf"), pdf_models.metadata)