Beispiel #1
0
    def test_new(self, new_step_signal):
        text = uuid4()
        response = self.client.post(reverse('app_steps_new',
                                            kwargs={'goal_id': self.goal.id}),
                                    data={'text': text},
                                    follow=False)

        step = Step.objects.get(text=text)

        self.assertRedirects(
            response,
            reverse('app_steps_start',
                    kwargs={
                        'goal_id': self.goal.id,
                        'step_id': step.id
                    }))

        self.assertIsNotNone(step)
        self.assertEquals(self.goal.id, step.goal.id)

        self.assertAlmostEquals(step.start,
                                timezone.now(),
                                delta=timedelta(seconds=2))

        local_start = step.start.astimezone(self.tz)
        local_end = step.end.astimezone(self.tz)
        self.assertEquals(step.end, Step.deadline(step.start, self.tz))
        self.assertEquals((local_start + timedelta(days=2)).date(),
                          local_end.date())
        self.assertEquals(local_end.time(), time())

        new_step_signal.send.assert_called_with('app.views.steps.new',
                                                step=step)
Beispiel #2
0
    def test_deadline(self):
        # Hong Kong UTC+8 - doesn't observe DST
        tz = pytz.timezone('Asia/Hong_Kong')

        start = tz.localize(datetime.utcnow())

        deadline = Step.deadline(start, 'Asia/Hong_Kong')

        self.assertTrue(is_aware(deadline))
        self.assertEquals(deadline.tzinfo, pytz.utc)

        local_deadline = deadline.astimezone(tz)
        print(deadline, local_deadline)
        self.assertEquals(start.date() + timedelta(days=2),
                          local_deadline.date())
        self.assertEquals(local_deadline.time(), time())
Beispiel #3
0
    def test_new(self, new_step, new_goal):
        text = uuid1()
        response = self.client.post(reverse('app_goals_new'), data={
            'text': text,
            'first_step': 'step text',
            'timezone': 'Europe/London'
        }, follow=False)

        goal = Goal.objects.get(text=text)
        tz = pytz.timezone('Europe/London')

        self.assertEquals(len(goal.steps.all()), 1)

        self.assertRedirects(response, reverse('app_steps_start', kwargs={
            'goal_id': goal.id, 'step_id': goal.steps.first().id}))

        self.assertIsNotNone(goal)
        self.assertEquals(goal.lives, 3)
        self.assertEquals(self.user.id, goal.user.id)
        self.assertEquals(goal.timezone, 'Europe/London')
        self.assertAlmostEquals(goal.start, timezone.now(),
                                delta=timedelta(seconds=1))

        first_step = goal.steps.first()
        self.assertEquals(first_step.text, 'step text')
        self.assertEquals(first_step.start, goal.start)

        local_start = first_step.start.astimezone(tz)
        local_end = first_step.end.astimezone(tz)
        self.assertEquals(first_step.end, Step.deadline(first_step.start, tz))
        self.assertEquals((local_start + timedelta(days=2)).date(),
                          local_end.date())
        self.assertEquals(local_end.time(), time())

        new_goal.send.assert_called_with('app.views.goals.new',
                                         goal=goal)
        new_step.send.assert_called_with('app.views.goals.new',
                                         step=first_step)