Ejemplo n.º 1
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)

helpers.attach_fixture_tests(TimePeriodTests, test_time_period_from_date, TIME_PERIOD_FIXTURES)

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)

helpers.attach_fixture_tests(TimePeriodTests, test_time_period_from_index, TIME_PERIOD_FIXTURES)

def test_time_period_friendly_name(self, fixture):
Ejemplo n.º 2
0
        send_reminder_email(self.h)

        self.assertEqual(len(mail.outbox), 1)
        self.assertTrue('Frobble your wingdangle' in mail.outbox[0].subject)

    def test_disable_send_data_collection_email(self):
        self.h.send_data_collection_emails = False

        result = send_data_collection_email(self.h)

        self.assertIsNone(result)
        self.assertEqual(len(mail.outbox), 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)

helpers.attach_fixture_tests(TestReminders, test_send_data_collection_email, DATA_COLLECTION_FIXTURES)
Ejemplo n.º 3
0
        self.assertIsNone(result)
        self.assertEqual(len(mail.outbox), 0)

    def test_send_data_collection_email_for_archived_habit(self):
        self.h.archived = True

        result = send_data_collection_email(self.h)

        self.assertIsNone(result)
        self.assertEqual(len(mail.outbox), 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)


helpers.attach_fixture_tests(TestReminders, test_send_data_collection_email,
                             DATA_COLLECTION_FIXTURES)
Ejemplo n.º 4
0
       data=(('2013-03-01', 3), ('2013-03-05', 3), ('2013-03-13', 0),
             ('2013-03-20', 1), ('2013-04-03', 3)),
       expects_none=True),
    PF(func=longest_streak_nonzero,
       habit=('2013-03-01', 'week'),
       data=(('2013-03-01', 2), ('2013-03-08', 3), ('2013-03-15', 0),
             ('2013-03-22', 1), ('2013-03-29', 3)),
       expects_none=True),
)


def test_longest_streak(self, fixture):
    _test_provider(self, fixture)


helpers.attach_fixture_tests(TestProviders, test_longest_streak,
                             STREAK_FIXTURES)

BEST_EVER_FIXTURES = (
    PF(func=best_day_ever,
       habit=('2013-03-04', 'day'),
       data=(('2013-03-04', 0), ),
       expects_none=True),
    # Not your "best day ever" if it's your first ever day
    PF(func=best_day_ever,
       habit=('2013-03-04', 'day'),
       data=(('2013-03-04', 1), ),
       expects_none=True),
    PF(func=best_day_ever,
       habit=('2013-03-04', 'day'),
       data=(('2013-03-04', 1), ('2013-03-05', 0)),
       expects_none=True),
Ejemplo n.º 5
0
        expects_none=True,
    ),
    PF(
        func=longest_streak_nonzero,
        habit=("2013-03-01", "week"),
        data=(("2013-03-01", 2), ("2013-03-08", 3), ("2013-03-15", 0), ("2013-03-22", 1), ("2013-03-29", 3)),
        expects_none=True,
    ),
)


def test_longest_streak(self, fixture):
    _test_provider(self, fixture)


helpers.attach_fixture_tests(TestProviders, test_longest_streak, STREAK_FIXTURES)


BEST_EVER_FIXTURES = (
    PF(func=best_day_ever, habit=("2013-03-04", "day"), data=(("2013-03-04", 0),), expects_none=True),
    # Not your "best day ever" if it's your first ever day
    PF(func=best_day_ever, habit=("2013-03-04", "day"), data=(("2013-03-04", 1),), expects_none=True),
    PF(func=best_day_ever, habit=("2013-03-04", "day"), data=(("2013-03-04", 1), ("2013-03-05", 0)), expects_none=True),
    PF(func=best_day_ever, habit=("2013-03-04", "day"), data=(("2013-03-04", 1), ("2013-03-05", 1)), expects_none=True),
    PF(
        func=best_day_ever, habit=("2013-03-04", "day"), data=(("2013-03-04", 1), ("2013-03-05", 2)), expects_none=False
    ),
    PF(
        func=best_day_ever,
        habit=("2013-03-04", "day"),
        data=(("2013-03-04", 1), ("2013-03-05", 0), ("2013-03-06", 2)),