예제 #1
0
def test_deserialize_command():
    class Command(ApplicationCommand):
        class Struct(ApplicationCommand.Struct):
            some_property: str

        __trace_id__: str
        __version__: int = 1
        __timestamp__: float
        some_property: Struct

    r = CommandRecord(trace_id='tid',
                      topic='Command',
                      version=1,
                      timestamp=0.0,
                      message=MessageType.APPLICATION_COMMAND.value,
                      payload={'some_property': {
                          'some_property': 'x'
                      }})

    t = Transcoder()
    m = t.deserialize(r, Command)
    assert isinstance(m, Command)
    assert m.__trace_id__ == r.trace_id
    assert m.__version__ == r.version
    assert m.__timestamp__ == r.timestamp
    assert m.some_property.some_property == 'x'
예제 #2
0
def test_deserialize_event():
    class Attribute(ValueObject):
        some_property: str

    class Event(DomainEvent):
        some_property: Attribute

    r = EventRecord(stream_id='sid',
                    number=1,
                    topic='Event',
                    version=1,
                    timestamp=0.0,
                    trace_id='tid',
                    message=MessageType.DOMAIN_EVENT.value,
                    context='some_context',
                    payload={'some_property': {
                        'some_property': 'x'
                    }})

    t = Transcoder()
    m = t.deserialize(r, Event)
    assert isinstance(m, Event)
    assert m.__stream_id__ == r.stream_id
    assert m.__number__ == r.number
    assert m.__version__ == r.version
    assert m.__timestamp__ == r.timestamp
    assert m.__trace_id__ == r.trace_id
    assert m.__context__ == r.context
    assert m.some_property.some_property == 'x'
예제 #3
0
def test_deserialize_integration():
    class Integration(IntegrationEvent):
        some_property: str

    r = IntegrationRecord(trace_id='tid',
                          context='some_context',
                          topic='Integration',
                          resolve='success',
                          error=None,
                          version=1,
                          timestamp=0.0,
                          message=MessageType.INTEGRATION_EVENT.value,
                          payload={'some_property': 'x'})

    t = Transcoder()
    m = t.deserialize(r, Integration)
    assert isinstance(m, Integration)
    assert m.__trace_id__ == r.trace_id
    assert m.__context__ == r.context
    assert m.__resolve__ == r.resolve
    assert m.__error__ == r.error
    assert m.__version__ == r.version
    assert m.__timestamp__ == r.timestamp
    assert m.some_property == 'x'