Beispiel #1
0
def finalizer() -> None:
    """
    Cleans up the DB after testing. Must be called as part of the test environment teardown.
    """
    _restore_default()
    loop = _LOOP
    loop._selector = _SELECTOR
    loop.run_until_complete(Tortoise._drop_databases())
Beispiel #2
0
def finalizer():
    """
    Cleans up the DB after testing. Must be called as part of the test environment teardown.
    """
    Tortoise.apps = deepcopy(_APPS)
    Tortoise._connections = _CONNECTIONS.copy()
    loop = _asyncio.get_event_loop()
    loop.run_until_complete(Tortoise._drop_databases())
Beispiel #3
0
async def initialize_tests(event_loop, request):
    await Tortoise.init(config=tortoise_orm, _create_db=True)
    await generate_schema_for_client(Tortoise.get_connection("default"),
                                     safe=True)

    client = Tortoise.get_connection("default")
    if client.schema_generator is MySQLSchemaGenerator:
        Migrate.ddl = MysqlDDL(client)
    elif client.schema_generator is SqliteSchemaGenerator:
        Migrate.ddl = SqliteDDL(client)
    elif client.schema_generator is AsyncpgSchemaGenerator:
        Migrate.ddl = PostgresDDL(client)
    Migrate.dialect = Migrate.ddl.DIALECT
    request.addfinalizer(
        lambda: event_loop.run_until_complete(Tortoise._drop_databases()))
Beispiel #4
0
async def initialize_tests(event_loop, request):
    tortoise_orm["connections"]["diff_models"] = "sqlite://:memory:"
    tortoise_orm["apps"]["diff_models"] = {
        "models": ["tests.diff_models"],
        "default_connection": "diff_models",
    }

    await Tortoise.init(config=tortoise_orm, _create_db=True)
    await generate_schema_for_client(Tortoise.get_connection("default"), safe=True)

    client = Tortoise.get_connection("default")
    if client.schema_generator is MySQLSchemaGenerator:
        Migrate.ddl = MysqlDDL(client)
    elif client.schema_generator is SqliteSchemaGenerator:
        Migrate.ddl = SqliteDDL(client)
    elif client.schema_generator is AsyncpgSchemaGenerator:
        Migrate.ddl = PostgresDDL(client)

    request.addfinalizer(lambda: event_loop.run_until_complete(Tortoise._drop_databases()))