Example #1
0
def test_watch_resolution_bus(mapper, trace_id, command, integration_success):
    integration_subscriber = BasicSubscriber()

    integration_bus = Bus()
    integration_bus.attach(integration_subscriber)

    store = MemoryTraceStore(mapper)
    store.start_trace(command)
    store.resolve_context(integration_success)
    store.watch_trace_resolution(trace_id, integration_bus=integration_bus)

    assert len(integration_subscriber) == 1
Example #2
0
def test_filter_policy_by_concept():
    class CommandMatch(ApplicationCommand):
        __concept__: str = 'ConceptMatch'
        __version__: int = 1
    class CommandNotMatch(ApplicationCommand):
        __concept__: str = 'ConceptNotMatch'
        __version__: int = 1

    command_match = CommandMatch.stamp()()
    command_not_match = CommandNotMatch.stamp()()

    subscriber = BasicSubscriber()

    bus = Bus()
    bus.attach(
        FilterPolicy(
            concepts=[CommandMatch.__concept__],
            targets=[subscriber]   
        )
    )
    
    bus.publish(command_match)
    bus.publish(command_not_match)

    assert len(subscriber) == 1
    assert subscriber[0] == command_match
Example #3
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
def test_watch_resolution_bus(dynamodb, mapper, trace_table_name, region_name,
                              trace_id, command, integration_success):
    integration_subscriber = BasicSubscriber()

    integration_bus = Bus()
    integration_bus.attach(integration_subscriber)

    store = DynamoDBTraceStore(trace_table_name,
                               mapper,
                               region_name=region_name)
    store.start_trace(command)
    store.resolve_context(integration_success)
    store.watch_trace_resolution(trace_id, integration_bus=integration_bus)

    assert len(integration_subscriber) == 1
Example #5
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
Example #6
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)
Example #7
0
def bus(bus_subscriber):
    bus = Bus()
    bus.attach(bus_subscriber)
    return bus
Example #8
0
def publisher_bus():
    return Bus()