Пример #1
0
 def test_error_property_type(self):
     source_id = 'source-id-value'
     syntax = ztreamy.json_media_type
     body = {'a': 1, 'b': 'blah!'}
     e = events.Event(source_id, syntax, body)
     events.Event(source_id, syntax, body, event_id='6767676766')
     events.Event(source_id,
                  syntax,
                  body,
                  aggregator_id=['6767676766', '788839393'])
     with self.assertRaises(ValueError):
         events.Event(source_id, syntax, body, event_id={'a': 5})
     with self.assertRaises(ValueError):
         events.Event({}, syntax, body)
     with self.assertRaises(ValueError):
         e.aggregator_id = ['2334343434', {'a': 5}]
     e.aggregator_id = ['2334343434', '435345345345']
Пример #2
0
 def test_error_extra_header(self):
     source_id = 'source-id-value'
     syntax = ztreamy.json_media_type
     body = {'a': 1, 'b': 'blah!'}
     extra = {'x-a': '23', 'x-b': 'df4'}
     e = events.Event(source_id, syntax, body, extra_headers=extra)
     e.set_extra_header('x-c', '565655656')
     with self.assertRaises(ValueError):
         e.set_extra_header('x-c', 565655656)
     with self.assertRaises(ValueError):
         e.set_extra_header('Body', 'sdfsdfsdf')
     with self.assertRaises(ValueError):
         e.set_extra_header('Source-Id', 'sdfsdfsdf')
Пример #3
0
 def test_without_application_id(self):
     callback = _FilterCallback()
     filter_ = filters.EventTypeFilter(callback.callback,
                                       ['TypeA', 'TypeB'])
     test_events = [
         events.Event('',
                      'text/plain',
                      '',
                      event_type='TypeC',
                      application_id='AppB'),
         events.Event('', 'text/plain', '', event_type='TypeA'),
         events.Event('',
                      'text/plain',
                      '',
                      event_type='TypeA',
                      application_id='AppA'),
         events.Event('',
                      'text/plain',
                      '',
                      event_type='TypeC',
                      application_id='AppA'),
         events.Event('',
                      'text/plain',
                      '',
                      event_type='TypeB',
                      application_id='AppA'),
         events.Event('',
                      'text/plain',
                      '',
                      event_type='TypeA',
                      application_id='AppB'),
         events.Event('',
                      'text/plain',
                      '',
                      event_type='TypeB',
                      application_id='AppB'),
     ]
     for event in test_events:
         filter_.filter_event(event)
     self.assertEqual(len(callback.events), 5)
     self.assertEqual(id(callback.events[0]), id(test_events[1]))
     self.assertEqual(id(callback.events[1]), id(test_events[2]))
     self.assertEqual(id(callback.events[2]), id(test_events[4]))
     self.assertEqual(id(callback.events[3]), id(test_events[5]))
     self.assertEqual(id(callback.events[4]), id(test_events[6]))
Пример #4
0
 def get(self):
     event_id = self.get_argument('event-id', default=None)
     if event_id is None:
         event_id = ztreamy.random_id()
     source_id = self.get_argument('source-id')
     syntax = self.get_argument('syntax')
     application_id = self.get_argument('application_id')
     body = self.get_argument('body')
     aggregator_id = events.parse_aggregator_id( \
         self.get_argument('aggregator-id', default=''))
     event_type = self.get_argument('event-type', default=None)
     timestamp = self.get_argument('timestamp', default=None)
     event = events.Event(source_id,
                          syntax,
                          body,
                          application_id=application_id,
                          aggregator_id=aggregator_id,
                          event_type=event_type,
                          timestamp=timestamp)
     event.aggregator_id.append(self.stream.source_id)
     self.stream.dispatch_event(event)
     self.finish()