Example #1
0
def test_time_period_friendly_name(self, fixture):

    start_date = helpers.parse_isodate(fixture.start)
    relative = helpers.parse_isodate(fixture.relative)

    tp = TimePeriod(fixture.resolution, 0, start_date)
    got = tp._friendly_date_relative_to(relative)
    self.assertEqual(fixture.expected, got)
Example #2
0
def test_time_period_from_index(self, fixture):
    start, when, resolution, result, date = fixture

    start_date = helpers.parse_isodate(start)
    when_date  = helpers.parse_isodate(when)

    if result is not throws:
        tp_date = helpers.parse_isodate(date)
        exp = TimePeriod(resolution, result, tp_date)
        self.assertEqual(TimePeriod.from_index(start_date, resolution, result), exp)
Example #3
0
def test_time_period_from_date(self, fixture):
    start, when, resolution, result, date = fixture

    start_date = helpers.parse_isodate(start)
    when_date  = helpers.parse_isodate(when)

    if result is throws:
        with self.assertRaises(ValueError):
            TimePeriod.from_date(start_date, resolution, when_date)
    else:
        tp_date = helpers.parse_isodate(date)
        exp = TimePeriod(resolution, result, tp_date)
        self.assertEqual(TimePeriod.from_date(start_date, resolution, when_date), exp)
Example #4
0
def test_get_streaks(self, fixture):
    start, resolution, target_value = fixture.habit
    start_date = helpers.parse_isodate(start)
    h = Habit.objects.create(description="Foo my bar",
                             start=start_date,
                             user=self.user,
                             resolution=resolution,
                             target_value=target_value)

    for datum in fixture.data:
        when, value = datum
        when_date = helpers.parse_isodate(when)
        tp = h.get_time_period(when_date)
        h.record(tp, value)

    self.assertEqual(list(h.get_streaks()), fixture.streaks)
Example #5
0
def _test_provider(self, fixture):
    start, resolution = fixture.habit
    start_date = helpers.parse_isodate(start)

    hab = Habit.objects.create(
        description="Go for a walk", start=start_date, user=self.user, resolution=resolution, target_value=3
    )

    for time_period, value in fixture.data:
        when = helpers.parse_isodate(time_period)
        hab.record(hab.get_time_period(when), value)

    periods = fixture.func(hab)
    if fixture.expects_none:
        self.assertIsNone(periods)
    else:
        self.assertIsNotNone(periods)
Example #6
0
def test_recent_unentered_time_periods(self, fixture):
    # start, resolution, data, date, expected = fixture
    start_date = helpers.parse_isodate(fixture.start)
    h = Habit.objects.create(description="Tangle my wobble",
                             start=start_date,
                             user=self.user,
                             resolution=fixture.resolution,
                             target_value=1)

    for datum in fixture.data:
        when, value = datum
        when_date = helpers.parse_isodate(when)
        tp = h.get_time_period(when_date)
        h.record(tp, value)


    periods = h.get_unentered_time_periods(helpers.parse_isodate(fixture.date))
    self.assertEquals(map(lambda p: p.index, periods), fixture.expected)
Example #7
0
def _test_provider(self, fixture):
    start, resolution = fixture.habit
    start_date = helpers.parse_isodate(start)

    hab = Habit.objects.create(description="Go for a walk",
                               start=start_date,
                               user=self.user,
                               resolution=resolution,
                               target_value=3)

    for time_period, value in fixture.data:
        when = helpers.parse_isodate(time_period)
        hab.record(hab.get_time_period(when), value)

    periods = fixture.func(hab)
    if fixture.expects_none:
        self.assertIsNone(periods)
    else:
        self.assertIsNotNone(periods)
Example #8
0
def test_record(self, fixture):
    start_date = helpers.parse_isodate(fixture.start)
    h = Habit.objects.create(description="Brush my teeth",
                             start=start_date,
                             user=self.user,
                             resolution=fixture.resolution)

    for datum in fixture.data:
        when, value = datum
        when_date = helpers.parse_isodate(when)
        tp = h.get_time_period(when_date)
        h.record(tp, value)

    for check in fixture.checks:
        # Assert the bucket does not exist
        if check.value is None:
            buckets = h.buckets.filter(resolution=check.resolution,
                                       index=check.index)
            self.assertEqual(buckets.count(), 0)
        else:
            bucket = h.buckets.get(resolution=check.resolution,
                                   index=check.index)
            self.assertEqual(bucket.value, check.value)
Example #9
0
def test_send_data_collection_email(self, fixture):
    resolution, today, should_send = fixture
    today_date = helpers.parse_isodate(today)

    self.h.resolution = resolution
    result = send_data_collection_email(self.h, today=today_date)

    if should_send:
        self.assertIsNotNone(result)
        self.assertEqual(len(mail.outbox), 1)
        self.assertTrue('Let us know' in mail.outbox[0].subject)
    else:
        self.assertIsNone(result)
        self.assertEqual(len(mail.outbox), 0)
Example #10
0
def test_send_data_collection_email(self, fixture):
    resolution, today, should_send = fixture
    today_date = helpers.parse_isodate(today)

    self.h.resolution = resolution
    result = send_data_collection_email(self.h, today=today_date)

    if should_send:
        self.assertIsNotNone(result)
        self.assertEqual(len(mail.outbox), 1)
        self.assertTrue('Let us know' in mail.outbox[0].subject)
    else:
        self.assertIsNone(result)
        self.assertEqual(len(mail.outbox), 0)