def test_log_error_if_umb_message_body_is_invalid(self, get, handle, SSLDomain): with open(os.path.join(test_data_dir, 'mts-test-rules.yaml'), 'r') as f: rules_content = f.read() get.return_value.text = rules_content ReceiverHandler.fake_msg_body = 'non-JSON message body' with patch.object(consumer, 'logger') as logger: run() args, _ = logger.error.call_args_list[0] assert 'Cannot decode message body: non-JSON message body' == args[0] args, _ = logger.error.call_args_list[1] assert args[0].startswith('Reason:')
def test_handle_umb_message(self, get, handle, SSLDomain): mbs_event_msg = { 'name': 'python', 'stream': '2.7', 'version': '1', 'context': 'c1', } ReceiverHandler.fake_msg_body = json.dumps(mbs_event_msg).encode() with open(os.path.join(test_data_dir, 'mts-test-rules.yaml'), 'r') as f: rules_content = f.read() get.return_value.text = rules_content run() handle.assert_called_once_with( yaml.safe_load(rules_content), mbs_event_msg)
def test_handle_fedora_messaging_message(self, get, handle, msg_body): with open(os.path.join(test_data_dir, 'mts-test-rules.yaml'), 'r') as f: rules_content = f.read() get.return_value.text = rules_content def api_consume(callback): msg = fedora_messaging.api.Message(msg_body) callback(msg) with patch('fedora_messaging.api.consume', new=api_consume): run() if msg_body: handle.assert_called_once_with(yaml.safe_load(rules_content), msg_body) else: # In case event message is empty, MTS stops handling the message. handle.assert_not_called()
if __name__ == '__main__': from message_tagging_service.consumer import run run()
def test_skip_if_rule_file_is_empty(self, get, handle, SSLDomain): ReceiverHandler.fake_msg_body = json.dumps({}).encode() get.return_value.text = '---' run() handle.assert_not_called()
def test_raise_error_if_specified_messaging_backend_is_unknown(self): with patch.object(conf, 'messaging_backend', new='xxxxxx'): with pytest.raises(ValueError, match='Unknown messaging backend: .+'): run()