# Path: radioco/apps/radioco/test_utils.py
# class TestDataMixin(object):
#     @classmethod
#     def setUpTestData(cls):
#         create_test_data()
#         cls.programme = Programme.objects.filter(name="Classic hits").get()
#         cls.schedule = cls.programme.schedule_set.first()
#         cls.calendar = cls.schedule.calendar
#         cls.episode = cls.programme.episode_set.first()
#         cls.another_calendar = Calendar.objects.create(name="Another")
# 
#         schedule, created = Schedule.objects.get_or_create(
#             programme=cls.programme,
#             calendar=cls.another_calendar,
#             type='S',
#             start_dt=pytz.utc.localize(datetime.datetime(2015, 1, 6, 16, 30, 0)))
# 
# Path: radioco/apps/radioco/tz_utils.py
# def recurrence_after(recurrence, after_dt, start_dt):
#     """
#     Fix for django-recurrence 1.3
#     Avoid outputting a impossible dt
#     """
#     dt = recurrence.after(after_dt, True, dtstart=start_dt)
#     if dt == start_dt:
#         return _fix_invalid_dt(recurrence, dt)
#     return dt
# 
# def recurrence_before(recurrence, before_dt, start_dt):
#     """
#     Fix for django-recurrence 1.3
#     Avoid outputting a impossible dt
#     """
#     dt = recurrence.before(before_dt, True, dtstart=start_dt)
#     if dt == start_dt:
#         return _fix_invalid_dt(recurrence, dt)
#     return dt


import datetime
import recurrence
from django.test import TestCase
from radioco.apps.radioco.test_utils import TestDataMixin
from radioco.apps.radioco.tz_utils import recurrence_after, recurrence_before

    def test_impossible_recurrence_after(self):
        """
        Testing error calling after and function wrapper to solve it (recurrence_after)
        """
        start_dt = datetime.datetime(2014, 1, 20, 14, 0, 0)
        until_dt = datetime.datetime(2014, 1, 19, 14, 0, 0)
        daily_recurrence = recurrence.Recurrence(
            rrules=[recurrence.Rule(recurrence.DAILY, until=until_dt)])

        dt = daily_recurrence.after(start_dt, True, dtstart=start_dt)
        self.assertEqual(start_dt, dt)  # wrong!

        self.assertIsNone(recurrence_after(daily_recurrence, start_dt, start_dt))

    def test_impossible_recurrence_before(self):
        """
        Testing error calling before and function wrapper to solve it (recurrence_before)
        """
        start_dt = datetime.datetime(2014, 1, 20, 14, 0, 0)
        until_dt = datetime.datetime(2014, 1, 19, 14, 0, 0)
        daily_recurrence = recurrence.Recurrence(
            rrules=[recurrence.Rule(recurrence.MONTHLY, until=until_dt)])

        dt = daily_recurrence.before(start_dt + datetime.timedelta(seconds=1), dtstart=start_dt)
        self.assertEqual(start_dt, dt)  # wrong!

        self.assertIsNone(recurrence_before(daily_recurrence, start_dt + datetime.timedelta(seconds=1), start_dt))



# Path: radioco/apps/radioco/test_utils.py
# class TestDataMixin(object):
#     @classmethod
#     def setUpTestData(cls):
#         create_test_data()
#         cls.programme = Programme.objects.filter(name="Classic hits").get()
#         cls.schedule = cls.programme.schedule_set.first()
#         cls.calendar = cls.schedule.calendar
#         cls.episode = cls.programme.episode_set.first()
#         cls.another_calendar = Calendar.objects.create(name="Another")
# 
#         schedule, created = Schedule.objects.get_or_create(
#             programme=cls.programme,
#             calendar=cls.another_calendar,
#             type='S',
#             start_dt=pytz.utc.localize(datetime.datetime(2015, 1, 6, 16, 30, 0)))
# 
# Path: radioco/apps/radioco/tz_utils.py
# def recurrence_after(recurrence, after_dt, start_dt):
#     """
#     Fix for django-recurrence 1.3
#     Avoid outputting a impossible dt
#     """
#     dt = recurrence.after(after_dt, True, dtstart=start_dt)
#     if dt == start_dt:
#         return _fix_invalid_dt(recurrence, dt)
#     return dt
# 
# def recurrence_before(recurrence, before_dt, start_dt):
#     """
#     Fix for django-recurrence 1.3
#     Avoid outputting a impossible dt
#     """
#     dt = recurrence.before(before_dt, True, dtstart=start_dt)
#     if dt == start_dt:
#         return _fix_invalid_dt(recurrence, dt)
#     return dt


# Path: radioco/apps/schedules/tests/test_recurrences.py
import datetime
import recurrence
from django.test import TestCase
from radioco.apps.radioco.test_utils import TestDataMixin
from radioco.apps.radioco.tz_utils import recurrence_after, recurrence_before


    def test_impossible_recurrence_after(self):
        """
        Testing error calling after and function wrapper to solve it (recurrence_after)
        """
        start_dt = datetime.datetime(2014, 1, 20, 14, 0, 0)
        until_dt = datetime.datetime(2014, 1, 19, 14, 0, 0)
        daily_recurrence = recurrence.Recurrence(
            rrules=[recurrence.Rule(recurrence.DAILY, until=until_dt)])

        dt = daily_recurrence.after(start_dt, True, dtstart=start_dt)
        self.assertEqual(start_dt, dt)  # wrong!

        self.assertIsNone(recurrence_after(daily_recurrence, start_dt, start_dt))

    def test_impossible_recurrence_before(self):
        """
        Testing error calling before and function wrapper to solve it (recurrence_before)
        """
        start_dt = datetime.datetime(2014, 1, 20, 14, 0, 0)
        until_dt = datetime.datetime(2014, 1, 19, 14, 0, 0)
        daily_recurrence = recurrence.Recurrence(
            rrules=[recurrence.Rule(recurrence.MONTHLY, until=until_dt)])

        dt = daily_recurrence.before(start_dt + datetime.timedelta(seconds=1), dtstart=start_dt)
        self.assertEqual(start_dt, dt)  # wrong!

        self.assertIsNone(recurrence_before(daily_recurrence, start_dt + datetime.timedelta(seconds=1), start_dt))



class EmptyRecurrenceTests(TestDataMixin, TestCase):