Beispiel #1
0
def test_filter_policy_by_context():
    context = "ctx"

    command_match = ApplicationCommand.stamp()(
        __context__ = context,
        __version__ = 1
    )
    command_not_match = ApplicationCommand.stamp()(
        __context__ = None,
        __version__ = 1
    )

    subscriber = BasicSubscriber()

    bus = Bus()
    bus.attach(
        FilterPolicy(
            contexts=[context],
            targets=[subscriber]   
        )
    )
    
    bus.publish(command_match)
    bus.publish(command_not_match)


    assert len(subscriber) == 1
    assert subscriber[0] == command_match
Beispiel #2
0
def test_publish():
    command = ApplicationCommand(__timestamp__=0.0,
                                 __trace_id__='tid',
                                 __version__=1)

    pub = MemoryPublisher()
    pub.publish(command)
Beispiel #3
0
def test_eventbridge_publish(bus_name):
    command = ApplicationCommand(__timestamp__=0.0,
                                 __trace_id__='tid',
                                 __version__=1)

    mapper = Mapper(transcoder=Transcoder())
    mapper.register(ApplicationCommand)

    pub = AwsEventBridgePublisher(bus_name, 'some_context', mapper)
    pub.publish(command)
Beispiel #4
0
def test_sns_publish(topic_arn, region_name):
    command = ApplicationCommand(__timestamp__=0.0,
                                 __trace_id__='tid',
                                 __version__=1)

    mapper = Mapper(transcoder=Transcoder())
    mapper.register(ApplicationCommand)

    pub = AwsSimpleNotificationServicePublisher(topic_arn,
                                                'default',
                                                mapper,
                                                region_name=region_name)
    pub.publish(command)
Beispiel #5
0
def test_sqs_publish(sqs, queue_url, queue_name, region_name):
    command = ApplicationCommand(
        __timestamp__=0.0,
        __trace_id__='tid',
        __version__=1
    )

    mapper = Mapper(transcoder=Transcoder())
    mapper.register(ApplicationCommand)

    pub = AwsSimpleQueueServicePublisher(queue_name, mapper, region_name=region_name)
    pub.publish(command)
    
    sqs_messages = sqs.receive_message(QueueUrl=queue_url)
    assert len(sqs_messages['Messages']) == 1
Beispiel #6
0
def test_mapper_serialize_command():
    command = ApplicationCommand(
        __timestamp__=0.0,
        __trace_id__='tid',
        __version__ = 1
    )
    
    mapper = Mapper(transcoder=Transcoder())
    record = mapper.serialize(command)
    
    assert isinstance(record, CommandRecord)
    assert record.trace_id == 'tid'
    assert record.topic == 'ApplicationCommand'
    assert record.version == 1
    assert record.timestamp == 0.0
    assert record.message == MessageType.APPLICATION_COMMAND.value
    assert record.payload == {}
def test_publisher_subscriber():
    class Publisher(IPublisher):
        def publish(self, messages: ApplicationMessage):
            self.proof_of_work(messages)

        def proof_of_work(self, *args, **kwargs):
            pass

    publisher = Publisher()
    publisher.proof_of_work = mock.Mock()

    command = ApplicationCommand(__timestamp__=0.0, __version__=1)

    x = subs.PublisherSubscriber(publisher)
    x.__route__(command)

    publisher.proof_of_work.assert_called_with(command)
def test_application_service_subscriber():
    class Service(ApplicationService):
        def handle(self, message: ApplicationMessage) -> None:
            self.proof_of_work(message)

        def proof_of_work(self, *args, **kwargs):
            pass

    service = Service()
    service.proof_of_work = mock.Mock()

    command = ApplicationCommand(__timestamp__=0.0, __version__=1)

    x = subs.ApplicationServiceSubscriber(service)
    x.__route__(command)

    service.proof_of_work.assert_called_with(command)
Beispiel #9
0
def test_bus():
    class Subscriber(ISubscriber):
        def __route__(self, message: Message):
            self.proof_of_work(message)

        def proof_of_work(self, *args, **kwargs):
            pass

    subscriber = Subscriber()
    subscriber.proof_of_work = mock.Mock()

    command = ApplicationCommand(__timestamp__ = 0.0, __version__ = 1)

    bus = Bus()
    bus.attach(subscriber)
    bus.publish(command)

    subscriber.proof_of_work.assert_called_with(command)
Beispiel #10
0
def test_filter_policy_by_type():
    message_match = ApplicationCommand.stamp()(__version__=1)
    message_not_match = ApplicationQuery.stamp()(__version__=1)

    subscriber = BasicSubscriber()

    bus = Bus()
    bus.attach(
        FilterPolicy(
            types=[ApplicationCommand],
            targets=[subscriber]   
        )
    )
    
    bus.publish(message_match)
    bus.publish(message_not_match)

    assert len(subscriber) == 1
    assert subscriber[0] == message_match
Beispiel #11
0
def command():
    return ApplicationCommand(__timestamp__=0.0, __version__=1)
def command(trace_id):
    return ApplicationCommand(__resolvers__=['some_context'],
                              __trace_id__=trace_id,
                              __version__=1,
                              __timestamp__=0.0)
Beispiel #13
0
def command(trace_id):
    return ApplicationCommand(
        __timestamp__ = 0.0,
        __trace_id__ = trace_id,
        __version__ = 1
    )