Beispiel #1
0
    def test_get_schema(self):
        obj = TestValidatableObject()
        obj.id = 'ffded5c4-e4f6-4e02-a175-48e13c5c12a0'
        obj.validate()
        self.assertTrue(hasattr(obj, '_obj_validator'))

        expected = {
            'description': 'Designate TestValidatableObject Object',
            'title': 'TestValidatableObject',
            'required': ['id'],
            'additionalProperties': False,
            '$schema': 'http://json-schema.org/draft-04/hyper-schema',
            'type': 'object',
            'properties': {
                'id': {
                    'type': 'string',
                    'format': 'uuid'
                }
            }
        }
        schema = obj._obj_validator.schema
        self.assertEqual(schema, expected)

        with raises(AttributeError):  # bug
            schema = obj.obj_get_schema()
Beispiel #2
0
 def test_validate_handle_exception(self):
     rs = create_test_recordset()
     with mock.patch('designate.objects.DesignateObject.obj_cls_from_name') \
             as patched:
         patched.side_effect = KeyError
         with raises(exceptions.InvalidObject):
             # TODO(Federico): check the attributes of the exception
             rs.validate()
Beispiel #3
0
    def test_get_schema(self):
        obj = TestValidatableObject()
        obj.id = "ffded5c4-e4f6-4e02-a175-48e13c5c12a0"
        obj.validate()
        self.assertTrue(hasattr(obj, "_obj_validator"))

        expected = {
            "description": "Designate TestValidatableObject Object",
            "title": "TestValidatableObject",
            "required": ["id"],
            "additionalProperties": False,
            "$schema": "http://json-schema.org/draft-04/hyper-schema",
            "type": "object",
            "properties": {"id": {"type": "string", "format": "uuid"}},
        }
        schema = obj._obj_validator.schema
        self.assertEqual(schema, expected)

        with raises(AttributeError):  # bug
            schema = obj.obj_get_schema()
Beispiel #4
0
    def test_get_schema(self):
        obj = TestValidatableObject()
        obj.id = 'ffded5c4-e4f6-4e02-a175-48e13c5c12a0'
        obj.validate()
        self.assertTrue(hasattr(obj, '_obj_validator'))

        expected = {
            'description': 'Designate TestValidatableObject Object',
            'title': 'TestValidatableObject', 'required': ['id'],
            'additionalProperties': False,
            '$schema': 'http://json-schema.org/draft-04/hyper-schema',
            'type': 'object',
            'properties': {
                'id': {
                    'type': 'string', 'format': 'uuid'
                }
            }
        }
        schema = obj._obj_validator.schema
        self.assertEqual(schema, expected)

        with raises(AttributeError):  # bug
            schema = obj.obj_get_schema()
Beispiel #5
0
 def test_get_missing(self):
     obj = TestObjectDict(name=1)
     self.assertFalse(obj.obj_attr_is_set('foo'))
     with raises(AttributeError):
         obj.get('foo')
Beispiel #6
0
 def test_update_unexpected_attribute(self):
     obj = TestObject(id='MyID', name='test')
     with raises(AttributeError):
         obj.update({'id': 'new_id', 'new_key': 3})
Beispiel #7
0
 def test_from_list(self):
     with raises(NotImplementedError):
         TestObject.from_list([])
Beispiel #8
0
 def test_get_missing(self):
     obj = TestObjectDict(name=1)
     self.assertFalse(obj.obj_attr_is_set('foo'))
     with raises(AttributeError):
         obj.get('foo')
Beispiel #9
0
 def test_update_unexpected_attribute(self):
     obj = TestObject(id='MyID', name='test')
     with raises(AttributeError):
         obj.update({'id': 'new_id', 'new_key': 3})
Beispiel #10
0
 def test_from_list(self):
     with raises(NotImplementedError):
         TestObject.from_list([])
Beispiel #11
0
 def test_validate_invalid_secondary(self):
     domain = objects.Domain(
         type='SECONDARY',
     )
     with raises(exceptions.InvalidObject):
         domain.validate()
Beispiel #12
0
 def test_update_unexpected_attribute(self):
     obj = TestObject(id="MyID", name="test")
     with raises(AttributeError):
         obj.update({"id": "new_id", "new_key": 3})
Beispiel #13
0
 def test_validate_invalid_secondary(self):
     domain = objects.Domain(
         type='SECONDARY',
     )
     with raises(exceptions.InvalidObject):
         domain.validate()
Beispiel #14
0
 def test_masters_none(self):
     domain = objects.Domain()
     with raises(exceptions.RelationNotLoaded):
         self.assertEqual(domain.masters, None)