def test_event_name_not_equal(self): event_one = Event({ 'name': 'One' }) event_two = Event({ 'name': 'Two' }) is_equal = event_one.__ne__(event_two) self.assertTrue(is_equal) is_equal = event_one.__eq__(event_two) self.assertFalse(is_equal)
def my_example_event_handler(event, session=None): """ Example event handler """ # Load Event event = Event(event) logger.debug("handling event: %s", event.name)
async def wrapper(*args, **kwargs): event = Event(args[0]) session = kwargs['session'] service_name = session.name await track_event(event, EventState.started, service_name) await func(*args, **kwargs) await track_event(event, EventState.completed, service_name)
def test_event_name_matches(self): event_one = Event({ 'name': 'One', 'message': 'Test' }) event_two = Event({ 'name': 'One', 'message': 'Test' }) is_equal = event_one.__eq__(event_two) self.assertTrue(is_equal) is_equal = event_one.__ne__(event_two) self.assertFalse(is_equal)
def test_event_string(self): event = Event({ 'name': 'TestEvent', 'message': 'TestBody' }) self.assertIsInstance(event, Event) self.assertEqual(event.name, 'TestEvent') self.assertEqual(event.message, 'TestBody')
def test_event_custom(self): event = Event( { 'name': 'TestEvent', 'message': { 'foo': 'bar' } }, custom_attr='foobar' ) self.assertEqual(event.custom_attr, 'foobar')
def test_event_json(self): event = Event({ 'name': 'TestEvent', 'message': { 'foo': 'bar' } }) self.assertIsInstance(event, Event) message = json.loads(event.message) self.assertIsNotNone(message.get('foo', None))
async def wrapper(*args, **kwargs): """ Wraps function to provide redis tracking """ event = Event(args[0]) session = kwargs['session'] service_name = session.name await track_event(event, EventState.started, service_name) await func(*args, **kwargs) await track_event(event, EventState.completed, service_name)
async def my_example_event_handler(event, session=None): """ Example event handler - This function is implemented as a callback method to the eventify service :param event: An event dictionary :param session: Access to the underlying methods of eventify """ # Parse Incoming Event from Dict to Object event = Event(event) # See the event that was received logger.debug("received event %s", event.name) print('received event %s' % event.name) # Create and Publish an Event # you can also use the publish method directly new_event = Event({ "name": "ReceivedEvent", "message": "Event received by consumer", "trace_id": event.trace_id }) await session.emit_event(new_event) print("emitted event")
async def produce_events(session): """ Produces 10 events """ print('called') logger.debug('called') counter = 1 for number in range(1,11): print(counter) event = Event({ "name": "EventProduced", "message": "Event %s" % number }) await session.emit_event(event) counter = counter + 1
async def init(self): while True: event = Event({'name': 'HelloWorld', 'message': 'Hi!'}) await self.session.emit_event(event) time.sleep(1)
def test_event_no_message(self): event = Event({ 'name': 'TestEvent' }) self.assertIsNotNone(event.name)
def test_event_no_name(self): with self.assertRaises(TypeError): event = Event()