Exemple #1
0
def test_database_backend(
    monkeypatch: MonkeyPatch, sqlalchemy_database_uri: str, expected_backend: DatabaseBackend
) -> None:
    monkeypatch.setenv("DB_SQLALCHEMY_URI", sqlalchemy_database_uri)
    clear_caches()
    engine = get_engine()
    assert DatabaseBackend.from_engine(engine) == expected_backend
Exemple #2
0
 def test_reregister_fails(self, monkeypatch: MonkeyPatch,
                           registered_user: AuthUser) -> None:
     monkeypatch.setenv("API_DEBUG", "0")
     clear_caches()
     message = self._get_registration_response(APIMessage,
                                               HTTP_409_CONFLICT)
     assert message.detail == "This username is already in use"
Exemple #3
0
def test_postgres_sqlalchemy_uri(monkeypatch: MonkeyPatch) -> None:
    environment = {"DB_BACKEND": "postgresql", "DB_USER": "******", "DB_PASSWORD": "******", "DB_HOST": "c", "db_db": "d"}
    for k, v in environment.items():
        monkeypatch.setenv(k, v)

    clear_caches()
    assert get_database_settings().sqlalchemy_uri == "postgresql://*****:*****@c/d"
Exemple #4
0
def engine(monkeypatch_module: MonkeyPatch) -> sa.engine.Engine:
    sqlalchemy_database_uri = "sqlite:///./test.db"
    monkeypatch_module.setenv("DB_SQLALCHEMY_URI", sqlalchemy_database_uri)
    monkeypatch_module.setenv("DB_LOG_SQLALCHEMY_SQL_STATEMENTS", "1")

    clear_caches()

    return get_engine()
Exemple #5
0
def prod_environment(monkeypatch_module: MonkeyPatch) -> None:
    """
    Not necessarily reflective of a prod environment.
    Just makes it easier to test multiple environment settings.
    """
    monkeypatch_module.setenv("API_DEBUG", "0")
    monkeypatch_module.setenv("API_INCLUDE_ADMIN_ROUTES", "1")

    monkeypatch_module.setenv("DB_BACKEND", "sqlite")
    monkeypatch_module.setenv("DB_SQLALCHEMY_URI", "sqlite:///./test.db")
    monkeypatch_module.setenv("DB_LOG_SQLALCHEMY_SQL_STATEMENTS", "0")

    monkeypatch_module.setenv("AUTH_FIRST_SUPERUSER", ADMIN_USERNAME)
    monkeypatch_module.setenv("AUTH_FIRST_SUPERUSER_PASSWORD", ADMIN_PASSWORD)
    monkeypatch_module.setenv("AUTH_INCLUDE_EXPIRES_IN_WITH_TOKENS", "true")
    clear_caches()
Exemple #6
0
def get_app() -> FastAPI:
    app = FastAPI(debug=True)

    @app.get("/1")
    def endpoint_1() -> None:
        with expected_exceptions(ValueError, detail=None):
            raise ValueError("debug message 1")

    @app.get("/2")
    def endpoint_2() -> None:
        with expected_exceptions(ValueError, detail="prod message"):
            raise ValueError("debug message 2")

    setup_openapi(app)
    clear_caches()
    return app
Exemple #7
0
def test_db_settings(monkeypatch: MonkeyPatch, sqlalchemy_database_uri: str) -> None:
    monkeypatch.setenv("DB_SQLALCHEMY_URI", sqlalchemy_database_uri)

    clear_caches()
    assert get_database_settings().sqlalchemy_uri == sqlalchemy_database_uri
Exemple #8
0
def prod_environment(monkeypatch: MonkeyPatch) -> None:
    monkeypatch.setenv("API_DEBUG", "0")
    clear_caches()
Exemple #9
0
def debug_environment(monkeypatch: MonkeyPatch) -> None:
    monkeypatch.setenv("API_DEBUG", "1")
    clear_caches()
Exemple #10
0
def disable_superuser_environment(monkeypatch: MonkeyPatch) -> None:
    monkeypatch.setenv("API_INCLUDE_ADMIN_ROUTES", "1")
    monkeypatch.setenv("API_DISABLE_SUPERUSER_DEPENDENCY", "1")
    clear_caches()