Exemplo n.º 1
0
def test_cca_conversion_data_convert(mocker, consumer_carriage, consumer_node):
    data = mocker.MagicMock(spec=CustomDataType1)
    consumer_node.expects.return_value = CustomDataType2
    cca = ConsumerNodeCarriageAdapter(consumer_carriage=consumer_carriage,
                                      consumer_node=consumer_node)

    consumer_node.process_document.assert_not_called()
    cca.data_adapters[0].convert_data.assert_not_called()

    cca.process_document(document=data)

    cca.data_adapters[0].convert_data.assert_called_once()
    cca.data_adapters[0].convert_data.assert_called_with(data)
    consumer_node.process_document.assert_called_once()
Exemplo n.º 2
0
def test_cca_instantiate(consumer_carriage, consumer_node,
                         get_document_data_adapter):
    instance = ConsumerNodeCarriageAdapter(consumer_carriage=consumer_carriage,
                                           consumer_node=consumer_node)
    assert isinstance(instance, IConsumerNode)
    assert isinstance(instance, IConsumerCarriage)
    get_document_data_adapter.assert_not_called()
    assert len(instance.data_adapters) == 0
Exemplo n.º 3
0
def test_cca_data_adapters_auto(consumer_carriage, consumer_node,
                                get_document_data_adapter):
    consumer_node.expects.return_value = CustomDataType2
    instance = ConsumerNodeCarriageAdapter(consumer_carriage=consumer_carriage,
                                           consumer_node=consumer_node)
    get_document_data_adapter.assert_called_once()
    get_document_data_adapter.assert_called_with(expects=CustomDataType1,
                                                 provides=CustomDataType2)
Exemplo n.º 4
0
def test_cca_data_adapters_auto_error_incompatible_param(
        consumer_carriage, consumer_node, get_document_data_adapter):
    consumer_node.expects.return_value = CustomDataType2

    get_document_data_adapter.side_effect = ValueError

    with pytest.raises(DataCompatError):
        instance = ConsumerNodeCarriageAdapter(
            consumer_carriage=consumer_carriage, consumer_node=consumer_node)
Exemplo n.º 5
0
def test_cca_data_adapters_custom_error_empty_param(mocker, consumer_carriage,
                                                    consumer_node):
    consumer_node.expects.return_value = CustomDataType2

    with pytest.raises(DataCompatError):
        instance = ConsumerNodeCarriageAdapter(
            consumer_carriage=consumer_carriage,
            consumer_node=consumer_node,
            data_adapters=[])
Exemplo n.º 6
0
def test_cca_data_adapters_custom_error_incompatible_param(
        mocker, consumer_carriage, consumer_node):
    consumer_node.expects.return_value = CustomDataType2
    dda = mocker.MagicMock(spec=IDocumentDataAdapter)
    dda.expects.return_value = CustomDataType1
    dda.provides.return_value = CustomDataType1

    with pytest.raises(DataCompatError):
        instance = ConsumerNodeCarriageAdapter(
            consumer_carriage=consumer_carriage,
            consumer_node=consumer_node,
            data_adapters=[dda])
Exemplo n.º 7
0
def test_cca_data_adapters_custom_success(mocker, consumer_carriage,
                                          consumer_node,
                                          get_document_data_adapter):
    consumer_node.expects.return_value = CustomDataType2
    dda = mocker.MagicMock(spec=IDocumentDataAdapter)
    dda.expects.return_value = CustomDataType1
    dda.provides.return_value = CustomDataType2
    instance = ConsumerNodeCarriageAdapter(consumer_carriage=consumer_carriage,
                                           consumer_node=consumer_node,
                                           data_adapters=[dda])
    get_document_data_adapter.assert_not_called()
    assert instance.data_adapters == [dda]
    dda.convert_data.assert_not_called()
    consumer_carriage.register_consumer_node.assert_called_once()
    consumer_node.register_consumer_carriage.assert_called_once()
Exemplo n.º 8
0
def main():
    args = parser.parse_args()
    create_loggers()
    log.info('This is a Simple Consumer example')

    manifest_path = args.manifest_path
    websocket_url = args.websocket_url
    consumer_impl = None
    fs_reader = None

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    if manifest_path:
        do_tail = args.do_tail
        consumer_impl = FilesystemConsumerImpl(reference_clock)
        fs_reader = FilesystemReader(manifest_path, consumer_impl, do_tail)
    else:
        consumer_impl = WebsocketConsumerCarriage()

    simple_consumer = SimpleConsumer(node_id='simple-consumer',
                                     reference_clock=reference_clock)

    # Chaining converter
    ConsumerNodeCarriageAdapter(consumer_node=simple_consumer,
                                consumer_carriage=consumer_impl)

    if manifest_path:
        fs_reader.resume_reading()
    else:
        factory_args = {}
        if args.proxy:
            proxyHost, proxyPort = args.proxy.split(':')
            factory_args['proxy'] = {'host': proxyHost, 'port': int(proxyPort)}

        twisted_consumer = TwistedWSConsumer(custom_consumer=consumer_impl)

        factory = BroadcastClientFactory(url=websocket_url,
                                         consumer=twisted_consumer,
                                         **factory_args)

        factory.protocol = BroadcastClientProtocol

        factory.connect()

        reactor.run()
Exemplo n.º 9
0
def consumer_carriage_adapter(consumer_carriage, consumer_node,
                              get_document_data_adapter):
    cca = ConsumerNodeCarriageAdapter(consumer_carriage=consumer_carriage,
                                      consumer_node=consumer_node)
    return cca