示例#1
0
    def test_new_range(self):
        self.assertEqual(
            {
                'type':
                'array',
                'items': [{
                    'type': 'string',
                    'format': 'date-time',
                }, {
                    'type': 'string',
                    'format': 'date-time',
                }],
            },
            JsonDatetimeSchema.new_range().to_dict())

        self.assertEqual(
            {
                'type': ['array', 'null'],
                'items': [{
                    'type': ['string', 'null'],
                    'format': 'date-time',
                    'minDatetime': '2002-01-01T00:00:00Z',
                    'maxDatetime': '2020-01-01T00:00:00Z',
                }, {
                    'type': ['string', 'null'],
                    'format': 'date-time',
                    'minDatetime': '2002-01-01T00:00:00Z',
                    'maxDatetime': '2020-01-01T00:00:00Z',
                }],
            },
            JsonDatetimeSchema.new_range(min_datetime='2002-01-01T00:00:00Z',
                                         max_datetime='2020-01-01T00:00:00Z',
                                         nullable=True).to_dict())
示例#2
0
 def test_min_max_validity_checks(self):
     with self.assertRaises(ValueError):
         JsonDatetimeSchema(  # missing timezone specifier
             min_datetime='1980-02-03T12:34:56',
             max_datetime='1982-02-03T23:34:56+05:00')
     with self.assertRaises(ValueError):
         JsonDatetimeSchema(
             min_datetime='1980-02-03T12:34:56-08:00',
             # invalid date
             max_datetime='1985-01-32')
示例#3
0
 def test_to_instance(self):
     self.assertEqual(
         '2020-06-12T12:30:19Z',
         JsonDatetimeSchema(
             min_datetime='2020-02-01T00:00:00Z',
             max_datetime='2020-07-05T00:00:00Z').to_instance(
                 '2020-06-12T12:30:19Z'))
示例#4
0
 def test_to_dict(self):
     self.assertEqual(
         {
             'type': 'string',
             'format': 'date-time',
             'minDatetime': '2020-02-01T00:00:00Z',
             'maxDatetime': '2020-07-05T00:00:00Z'
         },
         JsonDatetimeSchema(min_datetime='2020-02-01T00:00:00Z',
                            max_datetime='2020-07-05T00:00:00Z').to_dict())
示例#5
0
 def test_store_date_limits(self):
     minimum = '1981-05-06T00:00:00+00:00'
     maximum = '1982-09-15T00:00:00+00:00'
     schema = JsonDatetimeSchema(min_datetime=minimum, max_datetime=maximum)
     self.assertEqual(minimum, schema.min_datetime)
     self.assertEqual(maximum, schema.max_datetime)