Skip to content

Commit

Permalink
Merge pull request #22 from cloudblue/LITE-29272-create-upload-entity…
Browse files Browse the repository at this point in the history
…-representation

LITE-29272 Create upload entity representation
  • Loading branch information
jonatrios authored Feb 8, 2024
2 parents 32d7d1d + 9849125 commit 3159ffd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
13 changes: 13 additions & 0 deletions connect_bi_reporter/uploads/api/schemas.py
Original file line number Diff line number Diff line change
@@ -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
Empty file added tests/uploads/api/__init__.py
Empty file.
57 changes: 57 additions & 0 deletions tests/uploads/api/test_schemas.py
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit 3159ffd

Please sign in to comment.