def test_serialize_event(): class Attribute(ValueObject): some_property: str class Event(DomainEvent): __stream_id__: str __number__: int __version__: int __timestamp__: float __trace_id__: str __context__: str some_property: Attribute m = Event(__stream_id__='sid', __number__=1, __version__=1, __timestamp__=0.0, __trace_id__='tid', __context__='some_context', some_property=Attribute(some_property='x')) t = Transcoder() r = t.serialize(m) assert isinstance(r, EventRecord) assert r.stream_id == m.__stream_id__ assert r.number == m.__number__ assert r.version == m.__version__ assert r.timestamp == m.__timestamp__ assert r.trace_id == m.__trace_id__ assert r.context == m.__context__ assert r.payload['some_property']['some_property'] == 'x'
def test_serialize_integration(): class Integration(IntegrationEvent): __trace_id__: str __context__: str __resolve__: str __error__: typing.Optional[str] __version__: int __timestamp__: float some_property: str m = Integration(__trace_id__='tid', __context__='some_context', __resolve__='success', __error__=None, __version__=1, __timestamp__=0.0, some_property='x') t = Transcoder() r = t.serialize(m) assert isinstance(r, IntegrationRecord) assert r.trace_id == m.__trace_id__ assert r.context == m.__context__ assert r.resolve == m.__resolve__ assert r.error == m.__error__ assert r.version == m.__version__ assert r.timestamp == m.__timestamp__ assert r.payload['some_property'] == 'x'
def test_serialize_command(): class Command(ApplicationCommand): class Struct(ApplicationCommand.Struct): some_property: str __trace_id__: str __version__: int = 1 __timestamp__: float some_property: Struct m = Command(__trace_id__='tid', __version__=1, __timestamp__=0.0, some_property=Command.Struct(some_property='x')) t = Transcoder() r = t.serialize(m) assert isinstance(r, CommandRecord) assert r.trace_id == m.__trace_id__ assert r.version == m.__version__ assert r.timestamp == m.__timestamp__ assert r.payload['some_property'] == {'some_property': 'x'}