Пример #1
0
 def test_approved(self):
     start = utils.add_timezone(datetime.datetime(2011, 1, 1, 8))
     end = utils.add_timezone(datetime.datetime(2011, 1, 1, 12))
     unapproved_entry_a = factories.Entry(
         user=self.user,
         project=self.project_non_billable,
         start_time=start + relativedelta(hours=11),
         end_time=end + relativedelta(hours=15),
         status=Entry.VERIFIED)
     unapproved_entry_b = factories.Entry(
         user=self.user,
         project=self.project_non_billable,
         start_time=start + relativedelta(hours=11),
         end_time=end + relativedelta(hours=15),
         status=Entry.VERIFIED)
     response = self._get()
     self.assertEquals(response.status_code, 200)
     form = response.context['form']
     self.assertTrue(form.is_valid(), form.errors)
     unverified = set(response.context['unverified'])
     unapproved = set(response.context['unapproved'])
     user_a, user_b = unapproved_entry_a.user, unapproved_entry_b.user
     expected_unapproved = set([
         (user_a.pk, user_a.first_name, user_a.last_name),
         (user_b.pk, user_b.first_name, user_b.last_name),
     ])
     self.assertEquals(unverified, set())
     self.assertEquals(unapproved, expected_unapproved)
Пример #2
0
    def testRoundingConversions(self):
        """
        Verify that entries (which are in seconds) approximate a correct hourly value
        once each decimal conversion per entry is summed.
        """
        xtime = timezone.now() - relativedelta(minutes=10)
        factories.Entry(
            **{
                'user': self.superuser,
                'project': self.p2,
                'start_time': xtime,
                'end_time': xtime + relativedelta(seconds=29)
            })
        factories.Entry(
            **{
                'user': self.superuser,
                'project': self.p2,
                'start_time': xtime + relativedelta(seconds=30),
                'end_time': xtime + relativedelta(seconds=60)
            })

        self.login_user(self.superuser)
        response = self._get(url_args=(self.p2.pk, ))
        entries = response.context['entries']
        self.assertEqual(len(entries), 2)
        self.assertAlmostEqual(sum(Decimal(e['hours']) for e in entries),
                               Decimal(0.016),
                               places=2)
Пример #3
0
    def setUp(self):
        super(ListOutstandingInvoicesViewTestCase, self).setUp()
        self.user = factories.Superuser()
        self.login_user(self.user)

        start = utils.add_timezone(datetime.datetime(2011, 1, 1, 8))
        end = utils.add_timezone(datetime.datetime(2011, 1, 1, 12))

        self.project_billable = factories.BillableProject()
        self.project_billable2 = factories.BillableProject()
        self.project_non_billable = factories.NonbillableProject()

        self.entry1 = factories.Entry(
            user=self.user,
            project=self.project_billable,
            activity=factories.Activity(billable=True),
            start_time=start,
            end_time=end,
            status=Entry.APPROVED)
        self.entry2 = factories.Entry(
            user=self.user,
            project=self.project_billable,
            activity=factories.Activity(billable=True),
            start_time=start - relativedelta(days=5),
            end_time=end - relativedelta(days=5),
            status=Entry.APPROVED)
        self.entry3 = factories.Entry(
            user=self.user,
            project=self.project_billable2,
            activity=factories.Activity(billable=False),
            start_time=start - relativedelta(days=10),
            end_time=end - relativedelta(days=10),
            status=Entry.APPROVED)
        self.entry4 = factories.Entry(user=self.user,
                                      project=self.project_non_billable,
                                      start_time=start +
                                      relativedelta(hours=11),
                                      end_time=end + relativedelta(hours=15),
                                      status=Entry.APPROVED)

        # Default get kwargs.
        self.to_date = utils.add_timezone(
            datetime.datetime(2011, 1, 31, 0, 0, 0))
        self.get_kwargs = {
            'to_date': self.to_date.strftime(DATE_FORM_FORMAT),
            'statuses': list(Attribute.statuses.values_list('pk', flat=True)),
        }
Пример #4
0
 def _create_entries(self):
     for start_time in (self.weeks[1], self.weeks[3]):
         for user in (self.users[1], self.users[2]):
             end_time = start_time + relativedelta(hours=2)
             data = {
                 'user': user,
                 'start_time': start_time,
                 'end_time': end_time,
                 'project': self.project
             }
             factories.Entry(**data)
