fix: Remove global state (#1216)

* Remove all global settings state

* chore: remove autogenerated class

* chore: cleanup

* chore: merge conflicts
This commit is contained in:
Pablo Orgaz 2023-11-12 22:20:36 +01:00 committed by GitHub
parent f394ca61bb
commit 022bd718e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 286 additions and 190 deletions

View file

@ -8,7 +8,7 @@ NOTE: We are not testing the switch based on the config in
from typing import Annotated
import pytest
from fastapi import Depends, FastAPI
from fastapi import Depends
from fastapi.testclient import TestClient
from private_gpt.server.utils.auth import (
@ -29,15 +29,16 @@ def _copy_simple_authenticated(
@pytest.fixture(autouse=True)
def _patch_authenticated_dependency(current_test_app: FastAPI):
def _patch_authenticated_dependency(test_client: TestClient):
# Patch the server to use simple authentication
current_test_app.dependency_overrides[authenticated] = _copy_simple_authenticated
test_client.app.dependency_overrides[authenticated] = _copy_simple_authenticated
# Call the actual test
yield
# Remove the patch for other tests
current_test_app.dependency_overrides = {}
test_client.app.dependency_overrides = {}
def test_default_auth_working_when_enabled_401(test_client: TestClient) -> None:
@ -50,6 +51,6 @@ def test_default_auth_working_when_enabled_200(test_client: TestClient) -> None:
assert response_fail.status_code == 401
response_success = test_client.get(
"/v1/ingest/list", headers={"Authorization": settings.server.auth.secret}
"/v1/ingest/list", headers={"Authorization": settings().server.auth.secret}
)
assert response_success.status_code == 200