예제 #1
0
 def test_model_task_status(self):
     """Test task status"""
     obj = TaskStatus(name='test')
     obj.save()
     self.assertEquals('test', obj.name)
     self.assertNotEquals(obj.id, None)
     obj.get_absolute_url()
     obj.delete()
예제 #2
0
class ProjectsViewsTest(TestCase):
    username = "******"
    password = "******"

    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(name='default')
        perspective.set_default_user()
        perspective.save()

        ModuleSetting.set('default_perspective', perspective.id)

        self.contact_type = ContactType(name='test')
        self.contact_type.set_default_user()
        self.contact_type.save()

        self.contact = Contact(name='test', contact_type=self.contact_type)
        self.contact.related_user = self.user.profile
        self.contact.set_default_user()
        self.contact.save()

        self.project = Project(name='test', manager=self.contact, client=self.contact)
        self.project.set_default_user()
        self.project.save()

        self.status = TaskStatus(name='test')
        self.status.set_default_user()
        self.status.save()

        self.milestone = Milestone(name='test', project=self.project, status=self.status)
        self.milestone.set_default_user()
        self.milestone.save()

        self.task = Task(name='test', project=self.project, status=self.status, caller=self.contact)
        self.task.set_default_user()
        self.task.save()

        self.task_assigned = Task(name='test', project=self.project, status=self.status)
        self.task_assigned.save()
        self.task_assigned.assigned.add(self.user.profile)

        self.time_slot = TaskTimeSlot(task=self.task, details='test', time_from=datetime.now(), user=self.user.profile)
        self.time_slot.set_default_user()
        self.time_slot.save()

        self.parent = Project(name='test')
        self.parent.set_default_user()
        self.parent.save()

        self.parent_task = Task(
            name='test', project=self.project, status=self.status, priority=3)
        self.parent_task.set_default_user()
        self.parent_task.save()

        self.client = Client()

        self.client.login(username=self.username, password=self.password)

    def test_index(self):
        """Test project index page with login at /projects/"""
        response = self.client.get(reverse('projects'))
        self.assertEquals(response.status_code, 200)

    def assertQuerysetEqual(self, qs, values, transform=repr, ordered=True, msg=None):
        return super(ProjectsViewsTest, self).assertQuerysetEqual(qs, map(repr, values), transform, ordered, msg)

    def test_index_owned(self):
        """Test owned tasks page at /task/owned/"""
        response = self.client.get(reverse('projects_index_owned'))
        self.assertEquals(response.status_code, 200)
        self.assertQuerysetEqual(response.context['milestones'], [self.milestone])
        self.assertQuerysetEqual(response.context['tasks'], [self.task])
        self.assertEqual(type(response.context['filters']), FilterForm)
        # todo: actually test the form generated, if it has the right fields and querysets
        # self.assertEqual(str(response.context['filters']), str(filterform))

    def test_index_assigned(self):
        """Test assigned tasks page at /task/assigned/"""
        response = self.client.get(reverse('projects_index_assigned'))
        self.assertEquals(response.status_code, 200)
        self.assertQuerysetEqual(response.context['milestones'], [self.milestone])
        self.assertQuerysetEqual(response.context['tasks'], [self.task_assigned])
        self.assertEqual(type(response.context['filters']), FilterForm)

    # Projects
    def test_project_add(self):
        """Test index page with login at /projects/add/"""
        response = self.client.get(reverse('project_add'))
        self.assertEquals(response.status_code, 200)
        self.assertEqual(type(response.context['form']), ProjectForm)

        projects_qty = Project.objects.count()
        form_params = {'name': 'project_name', 'details': 'new project details'}
        response = self.client.post(reverse('project_add'), data=form_params)
        self.assertEquals(response.status_code, 302)
        project_id = response['Location'].split('/')[-1]
        self.assertRedirects(response, reverse('projects_project_view', args=[project_id]))
        self.assertEqual(Project.objects.count(), projects_qty+1)
        project = Project.objects.get(id=project_id)
        self.assertEqual(project.name, form_params['name'])
        self.assertEqual(project.details, form_params['details'])

    def test_project_add_typed(self):
        """Test index page with login at /projects/add/<project_id>/"""
        response = self.client.get(reverse('projects_project_add_typed', args=[self.parent.id]))
        self.assertEquals(response.status_code, 200)

    def test_project_view_login(self):
        """Test index page with login at /projects/view/<project_id>"""
        response = self.client.get(reverse('projects_project_view', args=[self.project.id]))
        self.assertEquals(response.status_code, 200)

    def test_project_edit_login(self):
        """Test index page with login at /projects/edit//<project_id>"""
        response = self.client.get(reverse('projects_project_edit', args=[self.project.id]))
        self.assertEquals(response.status_code, 200)

    def test_project_delete_login(self):
        """Test index page with login at /projects/delete//<project_id>"""
        response = self.client.get(reverse('projects_project_delete', args=[self.project.id]))
        self.assertEquals(response.status_code, 200)

    # Milestones
    def test_milestone_add(self):
        """Test index page with login at /projects/milestone/add"""
        response = self.client.get(reverse('projects_milestone_add'))
        self.assertEquals(response.status_code, 200)

    def test_milestone_add_typed(self):
        """Test index page with login at /projects/milestone/add/<project_id>"""
        response = self.client.get(reverse('projects_milestone_add_typed', args=[self.parent.id]))
        self.assertEquals(response.status_code, 200)

    def test_milestone_view_login(self):
        """Test index page with login at /projects/milestone/view/<milestone_id>"""
        response = self.client.get(reverse('projects_milestone_view', args=[self.milestone.id]))
        self.assertEquals(response.status_code, 200)

    def test_milestone_edit_login(self):
        """Test index page with login at /projects/milestone/edit/<milestone_id>"""
        response = self.client.get(reverse('projects_milestone_edit', args=[self.milestone.id]))
        self.assertEquals(response.status_code, 200)

    def test_milestone_delete_login(self):
        """Test index page with login at /projects/milestone/delete/<milestone_id>"""
        response = self.client.get(reverse('projects_milestone_delete', args=[self.milestone.id]))
        self.assertEquals(response.status_code, 200)

    # Tasks
    def test_task_add(self):
        """Test index page with login at /projects/task/add/"""
        response = self.client.get(reverse('projects_task_add'))
        self.assertEquals(response.status_code, 200)

    def test_task_add_typed(self):
        """Test index page with login at /projects/task/add/<project_id>"""
        response = self.client.get(reverse('projects_task_add_typed', args=[self.project.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_add_to_milestone(self):
        """Test index page with login at /projects/task/add/<milestone_id>"""
        response = self.client.get(reverse('projects_task_add_to_milestone', args=[self.milestone.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_add_subtask(self):
        """Test index page with login at /projects/task/add/<task_id>/"""
        response = self.client.get(reverse('projects_task_add_subtask', args=[self.parent_task.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_set_status(self):
        """Test index page with login at /projects/task/add/<task_id>/status/<status_id>"""
        response = self.client.get(reverse('projects_task_set_status', args=[self.task.id, self.status.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_view_login(self):
        """Test index page with login at /projects/task/view/<task_id>"""
        response = self.client.get(reverse('projects_task_view', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_edit_login(self):
        """Test index page with login at /projects/task/edit/<task_id>"""
        response = self.client.get(reverse('projects_task_edit', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_delete_login(self):
        """Test index page with login at /projects/task/delete/<task_id>"""
        response = self.client.get(reverse('projects_task_delete', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    # Task Time Slots
    def test_time_slot_add(self):
        """Test index page with login at /projects/task/view/time/<task_id>add/"""
        response = self.client.get(reverse('projects_task_time_slot_add', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    def test_time_slot_view_login(self):
        """Test index page with login at /projects/task/view/time/<time_slot_id>"""
        response = self.client.get(reverse('projects_task_view', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    def test_time_slot_edit_login(self):
        """Test index page with login at /projects/task/edit/time/<time_slot_id>"""
        response = self.client.get(reverse('projects_task_edit', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    def test_time_slot_delete_login(self):
        """Test index page with login at /projects/task/delete/time/<time_slot_id>"""
        response = self.client.get(reverse('projects_task_delete', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

    # Task Statuses
    def test_task_status_add(self):
        """Test index page with login at /projects/task/status/add/"""
        response = self.client.get(reverse('projects_task_status_add'))
        self.assertEquals(response.status_code, 200)

    def test_task_status_view_login(self):
        """Test index page with login at /projects/task/status/view/<status_id>/"""
        response = self.client.get(reverse('projects_index_by_status', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_status_edit_login(self):
        """Test index page with login at /projects/task/status/edit/<status_id>/"""
        response = self.client.get(reverse('projects_task_status_edit', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    def test_task_status_delete_login(self):
        """Test index page with login at /projects/task/status/delete/<status_id>/"""
        response = self.client.get(reverse('projects_task_status_delete', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    # Settings

    def test_project_settings_view(self):
        """Test index page with login at /projects/settings/view/"""
        response = self.client.get(reverse('projects_settings_view'))
        self.assertEquals(response.status_code, 200)

    def test_project_settings_edit(self):
        """Test index page with login at /projects/settings/edit/"""
        response = self.client.get(reverse('projects_settings_edit'))
        self.assertEquals(response.status_code, 200)
예제 #3
0
class TestModelTaskTimeSlot(TestCase):
    username = "******"
    password = "******"

    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test_group')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()

        self.project = Project(name='test')
        self.project.save()

        self.taskstatus = TaskStatus(name='test')
        self.taskstatus.save()

        self.task = Task(name='test', project=self.project, status=self.taskstatus)
        self.task.save()

        self.time_from = datetime(year=2015, month=8, day=3)
        self.total_time = timedelta(minutes=61)
        self.time_to = self.time_from + self.total_time
        self.timeslot = TaskTimeSlot(task=self.task, user=self.user.profile, time_from=self.time_from,
                                     time_to=self.time_to)
        self.timeslot.save()

    def test_get_absolute_url(self):
        self.timeslot.get_absolute_url()

    def test_get_time_secs(self):
        with freeze_time(datetime(year=2015, month=8, day=4)):
            self.assertEqual(self.timeslot.get_time_secs(), 86400)

    def test_get_time(self):
        """A time slot without a time from or time to will return a delta of 0"""
        timeslot2 = TaskTimeSlot(task=self.task, user=self.user.profile, time_from=self.time_from)
        timeslot3 = TaskTimeSlot(task=self.task, user=self.user.profile, time_to=self.time_to)
        self.assertEqual(timeslot2.get_time(), timedelta(0))
        self.assertEqual(timeslot3.get_time(), timedelta(0))
        self.assertEqual(self.timeslot.get_time(), self.total_time)

    def test_get_time_tuple(self):
        h, m, s = self.timeslot.get_time_tuple()
        self.assertEqual((h, m, s), (1, 1, 0))
        timeslot2 = TaskTimeSlot(task=self.task, user=self.user.profile, time_to=self.time_to)
        self.assertIsNone(timeslot2.get_time_tuple())

    def test_get_time_string(self):
        self.assertEqual(self.timeslot.get_time_string(), ' 1 hours  1 minutes')

        total_time = timedelta(minutes=1)
        self.timeslot.time_to = self.time_from + total_time
        self.assertEqual(self.timeslot.get_time_string(), ' 1 minutes')

        # if it has a timedelta of zero it will use now-time_from
        total_time = timedelta(minutes=0)
        self.timeslot.time_to = self.time_from + total_time
        with freeze_time(datetime(year=2015, month=8, day=4)):
            self.assertEqual(self.timeslot.get_time_string(), '24 hours ')

        total_time = timedelta(seconds=30)
        self.timeslot.time_to = self.time_from + total_time
        self.assertEqual(self.timeslot.get_time_string(), 'Less than 1 minute')

        total_time = timedelta(minutes=60)
        self.timeslot.time_to = self.time_from + total_time
        self.assertEqual(self.timeslot.get_time_string(), ' 1 hours ')

        self.timeslot.time_from = None
        self.assertEqual(self.timeslot.get_time_string(), '')

        self.timeslot.time_from = self.time_from
        self.timeslot.time_to = None
        with freeze_time(datetime(year=2015, month=8, day=4)):
            self.assertEqual(self.timeslot.get_time_string(), '24 hours ')

    def test_is_open(self):
        # a time slot with both time_from and time_to means it is closed
        self.assertFalse(self.timeslot.is_open())
        self.timeslot.time_to = None
        self.assertTrue(self.timeslot.is_open())
예제 #4
0
 def test_model_milestone(self):
     tstatus = TaskStatus(name='test')
     tstatus.save()
     mstone = Milestone(project=self.project, status=tstatus)
     mstone.save()
     mstone.get_absolute_url()
예제 #5
0
class ProjectsModelsTest(TestCase):
    """ Documents models tests"""
    def setUp(self):
        self.project = Project(name='test')
        self.project.save()

        self.taskstatus = TaskStatus(name='test')
        self.taskstatus.save()

        self.task = Task(name='test', project=self.project, status=self.taskstatus)
        self.task.save()

    def test_task_priority_human(self):
        """Default priority should be 3, text representation should be 'Normal'
        """
        self.assertEqual(self.task.priority, 3)
        self.assertEqual(self.task.priority_human(), 'Normal')

    def test_get_estimated_time_default(self):
        """Default estimated time is None, string representation is empty string """
        self.assertIsNone(self.task.estimated_time)
        self.assertEqual(self.task.get_estimated_time(), '')

    def test_get_estimated_time_one_min(self):
        self.task.estimated_time = 1
        self.assertEqual(self.task.get_estimated_time(), ' 1 minutes')

    def test_get_estimated_time_zero_min(self):
        self.task.estimated_time = 0
        self.assertEqual(self.task.get_estimated_time(), 'Less than 1 minute')

    def test_get_estimated_time_60_min(self):
        self.task.estimated_time = 60
        self.assertEqual(self.task.get_estimated_time(), ' 1 hours ')

    def test_get_estimated_time_61_min(self):
        self.task.estimated_time = 61
        self.assertEqual(self.task.get_estimated_time(), ' 1 hours  1 minutes')

    def test_model_task_get_absolute_url(self):
        self.task.get_absolute_url()

    # def test_save TODO: save is overridden and has some extra logic

    def test_get_absolute_url(self):
        """Test if get_absolute_url works without raising any exception"""
        self.project.get_absolute_url()

    def add_time_slot(self, total_time):
        duser, created = DjangoUser.objects.get_or_create(username='******')
        time_from = datetime(year=2015, month=8, day=3)
        time_to = time_from + total_time
        timeslot = TaskTimeSlot(task=self.task, user=duser.profile, time_from=time_from, time_to=time_to)
        timeslot.save()

    def test_get_total_time_default(self):
        self.assertEqual(self.task.get_total_time(), timedelta())

    def test_get_total_time_with_timeslots1(self):
        total_time = timedelta(hours=3)
        self.add_time_slot(total_time)
        self.assertEqual(self.task.get_total_time(), total_time)

    def test_get_total_time_tuple_default(self):
        self.assertIsNone(self.task.get_total_time_tuple())

    def test_get_total_time_tuple(self):
        total_time = timedelta(hours=3)
        self.add_time_slot(total_time)
        h, m, s = self.task.get_total_time_tuple()
        self.assertEqual((h, m, s), (3, 0, 0))

    def test_get_total_time_string_default(self):
        self.assertEqual(self.task.get_total_time_string(), '0 minutes')

    def test_get_total_time_string_one_min(self):
        total_time = timedelta(minutes=1)
        self.add_time_slot(total_time)
        self.assertEqual(self.task.get_total_time_string(), ' 1 minutes')

    def test_get_total_time_string_zero_min(self):
        total_time = timedelta(minutes=0)
        self.add_time_slot(total_time)
        self.assertEqual(self.task.get_total_time_string(), '0 minutes')

    def test_get_total_time_string_30_secs(self):
        total_time = timedelta(seconds=30)
        self.add_time_slot(total_time)
        self.assertEqual(self.task.get_total_time_string(), 'Less than 1 minute')

    def test_get_total_time_string_60_min(self):
        total_time = timedelta(minutes=60)
        self.add_time_slot(total_time)
        self.assertEqual(self.task.get_total_time_string(), ' 1 hours ')

    def test_get_total_time_string_61_min(self):
        total_time = timedelta(minutes=61)
        self.add_time_slot(total_time)
        self.assertEqual(self.task.get_total_time_string(), ' 1 hours  1 minutes')

    def test_is_being_done_by(self):
        duser, created = DjangoUser.objects.get_or_create(username='******')
        self.assertFalse(self.task.is_being_done_by(duser.profile))

        time_from = datetime(year=2015, month=8, day=3)
        timeslot = TaskTimeSlot(task=self.task, user=duser.profile, time_from=time_from)
        timeslot.save()
        self.task.save()

        self.assertTrue(self.task.is_being_done_by(duser.profile))

    def test_model_task_status(self):
        """Test task status"""
        obj = TaskStatus(name='test')
        obj.save()
        self.assertEquals('test', obj.name)
        self.assertNotEquals(obj.id, None)
        obj.get_absolute_url()
        obj.delete()

    def test_model_milestone(self):
        tstatus = TaskStatus(name='test')
        tstatus.save()
        mstone = Milestone(project=self.project, status=tstatus)
        mstone.save()
        mstone.get_absolute_url()