Example #1
0
 def setUp(self):
     """Stub `url_get_schema` and pre-fill schema cache."""
     super(SchemaTestMixin, self).setUp()
     self.event = Event(copy.deepcopy(_event))
     self.event_with_meta = Event(copy.deepcopy(_event_with_meta))
     self.incorrectly_serialized_empty_event = Event(
         copy.deepcopy(_incorrectly_serialized_empty_event))
     eventlogging.schema.schema_cache = copy.deepcopy(_schemas)
     eventlogging.topic.topic_config = copy.deepcopy(_topic_config)
     eventlogging.schema.url_get_schema = mock_url_get_schema
     self.event_generator = _get_event()
Example #2
0
 def event_from_temp_file(self):
     """
     Read the event(s) from the temp_file.
     """
     with open(self.temp_file_path, 'r') as f:
         event = Event.factory(f)
     return event
Example #3
0
 def test_factory_string(self):
     """Test Event.factory() with a JSON string."""
     s = json.dumps(_event_with_meta)
     self.assertEqual(
         Event.factory(s),
         _event_with_meta
     )
 def event_from_temp_file(self):
     """
     Read the event(s) from the temp_file.
     """
     with open(self.temp_file_path, 'r') as f:
         event = Event.factory(f)
     return event
Example #5
0
 def test_factory_list(self):
     """Test Event.factory() with a list of dicts."""
     l = [_event_with_meta, _event_with_meta]
     self.assertEqual(
         Event.factory(l),
         l
     )
Example #6
0
 def test_factory_string_list(self):
     """Test Event.factory() with a list JSON string."""
     l = [_event_with_meta, _event_with_meta]
     s = json.dumps(l)
     self.assertEqual(
         Event.factory(s),
         l
     )
Example #7
0
    def test_factory_file(self):
        """Test Event.factory() with a file object."""
        l = [_event_with_meta, _event_with_meta]
        s = json.dumps(l)

        file = tempfile.TemporaryFile(prefix='eventlogging-event-test')
        # Write the string to the temp file.
        file.write(s.encode('utf-8'))
        # Seek to the beginning of file so Event.factory() can read it.
        file.seek(0)
        self.assertEqual(Event.factory(file), l)
        file.close()
Example #8
0
    def test_factory_file(self):
        """Test Event.factory() with a file object."""
        l = [_event_with_meta, _event_with_meta]
        s = json.dumps(l)

        file = tempfile.TemporaryFile(prefix='eventlogging-event-test')
        # Write the string to the temp file.
        file.write(s.encode('utf-8'))
        # Seek to the beginning of file so Event.factory() can read it.
        file.seek(0)
        self.assertEqual(
            Event.factory(file),
            l
        )
        file.close()
Example #9
0
def _get_event():
    """ Creates events on demand with unique ids"""
    for i in range(1, 100):
        event = Event(copy.deepcopy(_event))
        event['uuid'] = i
        yield event
Example #10
0
 def test_factory_string_list(self):
     """Test Event.factory() with a list JSON string."""
     l = [_event_with_meta, _event_with_meta]
     s = json.dumps(l)
     self.assertEqual(Event.factory(s), l)
Example #11
0
 def test_factory_string(self):
     """Test Event.factory() with a JSON string."""
     s = json.dumps(_event_with_meta)
     self.assertEqual(Event.factory(s), _event_with_meta)
Example #12
0
 def test_factory_list(self):
     """Test Event.factory() with a list of dicts."""
     l = [_event_with_meta, _event_with_meta]
     self.assertEqual(Event.factory(l), l)
Example #13
0
 def test_factory_dict(self):
     """Test Event.factory() with a dict."""
     self.assertEqual(Event.factory(_event_with_meta), _event_with_meta)
Example #14
0
 def test_factory_dict(self):
     """Test Event.factory() with a dict."""
     self.assertEqual(
         Event.factory(_event_with_meta),
         _event_with_meta
     )