Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions backend/app/api/routes/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
router = APIRouter(prefix="/documents", tags=["documents"])


@router.get("/ls", response_model=APIResponse[List[Document]])
@router.get("/list", response_model=APIResponse[List[Document]])
def list_docs(
session: SessionDep,
current_user: CurrentUser,
Expand All @@ -35,7 +35,7 @@ def list_docs(
return APIResponse.success_response(data)


@router.post("/cp", response_model=APIResponse[Document])
@router.post("/upload", response_model=APIResponse[Document])
def upload_doc(
session: SessionDep,
current_user: CurrentUser,
Expand Down Expand Up @@ -68,10 +68,10 @@ def upload_doc(


@router.get(
"/rm/{doc_id}",
"/remove/{doc_id}",
response_model=APIResponse[Document],
)
def delete_doc(
def remove_doc(
session: SessionDep,
current_user: CurrentUser,
doc_id: UUID,
Expand All @@ -91,7 +91,7 @@ def delete_doc(
return APIResponse.success_response(data)


@router.get("/stat/{doc_id}", response_model=APIResponse[Document])
@router.get("/info/{doc_id}", response_model=APIResponse[Document])
def doc_info(
session: SessionDep,
current_user: CurrentUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

@pytest.fixture
def route():
return Route("stat")
return Route("info")


class TestDocumentRouteStat:
class TestDocumentRouteInfo:
def test_response_is_success(
self,
db: Session,
Expand All @@ -29,7 +29,7 @@ def test_response_is_success(

assert response.is_success

def test_stat_reflects_database(
def test_info_reflects_database(
self,
db: Session,
route: Route,
Expand All @@ -43,7 +43,7 @@ def test_stat_reflects_database(

assert source == target.data

def test_cannot_stat_unknown_document(
def test_cannot_info_unknown_document(
self,
db: Session,
route: Route,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def pushq(self, key, value):

@pytest.fixture
def route():
return QueryRoute("ls")
return QueryRoute("list")


class TestDocumentRouteList:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import openai_responses
from sqlmodel import Session, select

from app.models import Document
Expand All @@ -9,14 +10,18 @@
WebCrawler,
crawler,
)
from app.tests.utils.collection import get_collection
from app.tests.utils.utils import openai_credentials


@pytest.fixture
def route():
return Route("rm")
return Route("remove")


class TestDocumentRouteDelete:
@pytest.mark.usefixtures("openai_credentials")
class TestDocumentRouteRemove:
@openai_responses.mock()
def test_response_is_success(
self,
db: Session,
Expand All @@ -28,7 +33,8 @@ def test_response_is_success(

assert response.is_success

def test_item_is_soft_deleted(
@openai_responses.mock()
def test_item_is_soft_removed(
self,
db: Session,
route: Route,
Expand All @@ -44,7 +50,8 @@ def test_item_is_soft_deleted(

assert result.deleted_at is not None

def test_cannot_delete_unknown_document(
@openai_responses.mock()
def test_cannot_remove_unknown_document(
self,
db: Session,
route: Route,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def scratch():

@pytest.fixture
def route():
return Route("cp")
return Route("upload")


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from app.crud import CollectionCrud
from app.models import DocumentCollection
from app.tests.utils.document import DocumentStore
from app.tests.utils.collection import get_collection, openai_credentials
from app.tests.utils.collection import get_collection
from app.tests.utils.utils import openai_credentials


@pytest.mark.usefixtures("openai_credentials")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
from app.crud import CollectionCrud
from app.crud.rag import OpenAIAssistantCrud
from app.tests.utils.document import DocumentStore
from app.tests.utils.collection import (
get_collection,
openai_credentials,
uuid_increment,
)
from app.tests.utils.collection import get_collection, uuid_increment
from app.tests.utils.utils import openai_credentials


@pytest.mark.usefixtures("openai_credentials")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from app.core.config import settings
from app.models import Collection
from app.tests.utils.document import DocumentStore
from app.tests.utils.collection import get_collection, openai_credentials
from app.tests.utils.collection import get_collection
from app.tests.utils.utils import openai_credentials


def create_collections(db: Session, n: int):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
from app.core.config import settings
from app.crud import CollectionCrud
from app.tests.utils.document import DocumentStore
from app.tests.utils.collection import (
get_collection,
openai_credentials,
uuid_increment,
)
from app.tests.utils.collection import get_collection, uuid_increment
from app.tests.utils.utils import openai_credentials


def mk_collection(db: Session):
Expand Down
7 changes: 0 additions & 7 deletions backend/app/tests/utils/collection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from uuid import UUID

import pytest
from openai import OpenAI
from sqlmodel import Session

Expand All @@ -11,7 +10,6 @@

class constants:
openai_model = "gpt-4o"
openai_mock_key = "sk-fake123"
llm_service_name = "test-service-name"


Expand Down Expand Up @@ -47,8 +45,3 @@ def get_collection(db: Session, client=None):
llm_service_id=assistant.id,
llm_service_name=constants.llm_service_name,
)


@pytest.fixture(scope="class")
def openai_credentials():
settings.OPENAI_API_KEY = constants.openai_mock_key
6 changes: 6 additions & 0 deletions backend/app/tests/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
import string
from uuid import UUID

import pytest
from fastapi.testclient import TestClient
from sqlmodel import Session

from app.core.config import settings
from app.crud.user import get_user_by_email


@pytest.fixture(scope="class")
def openai_credentials():
settings.OPENAI_API_KEY = "sk-fake123"


def random_lower_string() -> str:
return "".join(random.choices(string.ascii_lowercase, k=32))

Expand Down