Пример #5
0
 def _create_entry(self, start_time, end_time=None, project=None):
     data = {
         'user': self.user,
         'project': project or self.project,
         'activity': self.activity,
         'location': self.location,
         'status': self.status,
         'start_time': start_time,
     }
     if end_time:
         data['end_time'] = end_time
     return factories.Entry(**data)
Пример #6
0
 def setUp(self):
     super(InvoiceCreateTestCase, self).setUp()
     self.user = factories.Superuser()
     self.login_user(self.user)
     start = utils.add_timezone(datetime.datetime(2011, 1, 1, 8))
     end = utils.add_timezone(datetime.datetime(2011, 1, 1, 12))
     self.project_billable = factories.BillableProject()
     self.project_billable2 = factories.BillableProject()
     self.project_non_billable = factories.NonbillableProject()
     self.entry1 = factories.Entry(
         user=self.user,
         project=self.project_billable,
         activity=factories.Activity(billable=True),
         start_time=start,
         end_time=end,
         status=Entry.APPROVED)
     self.entry2 = factories.Entry(
         user=self.user,
         project=self.project_billable,
         activity=factories.Activity(billable=True),
         start_time=start - relativedelta(days=5),
         end_time=end - relativedelta(days=5),
         status=Entry.APPROVED)
     self.entry3 = factories.Entry(
         user=self.user,
         project=self.project_billable2,
         activity=factories.Activity(billable=False),
         start_time=start - relativedelta(days=10),
         end_time=end - relativedelta(days=10),
         status=Entry.APPROVED)
     self.entry4 = factories.Entry(user=self.user,
                                   project=self.project_non_billable,
                                   start_time=start +
                                   relativedelta(hours=11),
                                   end_time=end + relativedelta(hours=15),
                                   status=Entry.APPROVED)
Пример #7
0
 def _create_entry(self, start_time, end_time=None, user=None):
     """
     Creates an entry using default values. If end time is not given, the
     entry is considered active.
     """
     data = {
         'user': user or self.user,
         'project': self.project,
         'activity': self.activity,
         'location': self.location,
         'status': self.status,
         'start_time': start_time,
     }
     if end_time:
         data['end_time'] = end_time
     return factories.Entry(**data)
Пример #8
0
 def test_unverified(self):
     start = utils.add_timezone(datetime.datetime(2011, 1, 1, 8))
     end = utils.add_timezone(datetime.datetime(2011, 1, 1, 12))
     factories.Entry(user=self.user,
                     project=self.project_non_billable,
                     start_time=start + relativedelta(hours=11),
                     end_time=end + relativedelta(hours=15),
                     status=Entry.UNVERIFIED)  # unverified
     response = self._get()
     self.assertEquals(response.status_code, 200)
     form = response.context['form']
     self.assertTrue(form.is_valid(), form.errors)
     unverified = list(response.context['unverified'])
     unapproved = list(response.context['unapproved'])
     expected_unverified = [(self.user.pk, self.user.first_name,
                             self.user.last_name)]
     self.assertEquals(unverified, expected_unverified)
     self.assertEquals(unapproved, [])
Пример #9
0
 def test_invoice_confirm_totals(self):
     """Verify that the per activity totals are valid."""
     ACTIVITY_NAME = 'activity_n'
     # Make a few extra entries to test per activity totals
     start = utils.add_timezone(datetime.datetime(2011, 1, 1, 8))
     end = utils.add_timezone(datetime.datetime(2011, 1, 1, 12))
     # start = utils.add_timezone(datetime.datetime.now())
     # end = start + relativedelta(hours=4)
     activity = factories.Activity(billable=True, name=ACTIVITY_NAME)
     for num in range(0, 4):
         factories.Entry(user=self.user,
                         project=self.project_billable,
                         start_time=start - relativedelta(days=num),
                         end_time=end - relativedelta(days=num),
                         status=Entry.APPROVED,
                         activity=activity)
     self.make_hourgroups()
     to_date = datetime.datetime(2011, 1, 31)
     kwargs = {
         'project': self.project_billable.id,
         'to_date': to_date.strftime(DATE_FORM_FORMAT),
     }
     url = self.get_create_url(**kwargs)
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
     for name, hours_activities in response.context['billable_totals']:
         total, activities = hours_activities
         if name == ACTIVITY_NAME:
             self.assertEqual(total, 16)
             self.assertEqual(total, activities[0][1])
             self.assertEqual(name, activities[0][0])
         elif name == 'Total':
             self.assertEqual(total, 24)
             self.assertEqual(activities, [])
         else:
             # Each other activity is 4 hrs each
             self.assertEqual(total, 4)
             self.assertEqual(total, activities[0][1])
             self.assertEqual(name, activities[0][0])
