Exemplo n.º 1
0
class ActiveTimezoneTodayConditionSetTests(TestCase):
    def setUp(self):
        """
        Assume we have:
        - server with `America/Chicago` timezone
        - app with `America/New_York` timezone (if Django timezone support enabled)
        - current timezone `Europe/Moscow` (if active)
        - then it is 2016-01-01T00:00:00 at server
        """
        self.condition_set = ActiveTimezoneTodayConditionSet()
        self.server_dt = datetime.datetime(2016, 1, 1, 0, 0, 0)
        self.server_tz = pytz.timezone('America/Chicago')
        self.server_dt_aware = self.server_tz.localize(self.server_dt)
        self.server_tz_offset = -6
        self.app_to_server_tz_offset = datetime.timedelta(hours=1)
        self.active_to_server_tz_offset = datetime.timedelta(hours=9)

    @override_settings(USE_TZ=True, TIME_ZONE="America/New_York")
    @timezone.override('Europe/Moscow')
    def test_use_tz_with_active(self):
        with freeze_time(self.server_dt_aware,
                         tz_offset=self.server_tz_offset):
            assert (self.condition_set.get_field_value(
                None, 'now_is_on_or_after') == self.server_dt +
                    self.active_to_server_tz_offset)

    @override_settings(USE_TZ=True, TIME_ZONE="America/New_York")
    @timezone.override(None)
    def test_use_tz_no_active(self):
        with freeze_time(self.server_dt_aware,
                         tz_offset=self.server_tz_offset):
            assert (self.condition_set.get_field_value(
                None, 'now_is_on_or_after') == self.server_dt +
                    self.app_to_server_tz_offset)

    @override_settings(USE_TZ=False, TIME_ZONE=None)
    @timezone.override('Europe/Moscow')
    def test_no_use_tz_with_active(self):
        with freeze_time(self.server_dt_aware,
                         tz_offset=self.server_tz_offset):
            assert self.condition_set.get_field_value(
                None, 'now_is_on_or_after') == self.server_dt

    @override_settings(USE_TZ=False, TIME_ZONE=None)
    @timezone.override(None)
    def test_no_use_tz_without_active(self):
        with freeze_time(self.server_dt_aware,
                         tz_offset=self.server_tz_offset):
            assert self.condition_set.get_field_value(
                None, 'now_is_on_or_after') == self.server_dt
Exemplo n.º 2
0
 def setUp(self):
     """
     Assume we have:
     - server with `America/Chicago` timezone
     - app with `America/New_York` timezone (if Django timezone support enabled)
     - current timezone `Europe/Moscow` (if active)
     - then it is 2016-01-01T00:00:00 at server
     """
     self.condition_set = ActiveTimezoneTodayConditionSet()
     self.server_dt = datetime.datetime(2016, 1, 1, 0, 0, 0)
     self.server_tz = pytz.timezone('America/Chicago')
     self.server_dt_aware = self.server_tz.localize(self.server_dt)
     self.server_tz_offset = -6
     self.app_to_server_tz_offset = datetime.timedelta(hours=1)
     self.active_to_server_tz_offset = datetime.timedelta(hours=9)
Exemplo n.º 3
0
class ActiveTimezoneTodayConditionSetTests(TestCase):
    def setUp(self):
        """
        Assume we have:
        - server with `America/Chicago` timezone
        - app with `America/New_York` timezone (if Django timezone support enabled)
        - current timezone `Europe/Moscow` (if active)
        - then it is 2016-01-01T00:00:00 at server
        """
        self.condition_set = ActiveTimezoneTodayConditionSet()
        self.server_dt = datetime.datetime(2016, 1, 1, 0, 0, 0)
        self.server_tz = pytz.timezone('America/Chicago')
        self.server_dt_aware = self.server_tz.localize(self.server_dt)
        self.server_tz_offset = -6
        self.app_to_server_tz_offset = datetime.timedelta(hours=1)
        self.active_to_server_tz_offset = datetime.timedelta(hours=9)

    @override_settings(USE_TZ=True, TIME_ZONE="America/New_York")
    @timezone.override('Europe/Moscow')
    def test_use_tz_with_active(self):
        with freeze_time(self.server_dt_aware, tz_offset=self.server_tz_offset):
            assert (
                self.condition_set.get_field_value(None, 'now_is_on_or_after') ==
                self.server_dt + self.active_to_server_tz_offset
            )

    @override_settings(USE_TZ=True, TIME_ZONE="America/New_York")
    @timezone.override(None)
    def test_use_tz_no_active(self):
        with freeze_time(self.server_dt_aware, tz_offset=self.server_tz_offset):
            assert (
                self.condition_set.get_field_value(None, 'now_is_on_or_after') ==
                self.server_dt + self.app_to_server_tz_offset
            )

    @override_settings(USE_TZ=False, TIME_ZONE=None)
    @timezone.override('Europe/Moscow')
    def test_no_use_tz_with_active(self):
        with freeze_time(self.server_dt_aware, tz_offset=self.server_tz_offset):
            assert self.condition_set.get_field_value(None, 'now_is_on_or_after') == self.server_dt

    @override_settings(USE_TZ=False, TIME_ZONE=None)
    @timezone.override(None)
    def test_no_use_tz_without_active(self):
        with freeze_time(self.server_dt_aware, tz_offset=self.server_tz_offset):
            assert self.condition_set.get_field_value(None, 'now_is_on_or_after') == self.server_dt
Exemplo n.º 4
0
 def setUp(self):
     """
     Assume we have:
     - server with `America/Chicago` timezone
     - app with `America/New_York` timezone (if Django timezone support enabled)
     - current timezone `Europe/Moscow` (if active)
     - then it is 2016-01-01T00:00:00 at server
     """
     self.condition_set = ActiveTimezoneTodayConditionSet()
     self.server_dt = datetime.datetime(2016, 1, 1, 0, 0, 0)
     self.server_tz = pytz.timezone('America/Chicago')
     self.server_dt_aware = self.server_tz.localize(self.server_dt)
     self.server_tz_offset = -6
     self.app_to_server_tz_offset = datetime.timedelta(hours=1)
     self.active_to_server_tz_offset = datetime.timedelta(hours=9)