def test_stop_sprint_move_issues_to_new_sprint(self): # self.sprint should not have started self.assertNotEqual(self.sprint.seqnum, -1) project = Project(creator=self.user, name_short='APF') project.save() project.manager.add(self.user) sprint = Sprint(project=project) sprint.save() self.assertEqual(project.sprint.get_new_sprints().count(), 1) # columns and issues for testing archiving function kanbancol1 = KanbanColumn.objects.get(name='Todo', project=project) kanbancol2 = KanbanColumn.objects.get(name='In Progress', project=project) kanbancol3 = KanbanColumn.objects.get(name='Done', project=project) issue = Issue(title="Test-Issue", kanbancol=kanbancol1, project=project, type="Bug", sprint=sprint) issue.save() issue2 = Issue(title="Test-Issue2", kanbancol=kanbancol2, project=project, type="Bug", sprint=sprint) issue2.save() issue3 = Issue(title="Test-Issue3", kanbancol=kanbancol2, project=project, type="Bug", sprint=sprint) issue3.save() issue4 = Issue(title="Test-Issue4", kanbancol=kanbancol3, project=project, type="Bug") issue4.save() sprint.set_active() # move to autocreated sprint response = self.client.post(reverse('sprint:stopsprint', kwargs={'project': project.name_short, 'sqn_s': sprint.seqnum}), {'sprint': 'new', 'move_to_new_sprint': [issue.number, issue2.number]}, follow=True) # new sprint created # self.sprint and sprint created during post request self.assertEqual(project.sprint.all().count(), 2) self.assertEqual(project.sprint.get_new_sprints().count(), 1) self.assertEqual(project.sprint.get_old_sprints().count(), 1) # issue, issue2 in new sprint, issue3 in backlog self.assertIn(issue, project.sprint.get_new_sprints().last().issue.all()) self.assertIn(issue2, project.sprint.get_new_sprints().last().issue.all()) self.assertNotIn(issue3, project.sprint.get_new_sprints().last().issue.all()) issue3.refresh_from_db() self.assertEqual(issue3.sprint, None) # move to existing sprint sprint = project.sprint.get_new_sprints().last() sprint.set_active() project.refresh_from_db() sprint2 = Sprint(project=project) sprint2.save() response = self.client.post(reverse('sprint:stopsprint', kwargs={'project': project.name_short, 'sqn_s': sprint.seqnum}), {'sprint': sprint2.seqnum, 'move_to_new_sprint': [issue.number]}, follow=True) # issue in sprint2, issue2 moved to backlog self.assertIn(issue, sprint2.issue.all()) self.assertNotIn(issue2, sprint2.issue.all()) issue2.refresh_from_db() self.assertEqual(issue2.sprint, None)
def test_sprint_functions(self): # sprint is new sprint self.assertTrue(self.sprint in Sprint.objects.get_new_sprints()) self.assertFalse(self.sprint in Sprint.objects.get_current_sprints()) self.assertFalse(self.sprint in Sprint.objects.get_old_sprints()) # set sprint active self.sprint.set_active() self.assertTrue(self.sprint.is_active) # sprint is new current sprint self.assertFalse(self.sprint in Sprint.objects.get_new_sprints()) self.assertTrue(self.sprint in Sprint.objects.get_current_sprints()) self.assertFalse(self.sprint in Sprint.objects.get_old_sprints()) # done and undone issue to put back in backlog kanbancoldone = KanbanColumn.objects.get(type='Done', project=self.project) kanbancolprogress = KanbanColumn.objects.get(type='InProgress', project=self.project) issuedone = Issue(title="Test-Issue", kanbancol=kanbancoldone, project=self.project, type="Bug", sprint=self.sprint) issuedone.save() issueprogress = Issue(title="Test-Issue", kanbancol=kanbancolprogress, project=self.project, type="Bug", sprint=self.sprint) issueprogress.save() # set sprint inactive issueleft = self.sprint.set_inactive() self.assertTrue(self.sprint.is_inactive()) issuedone.refresh_from_db() issueprogress.refresh_from_db() # issues are right archived and assigned self.assertTrue(issueleft) self.assertTrue(issuedone.archived) self.assertFalse(issueprogress.archived) self.assertIsNotNone(issuedone.sprint) self.assertIsNone(issueprogress.sprint) self.assertTrue(issueprogress.was_in_sprint) # sprint is new old sprint self.assertFalse(self.sprint in Sprint.objects.get_new_sprints()) self.assertFalse(self.sprint in Sprint.objects.get_current_sprints()) self.assertTrue(self.sprint in Sprint.objects.get_old_sprints())
def test_board_drag_n_drop(self): def ajax_complete(driver): try: return 0 == driver.execute_script("return jQuery.active") except WebDriverException: pass # create project and issues driver = self.selenium project = Project(name='TestProjekt', name_short='TP', creator=self.user) project.save() project.developer.add(self.user) issue1 = Issue(project=project, title="TestIssue1") issue2 = Issue(project=project, title="TestIssue2") issue1.save() issue2.save() driver.get("{}{}".format( self.live_server_url, reverse('sprint:sprintboard', kwargs={'project': project.name_short}))) self.assertEqual(issue1.kanbancol.position, 0) self.assertEqual(issue2.kanbancol.position, 0) driver.find_element_by_link_text("Board").click() # move issue1 and issue2 source_element = driver.find_element_by_id('board_issue_1') dest_element = driver.find_element_by_id('sortable1') ActionChains(driver).drag_and_drop(source_element, dest_element).perform() source_element = driver.find_element_by_id('board_issue_2') dest_element = driver.find_element_by_id('sortable2') ActionChains(driver).drag_and_drop(source_element, dest_element).perform() WebDriverWait(driver, 10).until(ajax_complete, "Timeout waiting for page to load") # assert kanbancol has changed issue1.refresh_from_db() issue2.refresh_from_db()
def test_archive_and_unarchive_single_issue_function(self): issue = Issue(title="bar", project=self.project) issue.save() self.assertFalse(issue.archived) n = Issue.objects.archived().count() values = {'sqn_i': issue.number} response = self.client.post( reverse('issue:archiveissue', kwargs={'project': self.project.name_short}), values) self.assertRedirects( response, reverse('issue:detail', kwargs={ 'project': self.project.name_short, 'sqn_i': issue.number })) issue.refresh_from_db() self.assertEqual(Issue.objects.archived().count(), (n + 1)) self.assertTrue(issue.archived) values = {'sqn_i': issue.number} response = self.client.post( reverse('issue:unarchiveissue', kwargs={'project': self.project.name_short}), values) self.assertRedirects( response, reverse('issue:detail', kwargs={ 'project': self.project.name_short, 'sqn_i': issue.number })) issue.refresh_from_db() self.assertEqual(Issue.objects.archived().count(), n) self.assertFalse(issue.archived)
def test_dont_assign_issues_to_stoped_sprints(self): issue = Issue(title="Test-Issue", project=self.project, type="Bug") issue.save() issue2 = Issue(title="Test-Issue2", project=self.project, type="Bug") issue2.save() # start sprint self.sprint.set_active() self.sprint.save() self.project.currentsprint = self.sprint self.project.save() # assign first issue response = self.client.post(reverse('sprint:assigntosprint', kwargs={'project': self.project.name_short}), {'sqn_i': issue.number}, follow=True, HTTP_REFERER=reverse('backlog:backlog', kwargs={'project': self.project.name_short})) self.assertRedirects(response, reverse('backlog:backlog', kwargs={'project': self.project.name_short, 'sqn_s': self.sprint.seqnum})) # first issue is part of the sprint issue.refresh_from_db() self.assertIsNotNone(issue.sprint) # stop sprint response = self.client.post(reverse('sprint:stopsprint', kwargs={'project': self.project.name_short, 'sqn_s': self.sprint.seqnum}), {'sprint': 'new', 'move_to_new_sprint': []}, follow=True) self.assertEqual(Issue.objects.get(pk=issue.pk).was_in_sprint, True) # assign second issue => should fail response = self.client.post(reverse('sprint:assigntosprint', kwargs={'project': self.project.name_short}), {'sqn_i': issue2.number}, follow=True, HTTP_REFERER=reverse('backlog:backlog', kwargs={'project': self.project.name_short})) self.assertRedirects(response, reverse('backlog:backlog', kwargs={'project': self.project.name_short})) # second issue is NOT part of the sprint issue2.refresh_from_db() self.assertIsNone(issue2.sprint) # create new sprint - so we don't run into the not-sprint part but really into the atomic check for enddate sprint2 = Sprint(project=self.project) sprint2.save() response = self.client.post(reverse('sprint:assigntosprint', kwargs={'project': self.project.name_short}), {'sqn_i': issue2.number}, follow=True, HTTP_REFERER=reverse('backlog:backlog', kwargs={'project': self.project.name_short, 'sqn_s': self.sprint.seqnum})) self.assertRedirects(response, reverse('backlog:backlog', kwargs={'project': self.project.name_short, 'sqn_s': self.sprint.seqnum})) issue2.refresh_from_db() self.assertIsNone(issue2.sprint)
def test_issue_kanban_moveleftright(self): self.assertEqual(self.project.kanbancol.count(), 4) issue1 = Issue(title="issue1", project=self.project, kanbancol=self.project.kanbancol.first()) issue1.save() self.assertEqual(issue1.get_left_kCol_for_issue(), -1) self.assertEqual(issue1.get_right_kCol_for_issue(), 1) # move issue to next row and check results issue1.kanbancol = self.project.kanbancol.get(position='1') issue1.save() self.assertEqual(issue1.get_left_kCol_for_issue(), 0) self.assertEqual(issue1.get_right_kCol_for_issue(), 2) # move issue to last row and check results issue1.kanbancol = self.project.kanbancol.get(position='3') issue1.save() self.assertEqual(issue1.get_left_kCol_for_issue(), 2) self.assertEqual(issue1.get_right_kCol_for_issue(), -1) # test view function response = self.client.post( reverse('issue:setkanbancol', kwargs={'project': self.project.name_short}), { 'sqn_k': '0', 'sqn_i': issue1.number, }, follow=True) self.assertRedirects( response, reverse('issue:projList', kwargs={'project': self.project.name_short})) issue1.refresh_from_db() self.assertEqual(issue1.kanbancol.position, 0) # check if error handling works (set col too high) response = self.client.post( reverse('issue:setkanbancol', kwargs={'project': self.project.name_short}), { 'sqn_k': '4', 'sqn_i': issue1.number, }, follow=True) self.assertRedirects( response, reverse('issue:projList', kwargs={'project': self.project.name_short})) self.assertEqual(len(list(response.context['messages'])), 1) issue1.refresh_from_db() self.assertEqual(issue1.kanbancol.position, 0) # check with invalid issue response = self.client.post( reverse('issue:setkanbancol', kwargs={'project': self.project.name_short}), { 'sqn_k': '2', 'sqn_i': issue1.number + 1, }, follow=True) self.assertRedirects( response, reverse('issue:projList', kwargs={'project': self.project.name_short})) self.assertEqual(len(list(response.context['messages'])), 1) issue1.refresh_from_db() self.assertEqual(issue1.kanbancol.position, 0)
def test_start_and_stop_sprint(self): # self.sprint should not have started self.assertNotEqual(self.sprint.seqnum, -1) project = Project(creator=self.user, name_short='APF') project.save() project.manager.add(self.user) n = Sprint.objects.get_new_sprints().count() sprint = Sprint(project=project) sprint.save() self.assertEqual(Sprint.objects.get_new_sprints().count(), (n+1)) self.assertTrue(sprint in Sprint.objects.get_new_sprints()) self.assertFalse(sprint in Sprint.objects.get_current_sprints()) self.assertFalse(sprint in Sprint.objects.get_old_sprints()) self.assertIsNone(project.currentsprint) # columns and issues for testing archiving function kanbancol3 = KanbanColumn.objects.get(name='Todo', project=project) kanbancol3.type = 'Done' kanbancol3.save() kanbancol2 = KanbanColumn.objects.get(name='In Progress', project=project) kanbancol1 = KanbanColumn.objects.get(name='Done', project=project) kanbancol1.type = 'ToDo' kanbancol1.save() issue = Issue(title="Test-Issue", kanbancol=kanbancol1, project=project, type="Bug", sprint=sprint) issue.save() issue2 = Issue(title="Test-Issue2", kanbancol=kanbancol2, project=project, type="Bug", sprint=sprint) issue2.save() issue3 = Issue(title="Test-Issue3", kanbancol=kanbancol3, project=project, type="Bug", sprint=sprint) issue3.save() issue4 = Issue(title="Test-Issue4", kanbancol=kanbancol3, project=project, type="Bug") issue4.save() # issues (except issue4) should be in not started sprint self.assertFalse(issue in Issue.objects.without_sprint()) self.assertFalse(issue in Issue.objects.current_sprint()) self.assertFalse(issue in Issue.objects.archived()) self.assertFalse(project.has_active_sprint()) # start sprint response = self.client.post(reverse('sprint:startsprint', kwargs={'project': project.name_short, 'sqn_s': sprint.seqnum})) self.assertRedirects(response, reverse('backlog:backlog', kwargs={'project': project.name_short, 'sqn_s': sprint.seqnum})) sprint.refresh_from_db() project.refresh_from_db() # sprint should be current sprint self.assertIsNotNone(project.currentsprint) self.assertEqual(project.currentsprint.seqnum, sprint.seqnum) self.assertTrue(project.has_active_sprint()) self.assertFalse(sprint in Sprint.objects.get_new_sprints()) self.assertTrue(sprint in Sprint.objects.get_current_sprints()) self.assertFalse(sprint in Sprint.objects.get_old_sprints()) # no issues archived until now self.assertFalse(issue in Issue.objects.without_sprint()) self.assertTrue(issue in Issue.objects.current_sprint()) self.assertFalse(issue in Issue.objects.archived()) self.assertFalse(issue2 in Issue.objects.archived()) self.assertFalse(issue3 in Issue.objects.archived()) self.assertFalse(issue4 in Issue.objects.archived()) # set sprint inactive(and archive) response = self.client.post(reverse('sprint:stopsprint', kwargs={'project': project.name_short, 'sqn_s': sprint.seqnum}), {'sprint': 'new', 'move_to_new_sprint': []}, follow=True) self.assertRedirects(response, reverse('backlog:backlog', kwargs={'project': project.name_short})) sprint.refresh_from_db() project.refresh_from_db() # sprint should no more be current sprint. not-done-issues back in backlog (not archived, without sprint) self.assertFalse(sprint in Sprint.objects.get_new_sprints()) self.assertFalse(sprint in Sprint.objects.get_current_sprints()) self.assertTrue(sprint in Sprint.objects.get_old_sprints()) self.assertIsNone(project.currentsprint) self.assertFalse(project.has_active_sprint()) self.assertTrue(issue in Issue.objects.without_sprint()) self.assertFalse(issue in Issue.objects.current_sprint()) # issue3 is archived because of column type and finished sprint, # issue (wrong type), issue2 (wrong type) and 4 (wrong sprint) arent self.assertFalse(issue in Issue.objects.archived()) self.assertFalse(issue2 in Issue.objects.archived()) self.assertTrue(issue3 in Issue.objects.archived()) self.assertFalse(issue4 in Issue.objects.archived()) # issue and issue4 are in same column, both without sprint issue4.kanbancol = kanbancol1 issue4.save() # archive column of issue and issue4 values = {'pos_c': kanbancol1.position} response = self.client.post(reverse('issue:archivecol', kwargs={'project': project.name_short}), values) self.assertRedirects(response, reverse('sprint:sprintboard', kwargs={'project': project.name_short})) issue4.refresh_from_db() self.assertTrue(issue in Issue.objects.archived()) # archived by archivecol self.assertFalse(issue2 in Issue.objects.archived()) # not archived wrong type self.assertTrue(issue3 in Issue.objects.archived()) # archived by stopsprint self.assertTrue(issue4 in Issue.objects.archived()) # archived by archivecol