From e0e95381b74845df42cdf72461e4b9640ecb9495 Mon Sep 17 00:00:00 2001 From: Francisco Aranda Date: Tue, 19 Nov 2024 14:21:02 +0100 Subject: [PATCH] chore: Add missing tests with empty chat values --- .../test_create_dataset_records_bulk.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/argilla-server/tests/unit/api/handlers/v1/datasets/records/records_bulk/test_create_dataset_records_bulk.py b/argilla-server/tests/unit/api/handlers/v1/datasets/records/records_bulk/test_create_dataset_records_bulk.py index 6c28b592d9..f3ac9b503c 100644 --- a/argilla-server/tests/unit/api/handlers/v1/datasets/records/records_bulk/test_create_dataset_records_bulk.py +++ b/argilla-server/tests/unit/api/handlers/v1/datasets/records/records_bulk/test_create_dataset_records_bulk.py @@ -514,6 +514,57 @@ async def test_create_dataset_records_bulk_with_chat_field_with_value_exceeding_ assert response.status_code == 422 assert (await db.execute(select(func.count(Record.id)))).scalar_one() == 0 + async def test_create_dataset_records_bulk_with_chat_field_empty_values( + self, db: AsyncSession, async_client: AsyncClient, owner_auth_header: dict + ): + dataset = await DatasetFactory.create(status=DatasetStatus.ready) + + await ChatFieldFactory.create(name="chat", dataset=dataset) + await LabelSelectionQuestionFactory.create(dataset=dataset) + + response = await async_client.post( + self.url(dataset.id), + headers=owner_auth_header, + json={ + "items": [ + { + "fields": {"chat": [{"role": "", "content": ""}]}, + }, + ], + }, + ) + + assert response.status_code == 422 + assert response.json() == { + "detail": { + "code": "argilla.api.errors::ValidationError", + "params": { + "errors": [ + { + "loc": ["body", "items", 0, "fields"], + "msg": "Value error, Error parsing chat " + "field 'chat': [{'type': " + "'string_too_short', 'loc': " + "('role',), 'msg': 'String should " + "have at least 1 character', " + "'input': '', 'ctx': {'min_length': " + "1}, 'url': " + "'https://errors.pydantic.dev/2.9/v/string_too_short'}, " + "{'type': 'string_too_short', 'loc': " + "('content',), 'msg': 'String should " + "have at least 1 character', " + "'input': '', 'ctx': {'min_length': " + "1}, 'url': " + "'https://errors.pydantic.dev/2.9/v/string_too_short'}]", + "type": "value_error", + } + ] + }, + } + } + + assert (await db.execute(select(func.count(Record.id)))).scalar_one() == 0 + async def test_create_dataset_records_bulk_with_chat_field_with_non_dicts( self, db: AsyncSession, async_client: AsyncClient, owner_auth_header: dict ):