Esempio n. 1
0
    def test_datetime_timezone_awareness(self):
        # parsed datetimes should obey USE_TZ
        f = IsoDateTimeField()
        r = make_aware(self.reference_dt, get_default_timezone())

        d = f.strptime(self.reference_str + "+01:00", IsoDateTimeField.ISO_8601)
        self.assertTrue(isinstance(d.tzinfo, tzinfo))
        self.assertEqual(d, r + r.utcoffset() - d.utcoffset())

        d = f.strptime(self.reference_str + "", IsoDateTimeField.ISO_8601)
        self.assertTrue(isinstance(d.tzinfo, tzinfo))
        self.assertEqual(d, r)
Esempio n. 2
0
    def test_datetime_timezone_naivety(self):
        # parsed datetimes should obey USE_TZ
        f = IsoDateTimeField()
        r = self.reference_dt.replace()

        d = f.strptime(self.reference_str + "+01:00", IsoDateTimeField.ISO_8601)
        self.assertTrue(d.tzinfo is None)
        self.assertEqual(d, r - timedelta(hours=1))

        d = f.strptime(self.reference_str + "", IsoDateTimeField.ISO_8601)
        self.assertTrue(d.tzinfo is None)
        self.assertEqual(d, r)
Esempio n. 3
0
    def test_datetime_timezone_naivety(self):
        # parsed datetimes should obey USE_TZ
        f = IsoDateTimeField()
        r = self.reference_dt.replace()

        # It's necessary to override this here, since the field class is parsed
        # when USE_TZ = True.
        f.default_timezone = None

        d = f.strptime(self.reference_str + "+01:00", IsoDateTimeField.ISO_8601)
        self.assertTrue(d.tzinfo is None)
        self.assertEqual(d, r - timedelta(hours=1))

        d = f.strptime(self.reference_str + "", IsoDateTimeField.ISO_8601)
        self.assertTrue(d.tzinfo is None)
        self.assertEqual(d, r)
    def test_datetime_timezone_naivety(self):
        # parsed datetimes should obey USE_TZ
        f = IsoDateTimeField()
        r = self.reference_dt.replace()

        # It's necessary to override this here, since the field class is parsed
        # when USE_TZ = True.
        f.default_timezone = None

        d = f.strptime(self.reference_str + "+01:00",
                       IsoDateTimeField.ISO_8601)
        self.assertTrue(d.tzinfo is None)
        self.assertEqual(d, r - timedelta(hours=1))

        d = f.strptime(self.reference_str + "", IsoDateTimeField.ISO_8601)
        self.assertTrue(d.tzinfo is None)
        self.assertEqual(d, r)
Esempio n. 5
0
    def _validate_history_date(self):
        params = {'lt': timedelta.max, 'gt': timedelta.max}
        for param_name in self.HISTORY_DATE_PARAMS:
            param_name = 'history_date__' + param_name
            param_value = self.query_params.get(param_name)
            if param_value is None:
                param_value = self.query_params.get(param_name + 'e')
            if param_value:
                try:
                    validator = IsoDateTimeField()
                    param_value = validator.strptime(param_value,
                                                     validator.ISO_8601)
                except ValueError:
                    pass
                else:
                    params[param_name.rsplit('_', 1)[1]] = param_value

        allowed_timedelta = timedelta(
            days=settings.ONLY_LAST_VERSION_ALLOWED_DAYS_RANGE)
        if abs(params['lt'] - params['gt']) > allowed_timedelta:
            raise DRFValidationError(self.ONLY_LAST_VERSION_ERROR_MSG)
 def test_datetime_zulu(self):
     f = IsoDateTimeField()
     d = f.strptime(self.reference_str + "Z", IsoDateTimeField.ISO_8601)
     self.assertTrue(isinstance(d, datetime))
 def test_datetime_string_with_timezone_is_parsed(self):
     f = IsoDateTimeField()
     d = f.strptime(self.reference_str + "+01:00",
                    IsoDateTimeField.ISO_8601)
     self.assertTrue(isinstance(d, datetime))
Esempio n. 8
0
 def test_datetime_non_iso_format(self):
     f = IsoDateTimeField()
     parsed = f.strptime('19-07-2015T51:34:13.759', '%d-%m-%YT%S:%M:%H.%f')
     self.assertTrue(isinstance(parsed, datetime))
     self.assertEqual(parsed, self.reference_dt)
Esempio n. 9
0
 def test_datetime_string_with_timezone_is_parsed(self):
     f = IsoDateTimeField()
     d = f.strptime("2015-07-19T13:34:51.759+01:00",
                    IsoDateTimeField.ISO_8601)
     self.assertTrue(isinstance(d, datetime))
Esempio n. 10
0
 def test_datetime_non_iso_format(self):
     f = IsoDateTimeField()
     parsed = f.strptime('19-07-2015T51:34:13.759', '%d-%m-%YT%S:%M:%H.%f')
     self.assertTrue(isinstance(parsed, datetime))
     self.assertEqual(parsed, self.reference_dt)
Esempio n. 11
0
 def test_datetime_string_with_timezone_is_parsed(self):
     f = IsoDateTimeField()
     d = f.strptime("2015-07-19T13:34:51.759+01:00", IsoDateTimeField.ISO_8601)
     self.assertTrue(isinstance(d, datetime))
Esempio n. 12
0
 def test_datetime_zulu(self):
     f = IsoDateTimeField()
     d = f.strptime(self.reference_str + "Z", IsoDateTimeField.ISO_8601)
     self.assertTrue(isinstance(d, datetime))
Esempio n. 13
0
 def test_datetime_string_with_timezone_is_parsed(self):
     f = IsoDateTimeField()
     d = f.strptime(self.reference_str + "+01:00", IsoDateTimeField.ISO_8601)
     self.assertTrue(isinstance(d, datetime))
Esempio n. 14
0
 def test_datetime_wrong_format(self):
     f = IsoDateTimeField()
     with self.assertRaises(ValueError):
         f.strptime('19-07-2015T51:34:13.759', IsoDateTimeField.ISO_8601)