Skip to content

Commit 8a0f551

Browse files
committed
Add tests
1 parent 9c2b03c commit 8a0f551

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

core_backend/app/contents/models.py

-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ async def get_list_of_content_from_db(
366366
if isinstance(limit, int) and limit > 0:
367367
stmt = stmt.limit(limit)
368368
content_rows = (await asession.execute(stmt)).all()
369-
print([c[0] for c in content_rows])
370369
return [c[0] for c in content_rows] if content_rows else []
371370

372371

core_backend/app/data_api/routers.py

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def convert_content_to_pydantic_model(*, content: ContentDB) -> ContentRetrieve:
9595
content_text=content.content_text,
9696
content_title=content.content_title,
9797
created_datetime_utc=content.created_datetime_utc,
98+
display_number=content.display_number,
9899
is_archived=content.is_archived,
99100
negative_votes=content.negative_votes,
100101
positive_votes=content.positive_votes,

core_backend/tests/api/test_manage_content.py

+51
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,56 @@ def test_admin_2_delete_admin_1_content(
475475
assert response.status_code == status.HTTP_404_NOT_FOUND
476476

477477

478+
def test_display_number_increases(
479+
client: TestClient,
480+
access_token_admin_1: str,
481+
existing_tag_id_in_workspace_1: int,
482+
) -> None:
483+
"""Test creating and deleting content.
484+
485+
Parameters
486+
----------
487+
client
488+
The test client.
489+
access_token_admin_1
490+
The access token for admin user 1.
491+
existing_tag_id_in_workspace_1
492+
The ID of the existing tag in workspace 1.
493+
content_metadata
494+
The metadata of the content.
495+
"""
496+
497+
content_tags = [existing_tag_id_in_workspace_1]
498+
response = client.post(
499+
"/content",
500+
headers={"Authorization": f"Bearer {access_token_admin_1}"},
501+
json={
502+
"content_metadata": {},
503+
"content_tags": content_tags,
504+
"content_text": "Content text 1",
505+
"content_title": "Content title 1",
506+
},
507+
)
508+
assert response.status_code == status.HTTP_200_OK
509+
json_response = response.json()
510+
display_number = json_response["display_number"]
511+
512+
response = client.post(
513+
"/content",
514+
headers={"Authorization": f"Bearer {access_token_admin_1}"},
515+
json={
516+
"content_metadata": {},
517+
"content_tags": content_tags,
518+
"content_text": "Content text 2",
519+
"content_title": "Content title 2",
520+
},
521+
)
522+
assert response.status_code == status.HTTP_200_OK
523+
json_response = response.json()
524+
display_number_2 = json_response["display_number"]
525+
assert display_number_2 == display_number + 1
526+
527+
478528
async def test_convert_record_to_schema() -> None:
479529
"""Test the conversion of a record to a schema."""
480530

@@ -487,6 +537,7 @@ async def test_convert_record_to_schema() -> None:
487537
content_text="sample text",
488538
content_title="sample title for content",
489539
created_datetime_utc=datetime.now(timezone.utc),
540+
display_number=2,
490541
is_archived=False,
491542
positive_votes=0,
492543
negative_votes=0,

0 commit comments

Comments
 (0)