From 9849125868c13e0d7b21557e3b0e10ebc0bee7b7 Mon Sep 17 00:00:00 2001 From: Jonathan Rios Date: Thu, 8 Feb 2024 14:49:48 +0100 Subject: [PATCH] LITE-29272 Create upload entity representation --- connect_bi_reporter/uploads/api/schemas.py | 13 +++++ tests/uploads/api/__init__.py | 0 tests/uploads/api/test_schemas.py | 57 ++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 tests/uploads/api/__init__.py create mode 100644 tests/uploads/api/test_schemas.py diff --git a/connect_bi_reporter/uploads/api/schemas.py b/connect_bi_reporter/uploads/api/schemas.py index e69de29..a116b2c 100644 --- a/connect_bi_reporter/uploads/api/schemas.py +++ b/connect_bi_reporter/uploads/api/schemas.py @@ -0,0 +1,13 @@ +from typing import Optional + +from connect_extension_utils.api.schemas import Events, NonNullSchema, ReferenceSchema + + +class UploadSchema(NonNullSchema): + id: str + name: Optional[str] + feed: ReferenceSchema + report: ReferenceSchema + size: Optional[int] + status: str + events: Events diff --git a/tests/uploads/api/__init__.py b/tests/uploads/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/uploads/api/test_schemas.py b/tests/uploads/api/test_schemas.py new file mode 100644 index 0000000..abd1780 --- /dev/null +++ b/tests/uploads/api/test_schemas.py @@ -0,0 +1,57 @@ +from connect_bi_reporter.uploads.api.schemas import UploadSchema + + +def test_upload_get_and_list_schema_full(upload_factory): + upload = upload_factory(size=600, name='My upload') + serializer = UploadSchema( + id=upload.id, + name=upload.name, + feed={'id': upload.feed_id}, + report={'id': 'RR-123'}, + size=upload.size, + events={ + 'created': {'at': upload.created_at}, + 'updated': {'at': upload.updated_at}, + }, + status=upload.status, + ) + + assert serializer.dict() == { + 'id': upload.id, + 'name': upload.name, + 'feed': {'id': upload.feed_id}, + 'report': {'id': 'RR-123'}, + 'size': upload.size, + 'events': { + 'created': {'at': upload.created_at}, + 'updated': {'at': upload.updated_at}, + }, + 'status': upload.status, + } + + +def test_upload_get_and_list_schema_wo_optional_fields(upload_factory): + upload = upload_factory() + serializer = UploadSchema( + id=upload.id, + name=upload.name, + feed={'id': upload.feed_id}, + report={'id': 'RR-123'}, + size=upload.size, + events={ + 'created': {'at': upload.created_at}, + 'updated': {'at': upload.updated_at}, + }, + status=upload.status, + ) + + assert serializer.dict() == { + 'id': upload.id, + 'feed': {'id': upload.feed_id}, + 'report': {'id': 'RR-123'}, + 'events': { + 'created': {'at': upload.created_at}, + 'updated': {'at': upload.updated_at}, + }, + 'status': upload.status, + }