def tasks(self, refresh=False, include_deleted=False, include_done=False, include_checked=True, include_unchecked=True): """Return a remote or chached task list for user.""" if not self.tasks_list or refresh: params = { 'includeDeleted': str(include_deleted).lower(), 'includeDone': str(include_done).lower(), } tasks_data = request.get(url=CONSTANTS.get('TASKS_URL'), session=self.session(), params=params) self.tasks_list = [ Task(data_dict=task, user=self) for task in tasks_data ] return Task.filter_tasks(self.tasks_list, include_deleted=include_deleted, include_done=include_done, include_checked=include_checked, include_unchecked=include_unchecked)
def test_subtask_knows_about_its_parent(self): user = self.get_me() with vcr.use_cassette('fixtures/vcr_cassettes/task_create_new_parent.json'): parent = Task.create(user=user, title='Parent') with vcr.use_cassette('fixtures/vcr_cassettes/task_create_new_subtask.json'): new_task = Task.create(user=parent.user, title='New subtask', parentGlobalTaskId=parent['id']) with vcr.use_cassette('fixtures/vcr_cassettes/fake.json', record_mode='none'): self.assertEqual(parent, new_task.parent()) self.assertEqual(None, parent.parent())
def test_task_have_subtasks_that_are_tasks_too(self): user = self.get_me() with vcr.use_cassette('fixtures/vcr_cassettes/task_create_new_parent.json'): parent = Task.create(user=user, title='Parent') self.assertEqual([], parent.subtasks()) with vcr.use_cassette('fixtures/vcr_cassettes/task_create_new_subtask.json'): new_task = Task.create(user=parent.user, title='New subtask', parentGlobalTaskId=parent['id']) self.assertEqual(new_task, parent.subtasks()[0])
def test_task_creation_reraises_occured_errors(self): # Emulate Server Error bypassing internal validaitons for missed fields original = Task.required_attributes def fake(): return set() Task.required_attributes = staticmethod(fake) with vcr.use_cassette('fixtures/vcr_cassettes/task_create_invalid.json'): with self.assertRaises(errors.InternalServerError): Task.create(user=self.get_me(), status='UNCHECKED', ) Task.required_attributes = staticmethod(original)
def test_new_task_could_be_deleted_permanently_after_creation(self): user = self.get_me() with vcr.use_cassette('fixtures/vcr_cassettes/task_create_for_delete2.json'): Task.create(user=user, title='Delete me2', status='UNCHECKED') with vcr.use_cassette('fixtures/vcr_cassettes/tasks_after_new_one_created2.json'): task = user.tasks(refresh=True)[-1] self.assertEqual('Delete me2', task.title) with vcr.use_cassette('fixtures/vcr_cassettes/task_destroy_valid2.json'): task.destroy() with vcr.use_cassette('fixtures/vcr_cassettes/tasks_after_new_one_deleted2.json'): tasks = user.tasks(refresh=True) self.assertFalse(task['id'] in map(lambda task: task['id'], tasks))
def test_task_have_subtasks_that_are_tasks_too(self): user = self.get_me() with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_new_parent.json'): parent = Task.create(user=user, title='Parent') self.assertEqual([], parent.subtasks()) with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_new_subtask.json'): new_task = Task.create(user=parent.user, title='New subtask', parentGlobalTaskId=parent['id']) self.assertEqual(new_task, parent.subtasks()[0])
def tasks(self, refresh=False, include_deleted=False, include_done=False, include_checked=True, include_unchecked=True): """Return a remote or chached task list for user.""" if not self.tasks_list or refresh: params = { 'includeDeleted': str(include_deleted).lower(), 'includeDone': str(include_done).lower(), } tasks_data = request.get( url=CONSTANTS.get('TASKS_URL'), session=self.session(), params=params ) self.tasks_list = [Task(data_dict=task, user=self) for task in tasks_data] return Task.filter_tasks(self.tasks_list, include_deleted=include_deleted, include_done=include_done, include_checked=include_checked, include_unchecked=include_unchecked)
def test_subtask_knows_about_its_parent(self): user = self.get_me() with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_new_parent.json'): parent = Task.create(user=user, title='Parent') with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_new_subtask.json'): new_task = Task.create(user=parent.user, title='New subtask', parentGlobalTaskId=parent['id']) with vcr.use_cassette('fixtures/vcr_cassettes/fake.json', record_mode='none'): self.assertEqual(parent, new_task.parent()) self.assertEqual(None, parent.parent())
def test_task_creation_returns_task_instance(self): with vcr.use_cassette('fixtures/vcr_cassettes/task_create_valid.json'): task = Task.create(user=self.get_me(), title='Test Task', category='Personal', priority='Normal', status='UNCHECKED') self.assertIsInstance(task, Task)
def test_task_creation_reraises_occured_errors(self): # Emulate Server Error bypassing internal validaitons for missed fields original = Task.required_attributes def fake(): return set() Task.required_attributes = staticmethod(fake) with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_invalid.json'): with self.assertRaises(errors.InternalServerError): Task.create( user=self.get_me(), status='UNCHECKED', ) Task.required_attributes = staticmethod(original)
def test_no_need_to_refresh_tasks_after_creation(self): user = self.get_me() with vcr.use_cassette('fixtures/vcr_cassettes/tasks.json'): initial_size = len(user.tasks()) with vcr.use_cassette('fixtures/vcr_cassettes/task_create_valid.json'): new_task = Task.create(user=user, title='New Task') self.assertTrue(new_task in user.tasks())
def test_task_creation_returns_task_instance(self): with vcr.use_cassette('fixtures/vcr_cassettes/task_create_valid.json'): task = Task.create(user=self.get_me(), title='Test Task', category='Personal', priority='Normal', status='UNCHECKED' ) self.assertIsInstance(task, Task)
def test_subtask_could_be_created_directly(self): user = self.get_me() with vcr.use_cassette('fixtures/vcr_cassettes/task_create_new_parent.json'): parent = Task.create(user=user, title='Parent') with vcr.use_cassette('fixtures/vcr_cassettes/task_create_new_subtask.json'): new_task = parent.create_subtask(title='New subtask') self.assertEqual(new_task, parent.subtasks()[0])
def test_new_task_could_be_deleted_permanently_after_creation(self): user = self.get_me() with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_for_delete2.json'): Task.create(user=user, title='Delete me2', status='UNCHECKED') with vcr.use_cassette( 'fixtures/vcr_cassettes/tasks_after_new_one_created2.json'): task = user.tasks(refresh=True)[-1] self.assertEqual('Delete me2', task.title) with vcr.use_cassette( 'fixtures/vcr_cassettes/task_destroy_valid2.json'): task.destroy() with vcr.use_cassette( 'fixtures/vcr_cassettes/tasks_after_new_one_deleted2.json'): tasks = user.tasks(refresh=True) self.assertFalse(task['id'] in map(lambda task: task['id'], tasks))
def test_task_could_be_approved_by_user(self): old_member = self.get_me() with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_for_sharing.json'): task = Task.create(user=old_member, title='Shared Task', category='Personal', priority='Normal', status='UNCHECKED') fake_email = '*****@*****.**' fake_password = '******' with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_user_for_sharing_and_approve.json', before_record_response=scrub_string(fake_password), filter_post_data_parameters=['password', 'j_password']): new_member = Client.create_user(name='fake', email=fake_email, password=fake_password) with vcr.use_cassette( 'fixtures/vcr_cassettes/task_share_with_user_to_approve.json'): task.share_with(new_member) with vcr.use_cassette( 'fixtures/vcr_cassettes/task_user_pending_tasks_before_approve.json' ): self.assertTrue( len(new_member.pending_tasks_ids(refresh=True)) == 1) with vcr.use_cassette( 'fixtures/vcr_cassettes/task_user_approve_pending_task.json'): new_member.approve_pending_task( pending_task_id=new_member.pending_tasks_ids()[0]) with vcr.use_cassette( 'fixtures/vcr_cassettes/task_user_pending_tasks_after_approve.json' ): self.assertTrue( len(new_member.pending_tasks_ids(refresh=True)) == 0) with vcr.use_cassette( 'fixtures/vcr_cassettes/task_members_after_refresh.json'): task.refresh() self.assertEqual([{ old_member['email']: old_member['name'] }, { new_member['email']: new_member['name'] }], task.members()) with vcr.use_cassette( 'fixtures/vcr_cassettes/tasks_of_new_member.json'): shared_task = new_member.tasks(refresh=True)[0] self.assertEqual(task['title'], shared_task['title'])
def test_text_notes_could_be_added_to_task(self): user = self.get_me() note = 'first one' with vcr.use_cassette('fixtures/vcr_cassettes/task_create_new_for_notes.json'): task = Task.create(user=user, title='I have notes') with vcr.use_cassette('fixtures/vcr_cassettes/task_add_some_notes.json'): task.add_note(note) self.assertTrue(note in task.notes())
def test_subtask_could_be_created_directly(self): user = self.get_me() with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_new_parent.json'): parent = Task.create(user=user, title='Parent') with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_new_subtask.json'): new_task = parent.create_subtask(title='New subtask') self.assertEqual(new_task, parent.subtasks()[0])
def test_subtask_could_be_added_as_another_task(self): user = self.get_me() with vcr.use_cassette('fixtures/vcr_cassettes/task_create_new_parent.json'): parent = Task.create(user=user, title='Parent') with vcr.use_cassette('fixtures/vcr_cassettes/task_create_new_subtask.json'): subtask = parent.create_subtask(title='New subtask') with vcr.use_cassette('fixtures/vcr_cassettes/task_add_subtask.json'): parent.add_subtask(subtask) self.assertEqual(subtask, parent.subtasks()[0])
def test_text_notes_could_be_added_to_task(self): user = self.get_me() note = 'first one' with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_new_for_notes.json'): task = Task.create(user=user, title='I have notes') with vcr.use_cassette( 'fixtures/vcr_cassettes/task_add_some_notes.json'): task.add_note(note) self.assertTrue(note in task.notes())
def test_subtask_could_be_added_as_another_task(self): user = self.get_me() with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_new_parent.json'): parent = Task.create(user=user, title='Parent') with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_new_subtask.json'): subtask = parent.create_subtask(title='New subtask') with vcr.use_cassette('fixtures/vcr_cassettes/task_add_subtask.json'): parent.add_subtask(subtask) self.assertEqual(subtask, parent.subtasks()[0])
def test_category_could_be_added_to_category(self): category = self.__get_category() with vcr.use_cassette('fixtures/vcr_cassettes/task_create_valid.json'): task = Task.create(user=category.user, title='Task For Category', priority='Normal', status='UNCHECKED') with vcr.use_cassette( 'fixtures/vcr_cassettes/category_move_task_to_category.json'): category.add_task(task) self.assertEqual(category, task.category()) self.assertTrue(task in category.tasks())
def test_task_creation_saves_attributers_correctly(self): title = 'New Task' note = 'Hello world' with vcr.use_cassette('fixtures/vcr_cassettes/task_create_valid_with_attributes.json'): task = Task.create(user=self.get_me(), title=title, category='Personal', priority='Normal', status='UNCHECKED', repeatingMethod='TASK_REPEAT_OFF', note=note, ) self.assertEqual(title, task.title) self.assertEqual(note, task['note'])
def test_task_creation_saves_attributers_correctly(self): title = 'New Task' note = 'Hello world' with vcr.use_cassette( 'fixtures/vcr_cassettes/task_create_valid_with_attributes.json' ): task = Task.create( user=self.get_me(), title=title, category='Personal', priority='Normal', status='UNCHECKED', repeatingMethod='TASK_REPEAT_OFF', note=note, ) self.assertEqual(title, task.title) self.assertEqual(note, task['note'])
def test_task_could_be_approved_by_user(self): old_member = self.get_me() with vcr.use_cassette('fixtures/vcr_cassettes/task_create_for_sharing.json'): task = Task.create(user=old_member, title='Shared Task', category='Personal', priority='Normal', status='UNCHECKED' ) fake_email = '*****@*****.**' fake_password = '******' with vcr.use_cassette('fixtures/vcr_cassettes/task_create_user_for_sharing_and_approve.json', before_record_response=scrub_string(fake_password), filter_post_data_parameters=['password', 'j_password'] ): new_member = Client.create_user(name='fake', email=fake_email, password=fake_password) with vcr.use_cassette('fixtures/vcr_cassettes/task_share_with_user_to_approve.json'): task.share_with(new_member) with vcr.use_cassette('fixtures/vcr_cassettes/task_user_pending_tasks_before_approve.json'): self.assertTrue(len(new_member.pending_tasks_ids(refresh=True)) == 1) with vcr.use_cassette('fixtures/vcr_cassettes/task_user_approve_pending_task.json'): new_member.approve_pending_task(pending_task_id=new_member.pending_tasks_ids()[0]) with vcr.use_cassette('fixtures/vcr_cassettes/task_user_pending_tasks_after_approve.json'): self.assertTrue(len(new_member.pending_tasks_ids(refresh=True)) == 0) with vcr.use_cassette('fixtures/vcr_cassettes/task_members_after_refresh.json'): task.refresh() self.assertEqual([ { old_member['email']: old_member['name'] }, { new_member['email']: new_member['name'] }], task.members() ) with vcr.use_cassette('fixtures/vcr_cassettes/tasks_of_new_member.json'): shared_task = new_member.tasks(refresh=True)[0] self.assertEqual(task['title'], shared_task['title'])
def test_category_could_be_removed_from_not_default_category(self): with vcr.use_cassette('fixtures/vcr_cassettes/categories.json'): categories = self.get_me().categories() category = categories[ 0] if not categories[0].isDefault else categories[1] with vcr.use_cassette('fixtures/vcr_cassettes/task_create_valid.json'): task = Task.create(user=category.user, title='Task For Category', priority='Normal', status='UNCHECKED') with vcr.use_cassette( 'fixtures/vcr_cassettes/category_move_task_to_category.json'): category.add_task(task) with vcr.use_cassette( 'fixtures/vcr_cassettes/category_remove_task_from_category.json' ): category.remove_task(task) self.assertNotEqual(category, task.category()) self.assertEqual(category.user.default_category(), task.category()) self.assertFalse(task in category.tasks())
def test_task_creation_checks_required_fields(self): with vcr.use_cassette('fixtures/vcr_cassettes/fake.json', record_mode='none'): with self.assertRaises(errors.ModelAttributeError): Task.create(user=self.get_me(), status='UNCHECKED')
def create_task(self, user, category, title): category.add_task(Task.create(user=user, title=title))