Пример #1
0
 def test_dictas_2(self):
     f = DictAs(ExampleResource, null=True)
     self.assertEqual(None, f.clean(None))
     self.assertRaises(ValidationError, f.clean, 'abc')
     self.assertRaises(ValidationError, f.clean, 123)
     self.assertRaises(ValidationError, f.clean, {})
     self.assertRaises(ValidationError, f.clean, {'$': 'test_composite_fields.ExampleResource'})
     self.assertResourceEqual(ExampleResource(name='foo'), f.clean({'name': 'foo'}))
     self.assertResourceEqual(ExampleResource(name='foo'), f.clean({
         '$': 'test_composite_fields.ExampleResource', 'name': 'foo'}))
Пример #2
0
 def test_dictas_2(self):
     f = DictAs(ExampleResource, null=True)
     self.assertEqual(None, f.clean(None))
     self.assertRaises(ValidationError, f.clean, 'abc')
     self.assertRaises(ValidationError, f.clean, 123)
     self.assertRaises(ValidationError, f.clean, {})
     self.assertRaises(ValidationError, f.clean, {'$': 'tests.test_composite_fields.ExampleResource'})
     self.assertResourceEqual(ExampleResource(name='foo'), f.clean({'name': 'foo'}))
     self.assertResourceEqual(ExampleResource(name='foo'), f.clean({
         '$': 'tests.test_composite_fields.ExampleResource', 'name': 'foo'}))
Пример #3
0
 def test_dictas_2(self):
     f = DictAs(ExampleResource, null=True)
     assert f.clean(None) is None
     pytest.raises(ValidationError, f.clean, 'abc')
     pytest.raises(ValidationError, f.clean, 123)
     pytest.raises(ValidationError, f.clean, {})
     pytest.raises(ValidationError, f.clean, {'$': 'tests.test_fields_composite.ExampleResource'})
     self.assertResourceEqual(ExampleResource(name='foo'), f.clean({'name': 'foo'}))
     self.assertResourceEqual(ExampleResource(name='foo'), f.clean({
         '$': 'tests.test_fields_composite.ExampleResource', 'name': 'foo'}))
Пример #4
0
 def test_dictas_1(self):
     f = DictAs(ExampleResource)
     pytest.raises(ValidationError, f.clean, None)
     pytest.raises(ValidationError, f.clean, 'abc')
     pytest.raises(ValidationError, f.clean, 123)
     pytest.raises(ValidationError, f.clean, {})
     pytest.raises(ValidationError, f.clean,
                   {'$': 'tests.test_fields_composite.ExampleResource'})
     self.assertResourceEqual(ExampleResource(name='foo'),
                              f.clean({'name': 'foo'}))
     self.assertResourceEqual(
         ExampleResource(name='foo'),
         f.clean({
             '$': 'tests.test_fields_composite.ExampleResource',
             'name': 'foo'
         }))
Пример #5
0
 def test_dictas_ensure_is_resource(self):
     with pytest.raises(TypeError):
         DictAs("an item")
Пример #6
0
 def test_dictas_ensure_is_resource(self):
     with self.assertRaises(TypeError):
         DictAs("an item")