Пример #1
0
    def test_no_registered_type_extract_command(self, get_message_type):
        """Validate InvalidCommandMessage is raised when no type matches"""
        message = {'type': 'test', 'body': 'payload'}

        get_message_type.side_effect = KeyError
        with self.assertRaises(InvalidCommandMessage):
            CommandMessageManager._extract_command(message)
Пример #2
0
    def test_valid_extract_command(self, get_message_type):
        """Validate a successful _extract_command call instantiation of CommandMessage class from payload"""
        message = {'type': 'test', 'body': 'payload'}

        from_json = MagicMock(return_value=MagicMock(spec=CommandMessage))
        message_class = MagicMock(from_json=from_json)
        get_message_type.return_value = message_class
        result = CommandMessageManager._extract_command(message)

        get_message_type.assert_called_once()
        message_class.from_json.assert_called_with(message['body'])
        self.assertTrue(isinstance(result, CommandMessage))
Пример #3
0
    def test_missing_body_extract_command(self):
        """Validate InvalidCommandMessage is raised when missing body key"""
        message = {'type': 'test'}

        with self.assertRaises(InvalidCommandMessage):
            CommandMessageManager._extract_command(message)
Пример #4
0
    def test_missing_type_extract_command(self):
        """Validate InvalidCommandMessage is raised when missing type key"""
        message = {'body': 'payload'}

        with self.assertRaises(InvalidCommandMessage):
            CommandMessageManager._extract_command(message)