def test_route_with_routes(self): app = App(routes=[ lambda **kwargs: { 'queue': kwargs['task'].name + '_queue' } ]) queue = app.route('task') self.assertEqual('task_queue', queue)
def test_update_local_event(self): update_local_event_events = [] class TestBackend(Backend): def update_local_event(self, event): update_local_event_events.append(event) def get_local_namespaces(self): return [] event = Event('app_name', 'event_name') app = App(TestBackend) app.update_local_event(event) self.assertEqual([event], update_local_event_events)
def test_invalid_backend_class(self): class InvalidBackend: pass try: App(InvalidBackend) self.fail() except TypeError: pass
def setUp(self): self.app = App() self.registry = Registry(self.app) self.namespaces = ['app_1', 'app_2'] self.local_events_from_backend = [] self.remote_events_from_backend = [] self.deleted_events = [] self.created_events = [] self.created_tasks = [] self.removed_tasks = [] self.updated_tasks = [] test_case = self class TestBackend(Backend): def get_local_namespaces(self): return test_case.namespaces def get_task_namespace(self, task): return task.name.split('.')[0] def fetch_events_for_namespaces(self, app_names): return test_case.local_events_from_backend def fetch_events(self, events): return [ event for event in test_case.local_events_from_backend + test_case.remote_events_from_backend if event in events ] def should_update_event(self, event): return True def delete_events(self, events): for event in events: test_case.deleted_events.append(event) def create_events(self, events): for event in events: test_case.created_events.append(event) def create_tasks(self, event, tasks): for task in tasks: test_case.created_tasks.append((event, task)) def remove_tasks(self, event, tasks): for task in tasks: test_case.removed_tasks.append((event, task)) def update_tasks(self, event, tasks): for task in tasks: test_case.updated_tasks.append((event, task)) self.backend_cls = TestBackend
def setUp(self): self.update_local_event_events = [] test_case = self class TestBackend(Backend): def update_local_event(self, event): test_case.update_local_event_events.append(event) def get_local_namespaces(self): return [] self.app = App(backend_class=TestBackend)
def test_sync_events(self): sync_local_events_called_times = [] sync_remote_events_called_times = [] class TestBackend(Backend): def sync_local_events(self): sync_local_events_called_times.append(1) def sync_remote_events(self): sync_remote_events_called_times.append(1) def get_local_namespaces(self): return [] app = App(TestBackend) app.sync_local_events() self.assertEqual(1, len(sync_local_events_called_times)) app.sync_remote_events() self.assertEqual(1, len(sync_remote_events_called_times))
def setUp(self): self.app = App()
def test_route_no_route(self): app = App() queue = app.route('task') self.assertIsNone(queue)
def test_broadcaster_no_broadcast_queue(self): app = App() self.assertEqual('events_broadcast', app.broadcaster.queue)
def test_broadcaster_with_broadcast_queue(self): app = App(broadcast_queue='b_queue') self.assertEqual('b_queue', app.broadcaster.queue)