def test_todo_should_have_all_events(self): todo_app = ToDoAggregate.create_todos(originator_id=1) todo_app.add_item('test todo') todo_app.complete_item(item_id=1) todo_app.clean_completed() events = todo_app.flush() self.assertEqual(len(events), 4)
def test_todo_should_uncomplete_completed_item(self): todo_app = ToDoAggregate.create_todos(originator_id=1) todo_app.add_item('test todo') todo_app.complete_item(item_id=1) self.assertEqual(todo_app.items[0].is_completed, True) todo_app.uncomplete_item(item_id=1) self.assertEqual(todo_app.items[0].is_completed, False)
async def test_todo_created(self): todo_item = ToDoAggregate.create_todos(1) self.assertEqual(todo_item.id, 1) await self.app.todos.save(todo_item) todo_item = await self.app.todos.get_entity(1) self.assertEqual(todo_item.id, 1) events = await self.app.todos.event_store.get_domain_events(1) self.assertEqual(len(events), 1)
async def test_todo_should_be_able_to_change_attribute(self): todo_item = ToDoAggregate.create_todos(3) await self.app.todos.save(todo_item) todo_item = await self.app.todos.get_entity(3) todo_item.todo_name = 'test name' await self.app.todos.save(todo_item) todo_item = await self.app.todos.get_entity(3) self.assertEqual(todo_item.todo_name, 'test name') events = await self.app.todos.event_store.get_domain_events(3) self.assertEqual(len(events), 2)
async def test_subscribe_to(self): test_var = False @subscribe_to(ToDoAggregate.Created) async def test_subs(event, **kwargs): nonlocal test_var test_var = True todo_item = ToDoAggregate.create_todos(4) await self.app.todos.save(todo_item) self.assertEqual(test_var, True)
async def test_todo_should_add_item(self): todo_item = ToDoAggregate.create_todos(2) await self.app.todos.save(todo_item) todo_item = await self.app.todos.get_entity(2) todo_item.add_item('test item') await self.app.todos.save(todo_item) todo_item = await self.app.todos.get_entity(2) self.assertEqual(todo_item.items[0].name, 'test item') events = await self.app.todos.event_store.get_domain_events(2) self.assertEqual(len(events), 2)
def test_todo_should_clean_completed_items(self): todo_app = ToDoAggregate.create_todos(originator_id=1) todo_app.add_item('test todo1') todo_app.add_item('test todo2') todo_app.add_item('test todo3') todo_app.complete_item(item_id=2) todo_app.clean_completed() self.assertEqual(len(todo_app.items), 2) self.assertEqual(todo_app.items[0].id, 1) self.assertEqual(todo_app.items[1].id, 3)
async def make_todo(self, index=0): id = uuid.uuid4() task_len = 10 todo_item = ToDoAggregate.create_todos(id) self.assertEqual(todo_item.id, id) await self.app.todos.save(todo_item) events = await self.app.todos.event_store.get_domain_events(originator_id=id) self.assertEqual(len(events), 1) todo_item = await self.app.todos.get_entity(id) self.assertEqual(todo_item.id, id) todo_item.todo_name = str(id) for task_index in range(0, task_len): todo_item.add_item('todo_item #' + str(task_index) + '-' + str(index)) await self.app.todos.save(todo_item) todo_item = await self.app.todos.get_entity(id) self.assertEqual(len(todo_item.items), task_len) self.assertEqual(todo_item.todo_name, str(id))
def test_todo_created(self): todo_app = ToDoAggregate.create_todos(originator_id=1) self.assertEqual(len(todo_app.items), 0) self.assertEqual(todo_app.id, 1) self.assertEqual(todo_app.version, 1)
def test_todo_should_add_item(self): todo_app = ToDoAggregate.create_todos(originator_id=1) todo_app.add_item('test todo') self.assertEqual(len(todo_app.items), 1)