def tearDown(self): from eventsourcing.domain.model.events import _event_handlers if _event_handlers: print("Warning: event handlers still subscribed: {}".format( _event_handlers)) _event_handlers.clear() try: del (os.environ['DB_URI']) except KeyError: pass
def test_subscribe_to_decorator(self): entity_id1 = uuid4() event1 = Example.Created( originator_id=entity_id1, originator_topic=get_topic(Example), a=1, b=2 ) event2 = Example.Discarded( originator_id=entity_id1, originator_version=1, ) handler = mock.Mock() # Check we can assert there are no event handlers subscribed. assert_event_handlers_empty() @subscribe_to(Example.Created) def test_handler(e): """Doc string""" handler(e) # Check the decorator doesn't mess with the function doc string. self.assertEqual('Doc string', test_handler.__doc__) # Check can fail to assert event handlers empty. self.assertRaises(EventHandlersNotEmptyError, assert_event_handlers_empty) # Check event is received when published individually. publish(event1) handler.assert_called_once_with(event1) # Check event of wrong type is not received. handler.reset_mock() publish(event2) self.assertFalse(handler.call_count) # Check a list of events can be filtered. handler.reset_mock() publish([event1, event2]) handler.assert_called_once_with(event1) handler.reset_mock() publish([event1, event1]) self.assertEqual(2, handler.call_count) handler.reset_mock() publish([event2, event2]) self.assertEqual(0, handler.call_count) _event_handlers.clear()
def tearDown(self): from eventsourcing.domain.model.events import _event_handlers if _event_handlers: print("Warning: event handlers still subscribed: {}".format( _event_handlers)) _event_handlers.clear() # Need to drop the stored events, because the __main__#Order topics # mess up the multiprocessing tests (because the Orders application # has the same ID so events from one test cause another to fail). os.environ['DB_URI'] = 'mysql+pymysql://{}:{}@{}/eventsourcing'.format( os.getenv('MYSQL_USER', 'root'), os.getenv('MYSQL_PASSWORD', ''), os.getenv('MYSQL_HOST', '127.0.0.1'), ) database = SQLAlchemyDatastore(settings=SQLAlchemySettings()) database.setup_connection() # Might as well drop everything.... Base.metadata.drop_all(database._engine) del (os.environ['DB_URI'])
def tearDown(self): if _event_handlers: print("Warning: event handlers still subscribed: {}".format( _event_handlers)) _event_handlers.clear()
def tearDown(self): _event_handlers.clear()
def tearDown(self): from eventsourcing.domain.model.events import _event_handlers if _event_handlers: print("Warning: event handlers still subscribed: {}".format(_event_handlers)) _event_handlers.clear()