def data_task(data): m = type("Models", (object, ), {}) m.public_task = f.TaskFactory(project=data.public_project, ref=2) m.public_history_entry = f.HistoryEntryFactory.create( type=HistoryType.change, comment="testing public", key=make_key_from_model_object(m.public_task), diff={}, user={"pk": data.project_member_with_perms.pk}) m.private_task1 = f.TaskFactory(project=data.private_project1, ref=6) m.private_history_entry1 = f.HistoryEntryFactory.create( type=HistoryType.change, comment="testing 1", key=make_key_from_model_object(m.private_task1), diff={}, user={"pk": data.project_member_with_perms.pk}) m.private_task2 = f.TaskFactory(project=data.private_project2, ref=10) m.private_history_entry2 = f.HistoryEntryFactory.create( type=HistoryType.change, comment="testing 2", key=make_key_from_model_object(m.private_task2), diff={}, user={"pk": data.project_member_with_perms.pk}) return m
def data_task(data): m = type("Models", (object,), {}) m.public_task = f.TaskFactory(project=data.public_project, ref=2) m.public_task_attachment = f.TaskAttachmentFactory(project=data.public_project, content_object=m.public_task) m.private_task1 = f.TaskFactory(project=data.private_project1, ref=6) m.private_task1_attachment = f.TaskAttachmentFactory(project=data.private_project1, content_object=m.private_task1) m.private_task2 = f.TaskFactory(project=data.private_project2, ref=10) m.private_task2_attachment = f.TaskAttachmentFactory(project=data.private_project2, content_object=m.private_task2) return m
def data(): m = type("Models", (object,), {}) m.us_closed_status = f.UserStoryStatusFactory(is_closed=True) m.us_open_status = f.UserStoryStatusFactory(is_closed=False) m.task_closed_status = f.TaskStatusFactory(is_closed=True) m.task_open_status = f.TaskStatusFactory(is_closed=False) m.user_story1 = f.UserStoryFactory(status=m.us_open_status) m.user_story2 = f.UserStoryFactory(status=m.us_open_status) m.task1 = f.TaskFactory(user_story=m.user_story1, status=m.task_open_status) m.task2 = f.TaskFactory(user_story=m.user_story1, status=m.task_open_status) m.task3 = f.TaskFactory(user_story=m.user_story1, status=m.task_open_status) return m
def test_task_create(data): data.task1.status = data.task_closed_status data.task1.save() data.task2.status = data.task_closed_status data.task2.save() data.task3.status = data.task_closed_status data.task3.save() data.user_story1 = UserStory.objects.get(pk=data.user_story1.pk) assert data.user_story1.is_closed is True f.TaskFactory(user_story=data.user_story1, status=data.task_closed_status) data.user_story1 = UserStory.objects.get(pk=data.user_story1.pk) assert data.user_story1.is_closed is True f.TaskFactory(user_story=data.user_story1, status=data.task_open_status) data.user_story1 = UserStory.objects.get(pk=data.user_story1.pk) assert data.user_story1.is_closed is False
def test_breed_children_repeating_when_last_child_plus_rec_older_than_today( ) -> None: """ Given: A repeating parent task, and the last child due plus the recurrence date is before today. When: breed_children is called. Then: The second children's due date is set to now. """ parent = RecurrentTaskFactory(recurrence_type="repeating", recurrence="1mo", due=datetime(1800, 8, 2)) first_child = factories.TaskFactory(parent_id=parent.id_) first_child.close("completed", datetime(1800, 8, 3)) result = parent.breed_children(first_child) assert result.due == datetime(2017, 5, 21)
def test_breed_children_new_due_follows_repeating_algorithm() -> None: """ Given: A repeating parent task, and it's first child. When: breed_children is called. Then: The second children's due date is calculated using the repeating algorithm. It will apply `recurrence` to the last completed or deleted child's completed date independently of when today is. """ parent = RecurrentTaskFactory(recurrence_type="repeating", recurrence="1mo", due=datetime(1800, 8, 2)) first_child = factories.TaskFactory(parent_id=parent.id_) first_child.close("completed", datetime(2020, 8, 2)) result = parent.breed_children(first_child) assert result.due == datetime(2020, 9, 2)
def test_breed_children_new_due_follows_recurr_algorithm() -> None: """ Given: A recurring parent task. When: breed_children is called. Then: The children's due date is calculated using the recurring algorithm. It will apply `recurrence` to the parent's due date, until we get the next one in the future. """ parent = RecurrentTaskFactory(recurrence_type="recurring", recurrence="1mo", due=datetime(1800, 8, 2)) first_child = factories.TaskFactory(parent_id=parent.id_) first_child.close("completed", datetime(1800, 8, 2)) result = parent.breed_children(first_child) assert result.due == datetime(2017, 6, 2)
def data(): m = type("Models", (object, ), {}) m.registered_user = f.UserFactory.create() m.project_member_with_perms = f.UserFactory.create() m.project_member_without_perms = f.UserFactory.create() m.project_owner = f.UserFactory.create() m.other_user = f.UserFactory.create() m.public_project = f.ProjectFactory( is_private=False, anon_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)), public_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)) + ["comment_task"], owner=m.project_owner, tasks_csv_uuid=uuid.uuid4().hex) m.public_project = attach_project_extra_info( Project.objects.all()).get(id=m.public_project.id) m.private_project1 = f.ProjectFactory( is_private=True, anon_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)), public_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)), owner=m.project_owner, tasks_csv_uuid=uuid.uuid4().hex) m.private_project1 = attach_project_extra_info( Project.objects.all()).get(id=m.private_project1.id) m.private_project2 = f.ProjectFactory(is_private=True, anon_permissions=[], public_permissions=[], owner=m.project_owner, tasks_csv_uuid=uuid.uuid4().hex) m.private_project2 = attach_project_extra_info( Project.objects.all()).get(id=m.private_project2.id) m.blocked_project = f.ProjectFactory( is_private=True, anon_permissions=[], public_permissions=[], owner=m.project_owner, tasks_csv_uuid=uuid.uuid4().hex, blocked_code=project_choices.BLOCKED_BY_STAFF) m.blocked_project = attach_project_extra_info( Project.objects.all()).get(id=m.blocked_project.id) m.public_membership = f.MembershipFactory(project=m.public_project, user=m.project_member_with_perms, role__project=m.public_project, role__permissions=list( map(lambda x: x[0], MEMBERS_PERMISSIONS))) m.private_membership1 = f.MembershipFactory( project=m.private_project1, user=m.project_member_with_perms, role__project=m.private_project1, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) f.MembershipFactory(project=m.private_project1, user=m.project_member_without_perms, role__project=m.private_project1, role__permissions=[]) m.private_membership2 = f.MembershipFactory( project=m.private_project2, user=m.project_member_with_perms, role__project=m.private_project2, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) f.MembershipFactory(project=m.private_project2, user=m.project_member_without_perms, role__project=m.private_project2, role__permissions=[]) m.blocked_membership = f.MembershipFactory( project=m.blocked_project, user=m.project_member_with_perms, role__project=m.blocked_project, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) f.MembershipFactory(project=m.blocked_project, user=m.project_member_without_perms, role__project=m.blocked_project, role__permissions=[]) f.MembershipFactory(project=m.public_project, user=m.project_owner, is_admin=True) f.MembershipFactory(project=m.private_project1, user=m.project_owner, is_admin=True) f.MembershipFactory(project=m.private_project2, user=m.project_owner, is_admin=True) f.MembershipFactory(project=m.blocked_project, user=m.project_owner, is_admin=True) milestone_public_task = f.MilestoneFactory(project=m.public_project) milestone_private_task1 = f.MilestoneFactory(project=m.private_project1) milestone_private_task2 = f.MilestoneFactory(project=m.private_project2) milestone_blocked_task = f.MilestoneFactory(project=m.blocked_project) m.public_task = f.TaskFactory(project=m.public_project, status__project=m.public_project, milestone=milestone_public_task, user_story__project=m.public_project, user_story__milestone=milestone_public_task) m.public_task = attach_task_extra_info( Task.objects.all()).get(id=m.public_task.id) m.private_task1 = f.TaskFactory( project=m.private_project1, status__project=m.private_project1, milestone=milestone_private_task1, user_story__project=m.private_project1, user_story__milestone=milestone_private_task1) m.private_task1 = attach_task_extra_info( Task.objects.all()).get(id=m.private_task1.id) m.private_task2 = f.TaskFactory( project=m.private_project2, status__project=m.private_project2, milestone=milestone_private_task2, user_story__project=m.private_project2, user_story__milestone=milestone_private_task2) m.private_task2 = attach_task_extra_info( Task.objects.all()).get(id=m.private_task2.id) m.blocked_task = f.TaskFactory( project=m.blocked_project, status__project=m.blocked_project, milestone=milestone_blocked_task, user_story__project=m.blocked_project, user_story__milestone=milestone_blocked_task) m.blocked_task = attach_task_extra_info( Task.objects.all()).get(id=m.blocked_task.id) m.public_project.default_task_status = m.public_task.status m.public_project.save() m.private_project1.default_task_status = m.private_task1.status m.private_project1.save() m.private_project2.default_task_status = m.private_task2.status m.private_project2.save() m.blocked_project.default_task_status = m.blocked_task.status m.blocked_project.save() return m
def data(): m = type("Models", (object, ), {}) m.registered_user = f.UserFactory.create() m.project_member_with_perms = f.UserFactory.create() m.project_member_without_perms = f.UserFactory.create() m.project_owner = f.UserFactory.create() m.other_user = f.UserFactory.create() m.public_project = f.ProjectFactory( is_private=False, anon_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)), public_permissions=list(map(lambda x: x[0], USER_PERMISSIONS)), owner=m.project_owner, slug="public") m.private_project1 = f.ProjectFactory( is_private=True, anon_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)), public_permissions=list(map(lambda x: x[0], USER_PERMISSIONS)), owner=m.project_owner, slug="private1") m.private_project2 = f.ProjectFactory(is_private=True, anon_permissions=[], public_permissions=[], owner=m.project_owner, slug="private2") m.public_membership = f.MembershipFactory(project=m.public_project, user=m.project_member_with_perms, role__project=m.public_project, role__permissions=list( map(lambda x: x[0], MEMBERS_PERMISSIONS))) m.private_membership1 = f.MembershipFactory( project=m.private_project1, user=m.project_member_with_perms, role__project=m.private_project1, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) f.MembershipFactory(project=m.private_project1, user=m.project_member_without_perms, role__project=m.private_project1, role__permissions=[]) m.private_membership2 = f.MembershipFactory( project=m.private_project2, user=m.project_member_with_perms, role__project=m.private_project2, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) f.MembershipFactory(project=m.private_project2, user=m.project_member_without_perms, role__project=m.private_project2, role__permissions=[]) f.MembershipFactory(project=m.public_project, user=m.project_owner, is_admin=True) f.MembershipFactory(project=m.private_project1, user=m.project_owner, is_admin=True) f.MembershipFactory(project=m.private_project2, user=m.project_owner, is_admin=True) m.view_only_membership = f.MembershipFactory( project=m.private_project2, user=m.other_user, role__project=m.private_project2, role__permissions=["view_project"]) m.us = f.UserStoryFactory(project=m.private_project2, ref=1) m.task = f.TaskFactory(project=m.private_project2, ref=2) m.issue = f.IssueFactory(project=m.private_project2, ref=3) m.milestone = f.MilestoneFactory(project=m.private_project2, slug="milestone-test-1") return m
def data(): m = type("Models", (object,), {}) m.registered_user = f.UserFactory.create() m.project_member_with_perms = f.UserFactory.create() m.project_member_without_perms = f.UserFactory.create() m.project_owner = f.UserFactory.create() m.other_user = f.UserFactory.create() m.superuser = f.UserFactory.create(is_superuser=True) m.public_project = f.ProjectFactory(is_private=False, anon_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)), public_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)), owner=m.project_owner) m.private_project1 = f.ProjectFactory(is_private=True, anon_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)), public_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)), owner=m.project_owner) m.private_project2 = f.ProjectFactory(is_private=True, anon_permissions=[], public_permissions=[], owner=m.project_owner) m.blocked_project = f.ProjectFactory(is_private=True, anon_permissions=[], public_permissions=[], owner=m.project_owner, blocked_code=project_choices.BLOCKED_BY_STAFF) m.public_membership = f.MembershipFactory(project=m.public_project, user=m.project_member_with_perms, email=m.project_member_with_perms.email, role__project=m.public_project, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) m.private_membership1 = f.MembershipFactory(project=m.private_project1, user=m.project_member_with_perms, email=m.project_member_with_perms.email, role__project=m.private_project1, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) f.MembershipFactory(project=m.private_project1, user=m.project_member_without_perms, email=m.project_member_without_perms.email, role__project=m.private_project1, role__permissions=[]) m.private_membership2 = f.MembershipFactory(project=m.private_project2, user=m.project_member_with_perms, email=m.project_member_with_perms.email, role__project=m.private_project2, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) f.MembershipFactory(project=m.private_project2, user=m.project_member_without_perms, email=m.project_member_without_perms.email, role__project=m.private_project2, role__permissions=[]) m.blocked_membership = f.MembershipFactory(project=m.blocked_project, user=m.project_member_with_perms, email=m.project_member_with_perms.email, role__project=m.blocked_project, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) f.MembershipFactory(project=m.blocked_project, user=m.project_member_without_perms, email=m.project_member_without_perms.email, role__project=m.blocked_project, role__permissions=[]) f.MembershipFactory(project=m.public_project, user=m.project_owner, is_admin=True) f.MembershipFactory(project=m.private_project1, user=m.project_owner, is_admin=True) f.MembershipFactory(project=m.private_project2, user=m.project_owner, is_admin=True) f.MembershipFactory(project=m.blocked_project, user=m.project_owner, is_admin=True) m.public_task_ca = f.TaskCustomAttributeFactory(project=m.public_project) m.private_task_ca1 = f.TaskCustomAttributeFactory(project=m.private_project1) m.private_task_ca2 = f.TaskCustomAttributeFactory(project=m.private_project2) m.blocked_task_ca = f.TaskCustomAttributeFactory(project=m.blocked_project) m.public_task = f.TaskFactory(project=m.public_project, status__project=m.public_project, milestone__project=m.public_project, user_story__project=m.public_project) m.private_task1 = f.TaskFactory(project=m.private_project1, status__project=m.private_project1, milestone__project=m.private_project1, user_story__project=m.private_project1) m.private_task2 = f.TaskFactory(project=m.private_project2, status__project=m.private_project2, milestone__project=m.private_project2, user_story__project=m.private_project2) m.blocked_task = f.TaskFactory(project=m.blocked_project, status__project=m.blocked_project, milestone__project=m.blocked_project, user_story__project=m.blocked_project) m.public_task_cav = m.public_task.custom_attributes_values m.private_task_cav1 = m.private_task1.custom_attributes_values m.private_task_cav2 = m.private_task2.custom_attributes_values m.blocked_task_cav = m.blocked_task.custom_attributes_values return m
def data_task(data): m = type("Models", (object,), {}) m.public_task = f.TaskFactory(project=data.public_project, ref=2) m.private_task1 = f.TaskFactory(project=data.private_project1, ref=6) m.private_task2 = f.TaskFactory(project=data.private_project2, ref=10) return m
def data(): m = type("Models", (object,), {}) m.registered_user = f.UserFactory.create() m.project_member_with_perms = f.UserFactory.create() m.project_member_without_perms = f.UserFactory.create() m.project_owner = f.UserFactory.create() m.other_user = f.UserFactory.create() m.public_project = f.ProjectFactory(is_private=False, anon_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)), public_permissions=list(map(lambda x: x[0], USER_PERMISSIONS)), owner=m.project_owner) m.private_project1 = f.ProjectFactory(is_private=True, anon_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)), public_permissions=list(map(lambda x: x[0], USER_PERMISSIONS)), owner=m.project_owner) m.private_project2 = f.ProjectFactory(is_private=True, anon_permissions=[], public_permissions=[], owner=m.project_owner) m.public_membership = f.MembershipFactory(project=m.public_project, user=m.project_member_with_perms, role__project=m.public_project, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) m.private_membership1 = f.MembershipFactory(project=m.private_project1, user=m.project_member_with_perms, role__project=m.private_project1, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) f.MembershipFactory(project=m.private_project1, user=m.project_member_without_perms, role__project=m.private_project1, role__permissions=[]) m.private_membership2 = f.MembershipFactory(project=m.private_project2, user=m.project_member_with_perms, role__project=m.private_project2, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) f.MembershipFactory(project=m.private_project2, user=m.project_member_without_perms, role__project=m.private_project2, role__permissions=[]) m.public_task = f.TaskFactory(project=m.public_project, status__project=m.public_project, milestone__project=m.public_project, user_story__project=m.public_project) m.private_task1 = f.TaskFactory(project=m.private_project1, status__project=m.private_project1, milestone__project=m.private_project1, user_story__project=m.private_project1) m.private_task2 = f.TaskFactory(project=m.private_project2, status__project=m.private_project2, milestone__project=m.private_project2, user_story__project=m.private_project2) m.public_project.default_task_status = m.public_task.status m.public_project.save() m.private_project1.default_task_status = m.private_task1.status m.private_project1.save() m.private_project2.default_task_status = m.private_task2.status m.private_project2.save() return m