def test_lazy_overrides_non_lazy_attachments(self): # given attachment = Attachment('attachment') attachment2 = Attachment('attachment2') # when result = Task.from_dict({'attachments': [attachment]}, lazy={'attachments': [attachment2]}) # then self.assertIsInstance(result, Task) self.assertEqual([attachment2], list(result.attachments))
def test_anon_user_can_view_public_task(self): # given task = Task('task', is_public=True) anon = AnonymousUserMixin() self.pl.add(task) self.pl.commit() # when result = TaskUserOps.user_can_view_task(task, anon) # then self.assertTrue(result)
def test_guest_user_can_view_public_task(self): # given task = Task('task', is_public=True) guest = self.pl.get_guest_user() self.pl.add(task) self.pl.commit() # when result = TaskUserOps.user_can_view_task(task, guest) # then self.assertTrue(result)
def test_unauthorized_nonadmin_cannot_access_task(self): # given task = Task('task') user = User('*****@*****.**') self.pl.add(task) self.pl.add(user) self.pl.commit() # when result = TaskUserOps.is_user_authorized_or_admin(task, user) # then self.assertFalse(result)
def test_unauthorized_nonadmin_cannot_edit_public_task(self): # given task = Task('task', is_public=True) user = User('*****@*****.**') self.pl.add(task) self.pl.add(user) self.pl.commit() # when result = TaskUserOps.user_can_edit_task(task, user) # then self.assertFalse(result)
def test_clearing_nullifies_task(self): # given task = Task('task') note = Note('note') note.task = task # precondition self.assertIs(task, note.task) # when note.clear_relationships() # then self.assertIsNone(note.task)
def test_unauthorized_admin_can_edit_private_task(self): # given task = Task('task') user = User('*****@*****.**', None, True) self.pl.add(task) self.pl.add(user) self.pl.commit() # when result = TaskUserOps.user_can_edit_task(task, user) # then self.assertTrue(result)
def test_clearing_nullifies_task(self): # given task = Task('task') attachment = Attachment('attachment') attachment.task = task # precondition self.assertIs(task, attachment.task) # when attachment.clear_relationships() # then self.assertIsNone(attachment.task)
def test_lazy_overrides_all_non_lazy_properties(self): # given attachment = Attachment('attachment') note = Note('note') # when result = Task.from_dict({'attachments': [attachment]}, lazy={'notes': [note]}) # then self.assertIsInstance(result, Task) self.assertEqual([], list(result.attachments)) self.assertEqual([note], list(result.notes))
def test_unauthorized_nonadmin_cannot_view_private_task(self): # given task = Task('task') user = User('*****@*****.**') self.pl.add(task) self.pl.add(user) self.pl.commit() # when result = TaskUserOps.user_can_view_task(task, user) # then self.assertFalse(result)
def test_setting_task_as_dependee_sets_other_task_as_dependant(self): # given t1 = Task('t1') t2 = Task('t2') # precondition self.assertEqual(0, len(t1.dependants)) self.assertEqual(0, len(t1.dependees)) self.assertEqual(0, len(t2.dependants)) self.assertEqual(0, len(t2.dependees)) # when t1.dependees.append(t2) # then self.assertEqual(0, len(t1.dependants)) self.assertEqual(1, len(t1.dependees)) self.assertEqual(1, len(t2.dependants)) self.assertEqual(0, len(t2.dependees)) self.assertTrue(t2 in t1.dependees) self.assertTrue(t1 in t2.dependants)
def test_authorized_admin_can_access_task(self): # given task = Task('task') user = User('*****@*****.**', None, True) self.pl.add(task) self.pl.add(user) task.users.append(user) self.pl.commit() # when result = TaskUserOps.is_user_authorized_or_admin(task, user) # then self.assertTrue(result)
def test_authorized_admin_can_edit_public_task(self): # given task = Task('task', is_public=True) user = User('*****@*****.**', None, True) self.pl.add(task) self.pl.add(user) task.users.append(user) self.pl.commit() # when result = TaskUserOps.user_can_edit_task(task, user) # then self.assertTrue(result)
def test_setting_task_as_before_sets_other_task_as_after(self): # given t1 = Task('t1') t2 = Task('t2') # precondition self.assertEqual(0, len(t1.prioritize_before)) self.assertEqual(0, len(t1.prioritize_after)) self.assertEqual(0, len(t2.prioritize_before)) self.assertEqual(0, len(t2.prioritize_after)) # when t1.prioritize_before.append(t2) # then self.assertEqual(1, len(t1.prioritize_before)) self.assertEqual(0, len(t1.prioritize_after)) self.assertEqual(0, len(t2.prioritize_before)) self.assertEqual(1, len(t2.prioritize_after)) self.assertTrue(t2 in t1.prioritize_before) self.assertTrue(t1 in t2.prioritize_after)
def test_tasks_with_tags_return_those_tags_values(self): # given t1 = Task('t1') tag1 = Tag('tag1') t1.tags.append(tag1) t2 = Task('t2') tag2 = Tag('tag2') t2.tags.append(tag1) t2.tags.append(tag2) self.pl.create_all() self.pl.add(t1) self.pl.add(t2) self.pl.add(tag1) self.pl.add(tag2) self.pl.commit() # when result = set(t1.get_tag_values()) # then self.assertEqual({tag1.value}, result) # when result = set(t2.get_tag_values()) # then self.assertEqual({tag1.value, tag2.value}, result)
def test_cycle_check_yields_false_for_no_cycles(self): # given t1 = Task('t1') t2 = Task('t2') t1.dependants.append(t2) # expect self.assertFalse(t1.contains_dependency_cycle()) self.assertFalse(t2.contains_dependency_cycle())
def test_cycle_check_yields_false_for_no_cycles(self): # given t1 = Task('t1') t2 = Task('t2') t1.prioritize_before.append(t2) # expect self.assertFalse(t1.contains_priority_cycle()) self.assertFalse(t2.contains_priority_cycle())
def create_task(self, summary, description='', is_done=False, is_deleted=False, deadline=None, expected_duration_minutes=None, expected_cost=None, is_public=False, lazy=None): return Task(summary=summary, description=description, is_done=is_done, is_deleted=is_deleted, deadline=deadline, expected_duration_minutes=expected_duration_minutes, expected_cost=expected_cost, is_public=is_public, lazy=lazy)
def test_empty_yields_empty_dbtask(self): # when result = Task.from_dict({}) # then self.assertIsInstance(result, Task) self.assertIsNone(result.id) self.assertIsNone(result.summary) self.assertEqual('', result.description) self.assertFalse(result.is_done) self.assertFalse(result.is_deleted) self.assertEqual(0, result.order_num) self.assertIsNone(result.deadline) self.assertIsNone(result.expected_duration_minutes) self.assertIsNone(result.expected_cost) self.assertEqual([], list(result.tags)) self.assertEqual([], list(result.users)) self.assertIsNone(result.parent) self.assertIsNone(result.parent_id) self.assertEqual([], list(result.dependees)) self.assertEqual([], list(result.dependants)) self.assertEqual([], list(result.prioritize_before)) self.assertEqual([], list(result.prioritize_after))
def test_valid_is_done_gets_set(self): # when result = Task.from_dict({'is_done': True}) # then self.assertIsInstance(result, Task) self.assertTrue(result.is_done)
def test_constructor_default_id_is_none(self): # when task = Task('summary') # then self.assertIsNone(task.id)
def test_cycle_check_yields_false_for_trees(self): # given t1 = Task('t1') t2 = Task('t2') t3 = Task('t3') t4 = Task('t4') t1.prioritize_before.append(t2) t1.prioritize_before.append(t3) t2.prioritize_before.append(t4) t3.prioritize_before.append(t4) # expect self.assertFalse(t1.contains_priority_cycle()) self.assertFalse(t2.contains_priority_cycle()) self.assertFalse(t3.contains_priority_cycle()) self.assertFalse(t4.contains_priority_cycle())
def test_is_deleted_none_becomes_false(self): # when result = Task.from_dict({'is_deleted': None}) # then self.assertIsInstance(result, Task) self.assertFalse(result.is_deleted)
def test_cycle_check_yields_true_for_long_cycles(self): # given t1 = Task('t1') t2 = Task('t2') t3 = Task('t3') t4 = Task('t4') t5 = Task('t5') t6 = Task('t6') t1.prioritize_before.append(t2) t2.prioritize_before.append(t3) t3.prioritize_before.append(t4) t4.prioritize_before.append(t5) t5.prioritize_before.append(t6) t6.prioritize_before.append(t1) # expect self.assertTrue(t1.contains_priority_cycle()) self.assertTrue(t2.contains_priority_cycle()) self.assertTrue(t3.contains_priority_cycle()) self.assertTrue(t4.contains_priority_cycle()) self.assertTrue(t5.contains_priority_cycle()) self.assertTrue(t6.contains_priority_cycle())
def setUp(self): self.parent = Task('parent') self.c1 = Task('c1') self.c2 = Task('c2')
def setUp(self): self.task = Task('task') self.user = User('user')
def setUp(self): self.t1 = Task('t1') self.t2 = Task('t2')
def setUp(self): self.task = Task('parent') self.n1 = Note('n1') self.n2 = Note('n2')
def setUp(self): self.task = Task('task') self.tag = Tag('tag')
def setUp(self): self.task = Task('parent') self.n1 = Attachment('n1') self.n2 = Attachment('n2')