Skip to content

Commit 22d4f22

Browse files
committed
fixes
1 parent a32684b commit 22d4f22

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

backend/app/crud/credentials.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from app.core.providers import (
88
validate_provider,
99
validate_provider_credentials,
10-
get_supported_providers,
1110
)
1211
from app.core.security import encrypt_credentials, decrypt_credentials
1312
from app.core.util import now

backend/app/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from starlette.middleware.cors import CORSMiddleware
66

77
from app.api.main import api_router
8-
from app.api.deps import http_exception_handler
98
from app.core.config import settings
109
from app.core.exception_handlers import register_exception_handlers
1110

backend/app/tests/crud/documents/test_crud_document_delete.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from app.models import Document
77

88
from app.tests.utils.document import DocumentStore
9+
from app.core.exception_handlers import HTTPException
910

1011

1112
@pytest.fixture
@@ -36,5 +37,8 @@ def test_cannot_delete_others_documents(self, db: Session):
3637
other_owner_id = store.documents.index.peek()
3738

3839
crud = DocumentCrud(db, other_owner_id)
39-
with pytest.raises(NoResultFound):
40+
with pytest.raises(HTTPException) as exc_info:
4041
crud.delete(document.id)
42+
43+
assert exc_info.value.status_code == 404
44+
assert "Document not found" in str(exc_info.value.detail)

backend/app/tests/crud/documents/test_crud_document_read_one.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from app.crud import DocumentCrud
66

77
from app.tests.utils.document import DocumentStore
8+
from app.core.exception_handlers import HTTPException
89

910

1011
@pytest.fixture
@@ -25,9 +26,13 @@ def test_cannot_select_invalid_id(self, db: Session, store: DocumentStore):
2526
document = next(store.documents)
2627

2728
crud = DocumentCrud(db, store.owner)
28-
with pytest.raises(NoResultFound):
29+
30+
with pytest.raises(HTTPException) as exc_info:
2931
crud.read_one(document.id)
3032

33+
assert exc_info.value.status_code == 404
34+
assert "Document not found" in str(exc_info.value.detail)
35+
3136
def test_cannot_read_others_documents(
3237
self,
3338
db: Session,
@@ -37,5 +42,8 @@ def test_cannot_read_others_documents(
3742
other = DocumentStore(db)
3843

3944
crud = DocumentCrud(db, other.owner)
40-
with pytest.raises(NoResultFound):
45+
with pytest.raises(HTTPException) as exc_info:
4146
crud.read_one(document.id)
47+
48+
assert exc_info.value.status_code == 404
49+
assert "Document not found" in str(exc_info.value.detail)

backend/app/tests/crud/test_api_key.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from app.models import APIKey, User, Organization
66
from app.tests.utils.utils import random_email
77
from app.core.security import get_password_hash, verify_password, decrypt_api_key
8+
from app.core.exception_handlers import HTTPException
89

910

1011
# Helper function to create a user
@@ -77,18 +78,18 @@ def test_get_api_keys_by_organization(db: Session) -> None:
7778
assert key.user_id in [user1.id, user2.id]
7879

7980

80-
def test_delete_api_key(db: Session) -> None:
81+
def test_delete_api_key_already_deleted(db: Session) -> None:
8182
user = create_test_user(db)
8283
org = create_test_organization(db)
8384

8485
api_key = api_key_crud.create_api_key(db, org.id, user.id)
8586
api_key_crud.delete_api_key(db, api_key.id)
8687

87-
deleted_key = db.exec(select(APIKey).where(APIKey.id == api_key.id)).first()
88+
with pytest.raises(HTTPException) as exc_info:
89+
api_key_crud.delete_api_key(db, api_key.id)
8890

89-
assert deleted_key is not None
90-
assert deleted_key.is_deleted is True
91-
assert deleted_key.deleted_at is not None
91+
assert exc_info.value.status_code == 404
92+
assert "already deleted" in str(exc_info.value.detail)
9293

9394

9495
def test_delete_api_key_already_deleted(db: Session) -> None:
@@ -98,9 +99,12 @@ def test_delete_api_key_already_deleted(db: Session) -> None:
9899
api_key = api_key_crud.create_api_key(db, org.id, user.id)
99100
api_key_crud.delete_api_key(db, api_key.id)
100101

101-
with pytest.raises(ValueError, match="API key not found or already deleted"):
102+
with pytest.raises(HTTPException) as exc_info:
102103
api_key_crud.delete_api_key(db, api_key.id)
103104

105+
assert exc_info.value.status_code == 404
106+
assert "already deleted" in exc_info.value.detail
107+
104108

105109
def test_get_api_key_by_value(db: Session) -> None:
106110
user = create_test_user(db)

0 commit comments

Comments
 (0)