Exemplo n.º 1
0
def client():
    """Test client."""
    db_url = f"postgres://*****:*****@localhost:5432/testing"
    initializer(settings.DB_MODELS)
    with TestClient(app) as c:
        yield c
    finalizer()
Exemplo n.º 2
0
def client() -> Generator:
    '''
    Generates a TestClient instance for models.user
    '''
    initializer(["app.models"])
    with TestClient(app) as test_client:
        yield test_client
    finalizer()
Exemplo n.º 3
0
def client() -> Generator:
    # setup test database and test client for all test cases
    initializer(["app.models"],
                db_url=f'postgres://{settings.PG_USER}:{settings.PG_PASSWORD}@{settings.PG_HOST}:{settings.PG_PORT}/test',
                app_label='app')
    with TestClient(app) as c:
        yield c
    # drop test database
    finalizer()
Exemplo n.º 4
0
def app() -> FastAPI:
    from app.app import app

    initializer(
        ["app.models"],
        db_url=os.environ["DATABASE_URL"],
    )
    yield app
    finalizer()
Exemplo n.º 5
0
def test_app():
    # set up
    app = create_application()  # new
    app.dependency_overrides[get_settings] = get_settings_override
    initializer(["app.models.tortoise"])
    with TestClient(app) as test_client:

        # testing
        yield test_client
    finalizer()
Exemplo n.º 6
0
def client() -> Generator:
    app = create_app(db_conn='sqlite', generate_schemas=True)
    # 初始化数据库
    initializer(['app.models'])

    with TestClient(app) as c:
        yield c

    # 测试完后清除数据
    finalizer()
Exemplo n.º 7
0
def test_app_with_db() -> Generator:
    app = create_application()
    app.dependency_overrides[get_settings] = get_settings_override
    initializer(db_url=os.environ.get("DATABASE_TEST_URL"),
                modules=["app.models.tortoise.users"])
    run_async(add_users())

    with TestClient(app) as test_client:
        yield test_client

    finalizer()
Exemplo n.º 8
0
async def client() -> Generator:
    """Async client with db connection."""
    nest_asyncio.apply()
    initializer(modules=APP_MODELS)
    app = create_application()
    async with AsyncClient(
            app=app,
            base_url="https://testserver") as test_client, LifespanManager(
                app):
        yield test_client
    finalizer()
Exemplo n.º 9
0
def client() -> Generator:
    # set up
    app = create_application()
    # app.dependency_overrides[get_settings] = get_settings_override
    settings = get_settings()
    initializer(["app.models"], db_url=settings.database_test_url)
    with TestClient(app) as test_client:

        # testing
        yield test_client
    finalizer()
Exemplo n.º 10
0
def client() -> Generator:
    # set up
    app = create_application()
    initializer(settings.MODELS, db_url=settings.TEST_DATABASE_URL)

    with TestClient(app) as test_client:

        # testing
        yield test_client

    # tear down
    finalizer()
Exemplo n.º 11
0
def yield_test_client(app, impl):
    if impl.__name__ == "tortoise_implementation":
        from tortoise.contrib.test import initializer, finalizer

        initializer(["tests.implementations.tortoise_"])
        with TestClient(app) as c:
            yield c
        finalizer()

    else:
        with TestClient(app) as c:
            yield c
Exemplo n.º 12
0
def event_loop(request):
    cfg = Config(".env")
    db_url = cfg.get("TEST_DB_URL", default="sqlite://:memory:")

    loop = asyncio.get_event_loop()
    initializer(["bnstats.models"],
                db_url=db_url,
                app_label="models",
                loop=loop)
    yield loop
    finalizer()
    loop.close()
Exemplo n.º 13
0
def client(request):
    impl = request.param

    if impl.__name__ == 'tortoise_implementation':
        from tortoise.contrib.test import initializer, finalizer

        initializer(["tests.implementations.tortoise_"])
        with TestClient(impl()) as c:
            yield c
        finalizer()

    else:
        yield TestClient(impl())
Exemplo n.º 14
0
def initialize_db_tests() -> None:
    db_url = os.environ.get("TORTOISE_TEST_DB", "sqlite://:memory:")
    initializer(
        [
            "mobilizon_reshare.models.event",
            "mobilizon_reshare.models.notification",
            "mobilizon_reshare.models.publication",
            "mobilizon_reshare.models.publisher",
        ],
        db_url=db_url,
        app_label="models",
    )
    yield None
    finalizer()
Exemplo n.º 15
0
def db():
    initializer(['app.events.models'], db_url=settings.DATABASE_TEST_URL)
    yield
    finalizer()
Exemplo n.º 16
0
 def tearDown(self) -> None:
     finalizer()
     return super().tearDown()
Exemplo n.º 17
0
def client() -> Generator:
    initializer(["models"])
    with TestClient(app) as c:
        yield c
    finalizer()
Exemplo n.º 18
0
def client():
    initializer(["app.models"])
    with TestClient(app) as test_client:
        yield test_client
    finalizer()
Exemplo n.º 19
0
    def tearDown(self) -> None:

        _flush_db = not hasattr(
            self, 'flush_db_at_the_end') or self.flush_db_at_the_end
        if _flush_db:
            finalizer()
Exemplo n.º 20
0
def pytest_runtest_teardown(item, nextitem):
    finalizer()
Exemplo n.º 21
0
 async def tearDownAsync(self) -> None:
     finalizer()
Exemplo n.º 22
0
def client():
    initializer(["users.models", "todos.models"])
    with TestClient(app) as c:
        yield c
    finalizer()
Exemplo n.º 23
0
def init_db() -> Generator:
    initializer(["app.models"], db_url="sqlite://test.sqlite3")
    yield
    finalizer()
Exemplo n.º 24
0
 def stopTestRun(self, event: Event) -> None:  # pylint: disable=R0201
     finalizer()
Exemplo n.º 25
0
def client() -> Generator:
    initializer([MODELS_MODULE])
    with TestClient(app) as c:
        yield c
    finalizer()
Exemplo n.º 26
0
 def stopTestRun(self, event: Event) -> None:
     finalizer()
Exemplo n.º 27
0
def client() -> Generator:
    initializer(['main'])
    with TestClient(app) as c:
        yield c
    finalizer()
 def tearDownClass(cls) -> None:
     finalizer()
Exemplo n.º 29
0
 def tearDown(self) -> None:
     finalizer()
Exemplo n.º 30
0
def client(event_loop):
    initializer(['app.models'])
    with TestClient(app) as client:
        yield client
    finalizer()