Skip to content

Commit

Permalink
Bugfix/pdct 664 update primary key constraint for physical document l…
Browse files Browse the repository at this point in the history
…anguage table (#56)

* PDCT-664 Updated primary key for physical doc language to include source.

* PDCT-664 Made user language name optional for doc create.

* PDCT-664 Added integration test for creating doc with null language.
  • Loading branch information
katybaulch authored Dec 7, 2023
1 parent 66f9429 commit 345cd4c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/model/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DocumentCreateDTO(BaseModel):
# From PhysicalDocument
title: str
source_url: str
user_language_name: str
user_language_name: Optional[str]


class DocumentUploadRequest(BaseModel):
Expand Down
52 changes: 50 additions & 2 deletions integration_tests/document/test_create.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from fastapi.testclient import TestClient
from fastapi import status
from fastapi.testclient import TestClient
from sqlalchemy.orm import Session
from app.clients.db.models.law_policy import FamilyDocument

from app.clients.db.models.document import PhysicalDocument
from app.clients.db.models.document.physical_document import PhysicalDocumentLanguage
from app.clients.db.models.law_policy import FamilyDocument
from app.clients.db.models.law_policy.family import Slug
from integration_tests.setup_db import setup_db
from unit_tests.helpers.document import create_document_create_dto
Expand Down Expand Up @@ -84,6 +86,52 @@ def test_create_document_null_variant(
assert slug.name.startswith("title")


def test_create_document_null_user_language_name(
client: TestClient, test_db: Session, user_header_token
):
setup_db(test_db)
new_document = create_document_create_dto(
title="Title", family_import_id="A.0.0.3", user_language_name=None
)
response = client.post(
"/api/v1/documents",
json=new_document.model_dump(),
headers=user_header_token,
)
assert response.status_code == status.HTTP_201_CREATED

created_import_id = response.json()
actual_fd = (
test_db.query(FamilyDocument)
.filter(FamilyDocument.import_id == created_import_id)
.one()
)
assert actual_fd is not None

language = (
test_db.query(PhysicalDocumentLanguage)
.filter(PhysicalDocumentLanguage.document_id == actual_fd.physical_document_id)
.one()
)
assert language is not None

actual_pd = (
test_db.query(PhysicalDocument)
.filter(PhysicalDocument.id == actual_fd.physical_document_id)
.one()
)
assert actual_pd is not None
assert actual_pd.title == "Title"

slug = (
test_db.query(Slug)
.filter(Slug.family_document_import_id == actual_fd.import_id)
.one()
)
assert len(slug.name) == len("title") + 1 + 4
assert slug.name.startswith("title")


def test_create_document_when_not_authenticated(client: TestClient, test_db: Session):
setup_db(test_db)
new_document = create_document_create_dto(title="Title", family_import_id="A.0.0.3")
Expand Down
1 change: 1 addition & 0 deletions unit_tests/helpers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def create_document_create_dto(
family_import_id="test.family.1.0",
title: str = "title",
variant_name: Optional[str] = "Original Language",
user_language_name: Optional[str] = None,
) -> DocumentCreateDTO:
return DocumentCreateDTO(
family_import_id=family_import_id,
Expand Down

0 comments on commit 345cd4c

Please sign in to comment.