Пример #10
0
    def test_invoice_confirm_rounding(self):
        """Verify that the per activity totals are rounded correctly."""
        ACTIVITY_NAME = 'activity_n'
        # Make a few extra entries to test per activity totals
        start = utils.add_timezone(datetime.datetime(2011, 1, 1, 8, 0, 0))
        end = utils.add_timezone(datetime.datetime(2011, 1, 1, 8, 3, 1))
        # 3m1s = 0.05166667h
        # 0.05166667 rounds to 0.05, at two decimal places
        # 0.05 * 5 = 0.25
        # 0.05166667 * 5 = 0.25833335
        # 0.25833335 rounds to 0.26, at two decimal places
        # If rounding happens before summation, then the total will be 0.25
        # If rounding happens after summation, then the total will be 0.26

        activity = factories.Activity(billable=True, name=ACTIVITY_NAME)
        for num in range(0, 5):
            factories.Entry(user=self.user,
                            project=self.project_billable,
                            start_time=start - relativedelta(days=num),
                            end_time=end - relativedelta(days=num),
                            status=Entry.APPROVED,
                            activity=activity)
        self.make_hourgroups()
        to_date = datetime.datetime(2011, 1, 31)
        kwargs = {
            'project': self.project_billable.id,
            'to_date': to_date.strftime(DATE_FORM_FORMAT),
        }
        url = self.get_create_url(**kwargs)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        for name, hours_activities in response.context['billable_totals']:
            total, activities = hours_activities
            if name == ACTIVITY_NAME:
                self.assertEqual(total, 0.25)
                self.assertNotAlmostEqual(float(total), 0.26, places=2)
Пример #11
0
    def setUp(self):
        super(ProjectContractEntryTestCase, self).setUp()
        self.user_a = factories.User(username='******')
        self.user_b = factories.User(username='******')
        self.project_a = factories.Project(type__enable_timetracking=True,
                                           status__enable_timetracking=True,
                                           name='Project A')
        self.project_b = factories.Project(type__enable_timetracking=True,
                                           status__enable_timetracking=True,
                                           name='Project B')

        self.contract1 = factories.ProjectContract(
            name='Contract 1',
            projects=[self.project_a, self.project_b],
            status=ProjectContract.STATUS_CURRENT,
            start_date=timezone.now().replace(
                hour=0, minute=0, second=0, microsecond=0) -
            relativedelta(days=16),
            end_date=timezone.now().replace(
                hour=0, minute=0, second=0, microsecond=0) -
            relativedelta(days=12),
        )

        self.contract2 = factories.ProjectContract(
            name='Contract 2',
            projects=[self.project_b],
            status=ProjectContract.STATUS_CURRENT,
            start_date=timezone.now().replace(
                hour=0, minute=0, second=0, microsecond=0) -
            relativedelta(days=8),
            end_date=timezone.now().replace(
                hour=0, minute=0, second=0, microsecond=0) -
            relativedelta(days=4),
        )

        for x in range(20):
            factories.Entry(
                **{
                    'user':
                    self.user_a,
                    'project':
                    self.project_a,
                    'start_time':
                    timezone.now() - relativedelta(days=x),
                    'end_time': (timezone.now() - relativedelta(days=x)) +
                    relativedelta(hours=1),
                    'seconds_paused':
                    0,
                    'status':
                    Entry.UNVERIFIED,
                })

            factories.Entry(
                **{
                    'user':
                    self.user_b,
                    'project':
                    self.project_b,
                    'start_time':
                    timezone.now() - relativedelta(days=x),
                    'end_time': (timezone.now() - relativedelta(days=x)) +
                    relativedelta(hours=1),
                    'seconds_paused':
                    0,
                    'status':
                    Entry.UNVERIFIED,
                })