Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve and tests #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pamelafox merged 31 commits into Azure-Samples:main from john0isaac:improve-and-tests
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
676a2eb
add pytest dependency
john0isaac Jun 28, 2024
296db5c
restrict workflow run and cache dependencies for faster reruns
john0isaac Jun 28, 2024
d41a6df
mypy fixes
john0isaac Jun 28, 2024
44446bb
add dataclasses for response for better typing and easier usage
john0isaac Jun 28, 2024
8c58aac
setup test client for database and without database with test coverag...
john0isaac Jun 28, 2024
a0522e6
fix tests for windows and macos
john0isaac Jun 28, 2024
06c424b
use basemodel instead of dataclass to match the other models and for ...
john0isaac Jun 29, 2024
cf3bc78
fix scopes and add app fixture
john0isaac Jun 29, 2024
4d9a536
fix tests to use existing setup
john0isaac Jul 1, 2024
7573249
add mocks and use monkey patch for setting env vars
john0isaac Jul 5, 2024
9fb9e54
create database and seed data
john0isaac Jul 5, 2024
61f9b8f
add tests for items handler and similar
john0isaac Jul 5, 2024
86b7986
add search_handler tests
john0isaac Jul 5, 2024
610a418
add chat tests
john0isaac Jul 5, 2024
eac85f0
remove content length assertion to allow for flexibility in response ...
john0isaac Jul 6, 2024
b36a260
add azure openai env vars and use session scoped fixutres
john0isaac Jul 6, 2024
ea722d7
Typing improvements
pamelafox Jul 11, 2024
addd3da
fix mypy module error
john0isaac Jul 12, 2024
5261ab2
typing improvements
john0isaac Jul 12, 2024
39abb0f
ignore pgvector from mypy checks
john0isaac Jul 12, 2024
121b341
follow sqlalchmey example for using columns()
john0isaac Jul 12, 2024
d0a9a02
reimplement abstract functions
john0isaac Jul 12, 2024
c5d99f5
fix typo in env var name
john0isaac Jul 12, 2024
5c17e9a
use fastapi dependency instead of global storage
john0isaac Jul 12, 2024
3a6076c
fix type and add mypy to tests
john0isaac Jul 12, 2024
da5220c
remove multiple env loading, use single azure_credentials
john0isaac Jul 12, 2024
79a8a2d
use app state to store global vars
john0isaac Jul 13, 2024
3f0286b
add pydatnic types for Item table
john0isaac Jul 13, 2024
02d0b1b
add more tests and fix azure credentials mocking
john0isaac Jul 15, 2024
17fc97f
apply feedback from pr review
john0isaac Jul 17, 2024
b2bb121
add postgres searcher tests
john0isaac Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
create database and seed data
  • Loading branch information
john0isaac committed Jul 5, 2024
commit 9fb9e54b7cd91eec24a0c3d5e93b58050c0c05dd
34 changes: 24 additions & 10 deletions tests/conftest.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
from unittest import mock

import pytest
import pytest_asyncio
from fastapi.testclient import TestClient
from sqlalchemy.ext.asyncio import async_sessionmaker

from fastapi_app import create_app
from fastapi_app.globals import global_storage
from fastapi_app.postgres_engine import create_postgres_engine_from_env
from fastapi_app.setup_postgres_database import create_db_schema
from fastapi_app.setup_postgres_seeddata import seed_data
from tests.mocks import MockAzureCredential

POSTGRES_HOST = "localhost"
Expand Down Expand Up @@ -51,12 +54,22 @@ def mock_session_env(monkeypatch_session):
yield


@pytest.fixture(scope="session")
def app(mock_session_env):
async def create_and_seed_db():
"""Create and seed the database."""
engine = await create_postgres_engine_from_env()
await create_db_schema(engine)
await seed_data(engine)
await engine.dispose()


@pytest_asyncio.fixture(scope="session")
async def app(mock_session_env):
"""Create a FastAPI app."""
if not Path("src/static/").exists():
pytest.skip("Please generate frontend files first!")
return create_app(testing=True)
app = create_app(testing=True)
await create_and_seed_db()
return app


@pytest.fixture(scope="function")
Expand All @@ -67,20 +80,21 @@ def mock_default_azure_credential(mock_session_env):
yield mock_default_azure_credential


@pytest.fixture(scope="function")
def test_client(monkeypatch, app, mock_default_azure_credential):
@pytest_asyncio.fixture(scope="function")
async def test_client(monkeypatch, app, mock_default_azure_credential):
"""Create a test client."""

with TestClient(app) as test_client:
yield test_client


@pytest.fixture(scope="function")
def db_session():
@pytest_asyncio.fixture(scope="function")
async def db_session():
"""Create a new database session with a rollback at the end of the test."""
async_sesion = async_sessionmaker(autocommit=False, autoflush=False, bind=global_storage.engine)
engine = await create_postgres_engine_from_env()
async_sesion = async_sessionmaker(autocommit=False, autoflush=False, bind=engine)
session = async_sesion()
session.begin()
yield session
session.rollback()
session.close()
await engine.dispose()
12 changes: 12 additions & 0 deletions tests/test_api_routes.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest


@pytest.mark.asyncio
async def test_chat_non_json_415(test_client):
"""test the chat route with a non-json request"""
response = test_client.post("/chat")

assert response.status_code == 422
assert response.headers["Content-Type"] == "application/json"
assert response.headers["Content-Length"] == "82"
assert b'{"detail":[{"type":"missing"' in response.content
11 changes: 0 additions & 11 deletions tests/test_endpoints.py → tests/test_frontend_routes.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,3 @@ async def test_assets(test_client):
assert response.status_code == 200
assert response.headers["Content-Length"] == str(len(assets_file))
assert assets_file == response.content


@pytest.mark.asyncio
async def test_chat_non_json_415(test_client):
"""test the chat route with a non-json request"""
response = test_client.post("/chat")

assert response.status_code == 422
assert response.headers["Content-Type"] == "application/json"
assert response.headers["Content-Length"] == "82"
assert b'{"detail":[{"type":"missing"' in response.content

AltStyle によって変換されたページ (->オリジナル) /