Example #1
0
 def test__get_output_prop_kwargs_content_type_not_set(self, source_type):
     mock = Mock(spec=BaseCollector,
                 type=source_type,
                 get_output_message_id=Mock(return_value=SAMPLE_MESSAGE_ID))
     created_timestamp = 1234
     with patch('time.time', return_value=created_timestamp) as time_mock:
         # collectors handling the sources of "stream" type do not
         # need the `content_type` to be set
         if source_type == 'stream':
             output_prop_kwargs = BaseCollector.get_output_prop_kwargs(
                 mock,
                 source=SAMPLE_SOURCE,
                 output_data_body=SAMPLE_OUTPUT_DATA_BODY,
                 arg_a=SAMPLE_ARG_A)
             # assertions
             time_mock.assert_called_once_with()
             mock.get_output_message_id.assert_called_once_with(
                 source=SAMPLE_SOURCE,
                 created_timestamp=created_timestamp,
                 output_data_body=SAMPLE_OUTPUT_DATA_BODY,
                 arg_a=SAMPLE_ARG_A)
             self.assertEqual(
                 output_prop_kwargs, {
                     'message_id': SAMPLE_MESSAGE_ID,
                     'type': source_type,
                     'timestamp': 1234,
                     'headers': {}
                 })
         else:
             with self.assertRaises(AttributeError):
                 BaseCollector.get_output_prop_kwargs(
                     mock,
                     source=SAMPLE_SOURCE,
                     output_data_body=SAMPLE_OUTPUT_DATA_BODY,
                     arg_a=SAMPLE_ARG_A)
Example #2
0
 def test__get_output_prop_kwargs(self, source_type):
     mock = Mock(__class__=BaseCollector,
                 type=source_type,
                 content_type=SAMPLE_CONTENT_TYPE,
                 get_output_message_id=Mock(return_value=SAMPLE_MESSAGE_ID))
     created_timestamp = 1234
     with patch('time.time', return_value=created_timestamp) as time_mock:
         # the call
         output_prop_kwargs = BaseCollector.get_output_prop_kwargs(
                 mock,
                 source=SAMPLE_SOURCE,
                 output_data_body=SAMPLE_OUTPUT_DATA_BODY,
                 arg_a=SAMPLE_ARG_A)
         # assertions
         time_mock.assert_called_once_with()
         mock.get_output_message_id.assert_called_once_with(
                 source=SAMPLE_SOURCE,
                 created_timestamp=created_timestamp,
                 output_data_body=SAMPLE_OUTPUT_DATA_BODY,
                 arg_a=SAMPLE_ARG_A)
         # if the stream is of the type "source" - it does not
         # add `content_type` to the properties
         if source_type == 'stream':
             self.assertEqual(output_prop_kwargs, {
                     'message_id': SAMPLE_MESSAGE_ID,
                     'type': source_type,
                     'timestamp': 1234,
                     'headers': {}})
         else:
             self.assertEqual(output_prop_kwargs, {
                     'message_id': SAMPLE_MESSAGE_ID,
                     'type': source_type,
                     'content_type': SAMPLE_CONTENT_TYPE,
                     'timestamp': 1234,
                     'headers': {}})