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' }))
def test_incoming_message_translator_incomprehensible_message_should_raise_error( mock_observer): i = IncomingMessageTranslator([mock_observer]) with pytest.raises(ValueError): i.translate("utter garbage")
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()
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()
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()
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()
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")
def test_incoming_message_translator_translating_empty_data_should_raise_error( mock_observer): i = IncomingMessageTranslator([mock_observer]) with pytest.raises(ValueError): i.translate(None)
def test_incoming_message_translator_without_method_observer_should_raise_error( ): with pytest.raises(AttributeError): IncomingMessageTranslator(None)