Ejemplo n.º 1
0
def test_get_engine_explicit_config(config_with_in_memory_database):
    """Check that created engine use proper connection string from explicit config.

    1. Provide database config explicitly to the method to create engine.
    2. Check that engine use connection string from config.
    """
    database_config = get_database_config(config_with_in_memory_database)
    engine = database_common.get_engine(database_config)
    assert str(engine.url) == database_config.get_connection_string(), "Wrong engine url"
Ejemplo n.º 2
0
def test_get_engine_implicit_config(config_with_in_memory_database, monkeypatch):
    """Check that created engine use proper connection string from implicit config.

    1. Provide database config implicitly to the method to create engine.
    2. Check that engine use connection string from config.
    """
    monkeypatch.setenv(ENV_DB_CONFIG_PATH, config_with_in_memory_database)
    engine = database_common.get_engine()
    database_config = get_database_config(config_with_in_memory_database)
    assert str(engine.url) == database_config.get_connection_string(), "Wrong engine url"
Ejemplo n.º 3
0
def create_all(database_config=None):
    """Create database tables using database config.

    :param database_config: config with information about database.
    """
    engine = get_engine(database_config)

    logger = logging.getLogger(__name__)
    logger.debug("Try to create all tables.")
    metadata = prepare_metadata()
    metadata.create_all(engine)

    logger.debug("Try to populate tables.")
    session = Session(bind=engine)
    session.add_all(_get_initial_records())
    session.commit()

    logger.info("Database has been created.")
Ejemplo n.º 4
0
 def __init__(self, database_config):
     engine = get_engine(database_config)
     self.__session_maker = sessionmaker(bind=engine)