Ejemplo n.º 1
0
def test_incoming_message_translator_json_message_without_opcode_key_should_raise_error(
        mock_observer):
    i = IncomingMessageTranslator([mock_observer])
    with pytest.raises(ValueError):
        i.translate(
            json.dumps({
                'version': 1,
                'application': ['myapp-key', 0],
                'address': ['my-address', 0],
                'payload': 'my-payload'
            }))
Ejemplo n.º 2
0
def test_incoming_message_translator_incomprehensible_message_should_raise_error(
        mock_observer):
    i = IncomingMessageTranslator([mock_observer])
    with pytest.raises(ValueError):
        i.translate("utter garbage")
Ejemplo n.º 3
0
def test_incoming_message_translator_publication_should_send_publish_message(
        mock_observer):
    i = IncomingMessageTranslator([mock_observer])
    i.translate(_create_json_message(Opcode.PUBLISH))
    mock_observer.publish.assert_called()
Ejemplo n.º 4
0
def test_incoming_message_translator_publication_with_incorrect_version_should_be_ignored(
        mock_observer):
    i = IncomingMessageTranslator([mock_observer])
    i.translate(
        _create_json_message(Opcode.PUBLISH, Defaults.INBUS_VERSION + 1))
    mock_observer.publish.assert_not_called()
Ejemplo n.º 5
0
def test_incoming_message_translator_cancellation_with_incorrect_version_should_be_ignored(
        mock_observer):
    i = IncomingMessageTranslator([mock_observer])
    i.translate(
        _create_json_message(Opcode.UNSUBSCRIBE, Defaults.INBUS_VERSION + 1))
    mock_observer.unsubscribe.assert_not_called()
Ejemplo n.º 6
0
def test_incoming_message_translator_cancellation_should_send_unsubscribe_message(
        mock_observer):
    i = IncomingMessageTranslator([mock_observer])
    i.translate(_create_json_message(Opcode.UNSUBSCRIBE))
    mock_observer.unsubscribe.assert_called()
Ejemplo n.º 7
0
def test_incoming_message_translator_translating_incorrect_json_should_raise_error(
        mock_observer):
    i = IncomingMessageTranslator([mock_observer])
    with pytest.raises(BaseException):
        i.translate("this aint't JSON")
Ejemplo n.º 8
0
def test_incoming_message_translator_translating_empty_data_should_raise_error(
        mock_observer):
    i = IncomingMessageTranslator([mock_observer])
    with pytest.raises(ValueError):
        i.translate(None)
Ejemplo n.º 9
0
def test_incoming_message_translator_without_method_observer_should_raise_error(
):
    with pytest.raises(AttributeError):
        IncomingMessageTranslator(None)