Skip to content

Commit

Permalink
dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
azliu0 committed Apr 16, 2024
1 parent bbe8baa commit 673b6e6
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions server_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,6 @@ def redis_host():
yield host


@pytest.fixture(scope="session")
def app(db_url: str, redis_host: str):
os.environ["DATABASE_URL"] = db_url
os.environ["REDIS_HOST"] = redis_host

app = create_app()
app.config.update(
{
"TESTING": True,
}
)

with app.app_context():
from server_tests.utils import seed_database
seed_database()

yield app


@pytest.fixture(autouse=True)
def mock_openai_chat_completion():
"""Mock the OpenAI chat completion API."""
Expand Down Expand Up @@ -127,6 +108,28 @@ def mock_openai_embeddings():
yield mock


@pytest.fixture(scope="session")
def app(
db_url: str, redis_host: str, mock_openai_chat_completion, mock_openai_embeddings
):
os.environ["DATABASE_URL"] = db_url
os.environ["REDIS_HOST"] = redis_host

app = create_app()
app.config.update(
{
"TESTING": True,
}
)

with app.app_context():
from server_tests.utils import seed_database

seed_database()

yield app


@pytest.fixture(autouse=True)
def enable_transactional_tests(app: APIFlask):
"""Enables fast independent tests by rolling back changes made during every test.
Expand Down

0 comments on commit 673b6e6

Please sign in to comment.