Exemplo n.º 1
0
 def test_with_default_as_date(self):
     field = fields.DateTime(default=date(2014, 8, 25))
     assert field.__schema__ == {
         'type': 'string',
         'format': 'date-time',
         'default': '2014-08-25T00:00:00'
     }
     self.assert_field(field, None, '2014-08-25T00:00:00')
Exemplo n.º 2
0
    def test_model_with_required(self):
        model = Model(
            'Person', {
                'name': fields.String(required=True),
                'age': fields.Integer,
                'birthdate': fields.DateTime(required=True),
            })

        assert model.__schema__ == {
            'properties': {
                'name': {
                    'type': 'string'
                },
                'age': {
                    'type': 'integer'
                },
                'birthdate': {
                    'type': 'string',
                    'format': 'date-time'
                }
            },
            'required': ['birthdate', 'name'],
            'type': 'object'
        }
Exemplo n.º 3
0
 def test_unsupported_value_format(self):
     field = fields.DateTime(dt_format='raw')
     self.assert_field_raises(field, 'xxx')
Exemplo n.º 4
0
 def test_unsupported_format(self):
     field = fields.DateTime(dt_format='raw')
     self.assert_field_raises(field, datetime.now())
Exemplo n.º 5
0
 def test_iso8601_value(self, value, expected):
     self.assert_field(fields.DateTime(dt_format='iso8601'), value,
                       expected)
Exemplo n.º 6
0
 def test_rfc822_value(self, value, expected):
     self.assert_field(fields.DateTime(dt_format='rfc822'), value, expected)
Exemplo n.º 7
0
 def test_max_exclusive(self):
     field = fields.DateTime(max='1984-06-07T00:00:00', exclusiveMax=True)
     assert 'maximum' in field.__schema__
     assert field.__schema__['maximum'] == '1984-06-07T00:00:00'
     assert 'exclusiveMaximum' in field.__schema__
     assert field.__schema__['exclusiveMaximum'] is True
Exemplo n.º 8
0
 def test_max_as_datetime(self):
     field = fields.DateTime(max=datetime(1984, 6, 7, 1, 2, 0))
     assert 'maximum' in field.__schema__
     assert field.__schema__['maximum'] == '1984-06-07T01:02:00'
     assert 'exclusiveMaximum' not in field.__schema__
Exemplo n.º 9
0
 def test_max(self):
     field = fields.DateTime(max='1984-06-07T00:00:00')
     assert 'maximum' in field.__schema__
     assert field.__schema__['maximum'] == '1984-06-07T00:00:00'
     assert 'exclusiveMaximum' not in field.__schema__
Exemplo n.º 10
0
 def test_min_as_date(self):
     field = fields.DateTime(min=date(1984, 6, 7))
     assert 'minimum' in field.__schema__
     assert field.__schema__['minimum'] == '1984-06-07T00:00:00'
     assert 'exclusiveMinimum' not in field.__schema__
Exemplo n.º 11
0
 def test_defaults(self):
     field = fields.DateTime()
     assert not field.required
     assert field.__schema__ == {'type': 'string', 'format': 'date-time'}
     self.assert_field(field, None, None)