Esempio n. 1
0
    def test_get_query_empty(self):
        """
        Tests whether a query with no associated project searches the entire
        set of activities, regardless of project.
        """
        activity1 = factories.Activity(name='foo')
        activity2 = factories.Activity(name='bar')
        activity3 = factories.Activity(name='baz')
        activity4 = factories.Activity(name='qux')

        activity_group1 = factories.ActivityGroup()
        activity_group1.activities.add(activity1)
        activity_group1.activities.add(activity2)

        activity_group2 = factories.ActivityGroup()
        activity_group2.activities.add(activity3)
        activity_group2.activities.add(activity4)

        request = RequestFactory().get('/selectable/entries-activitylookup',
                                       {'project': ''})

        data = self.lookup.get_query(request, '')

        self.assertIn(activity1, data)
        self.assertIn(activity2, data)
        self.assertIn(activity3, data)
        self.assertIn(activity4, data)

        data = self.lookup.get_query(request, 'a')

        self.assertNotIn(activity1, data)
        self.assertIn(activity2, data)
        self.assertIn(activity3, data)
        self.assertNotIn(activity4, data)
    def setUp(self):
        self.user = factories.User()
        permissions = Permission.objects.filter(
            content_type=ContentType.objects.get_for_model(Entry),
            codename__in=('can_clock_in', 'can_clock_out', 'can_pause',
                          'change_entry'))
        self.user.user_permissions = permissions
        self.user.save()
        self.superuser = factories.Superuser()

        self.tracked_status = factories.StatusAttribute(
            label='Current', billable=True, enable_timetracking=True)
        self.untracked_status = factories.StatusAttribute(
            label='Closed', billable=False, enable_timetracking=False)
        self.tracked_type = factories.TypeAttribute(label='Tracked',
                                                    billable=True,
                                                    enable_timetracking=True)
        self.untracked_type = factories.TypeAttribute(
            label='Untracked', billable=False, enable_timetracking=False)

        self.work_activities = factories.ActivityGroup(name='Work')
        self.leave_activities = factories.ActivityGroup(name='Leave')
        self.all_activities = factories.ActivityGroup(name='All')

        self.leave_activity = factories.Activity(code='leave',
                                                 name='Leave',
                                                 billable=False)
        self.leave_activity.activity_group.add(self.leave_activities,
                                               self.all_activities)
        self.work_activity = factories.Activity(code='work',
                                                name='Work',
                                                billable=True)
        self.work_activity.activity_group.add(self.work_activities,
                                              self.all_activities)

        data = {
            'type': self.tracked_type,
            'status': self.tracked_status,
            'activity_group': self.work_activities,
        }
        self.tracked_project = factories.BillableProject(name='Tracked',
                                                         **data)
        data = {
            'type': self.untracked_type,
            'status': self.untracked_status,
            'activity_group': self.all_activities,
        }
        self.untracked_project = factories.BillableProject(name='Untracked',
                                                           **data)
Esempio n. 3
0
    def test_get_query(self):
        """
        Tests whether we get the right results with a non-empty query.
        """
        activity1 = factories.Activity(name='foo')
        activity2 = factories.Activity(name='bar')
        activity3 = factories.Activity(name='baz')
        activity4 = factories.Activity(name='qux')

        activity_group = factories.ActivityGroup()
        activity_group.activities.add(activity1)
        activity_group.activities.add(activity2)
        activity_group.activities.add(activity3)
        activity_group.activities.add(activity4)

        project = factories.Project(activity_group=activity_group)

        request = RequestFactory().get('/selectable/entries-activitylookup',
                                       {'project': project.pk})

        data = self.lookup.get_query(request, 'a')

        self.assertNotIn(activity1, data)
        self.assertIn(activity2, data)
        self.assertIn(activity3, data)
        self.assertNotIn(activity4, data)
Esempio n. 4
0
 def setUp(self):
     super(TestCreateProject, self).setUp()
     self.user = factories.User(permissions=self.permissions)
     self.login_user(self.user)
     self.post_data = {
         'name': 'Project',
         'business_1': factories.Business().pk,
         'point_person': factories.Superuser().pk,
         'activity_group': factories.ActivityGroup().pk,
         'type': factories.TypeAttribute().pk,
         'status': factories.StatusAttribute().pk,
         'description': 'a project...',
     }
    def setUp(self):
        self.permissions = [Permission.objects.get(codename='add_project')]
        self.user = factories.User(permissions=self.permissions)
        self.login_user(self.user)

        self.post_data = {
            'name': 'Project',
            'business_1': factories.Business().pk,
            'point_person': factories.Superuser().pk,
            'activity_group': factories.ActivityGroup().pk,
            'type': factories.TypeAttribute().pk,
            'status': factories.StatusAttribute().pk,
            'description': 'a project...',
        }
Esempio n. 6
0
 def test_clock_in_form_activity_lookup(self):
     """Create an ActivityGroup that includes the Activity, and associate it with the project.
     Add a second Activity that is not included.  Ensure that the ActivityLookup disallows
     the second Activity. """
     factory = RequestFactory()
     lookup = ActivityLookup()
     factories.Activity()
     activity_group = factories.ActivityGroup()
     activity_group.activities.add(self.activity)
     project2 = factories.Project(activity_group=activity_group)
     factories.ProjectRelationship(project=project2, user=self.user)
     request = factory.get("/entry/clock_in/", {'project': project2.pk})
     response = lookup.results(request)
     data = json.loads(response.content.decode("utf-8"))['data']
     self.assertEqual(1, len(data))
     self.assertEqual(self.activity.pk, data[0]['id'])