Beispiel #1
0
 def test_01_complete_correct(self):
     correct = {
         "mybool1" : True,
         "mybool2" : False,
         "field1" : "stuff",
         "field2" : "other stuff",
         "list1" : [{
             "listbool" : True,
             "listfield" : "more stuff",
             "listlist" : ["plain string", "another string"],
             "listobj" : {
                 "objfield1" : "object property 1",
                 "objfield2" : "object property 2"
             }
         }],
         "list2" : ["string", u"unicode"],
         "obj1" : {
             "objbool" : False,
             "objfield" : "a field",
             "objlist" : [],
             "objobj" : {
                 "objfield3" : "3",
                 "objfield4" : "4"
             }
         },
         "obj2" : {
             "objfield5" : 5,
             "objfield6" : 6
         }
     }
     schema.validate(correct, _complete)
Beispiel #2
0
 def test_02_complete_bool_error(self):
     wrong = {
         "mybool1" : "wibble",
         "mybool2" : False,
         "field1" : "stuff",
         "field2" : "other stuff",
         "list1" : [{
             "listbool" : True,
             "listfield" : "more stuff",
             "listlist" : ["plain string", "another string"],
             "listobj" : {
                 "objfield1" : "object property 1",
                 "objfield2" : "object property 2"
             }
         }],
         "list2" : ["string", u"unicode"],
         "obj1" : {
             "objbool" : False,
             "objfield" : "a field",
             "objlist" : [],
             "objobj" : {
                 "objfield3" : "3",
                 "objfield4" : "4"
             }
         },
         "obj2" : {
             "objfield5" : 5,
             "objfield6" : 6
         }
     }
     with self.assertRaises(schema.ObjectSchemaValidationError):
         schema.validate(wrong, _complete)
     if fail:
         schema.validate(wrong, _complete)
Beispiel #3
0
 def test_04_complete_list_error(self):
     wrong = {
         "mybool1" : True,
         "mybool2" : False,
         "field1" : "stuff",
         "field2" : "other stuff",
         "list1" : "not a list",
         "list2" : ["string", u"unicode"],
         "obj1" : {
             "objbool" : False,
             "objfield" : "a field",
             "objlist" : [],
             "objobj" : {
                 "objfield3" : "3",
                 "objfield4" : "4"
             }
         },
         "obj2" : {
             "objfield5" : 5,
             "objfield6" : 6
         }
     }
     with self.assertRaises(schema.ObjectSchemaValidationError):
         schema.validate(wrong, _complete)
     if fail:
         schema.validate(wrong, _complete)
Beispiel #4
0
 def _validate_root(self, root):
     try:
         schema.validate(root, self._root_schema)
         return True
     except schema.ObjectSchemaValidationError as e:
         print e.message
     return False
Beispiel #5
0
 def _validate_register(self, reg):
     try:
         schema.validate(reg, self._register_schema)
         return True
     except schema.ObjectSchemaValidationError as e:
         print e.message
     return False
Beispiel #6
0
    def schema_validate(cls, obj):
        try:
            schema.validate(obj, cls._file_schema)
        except schema.ObjectSchemaValidationError as e:
            log.info("Could not validate the structure of the file: " + e.message)
            return False, [e.message]

        try:
            schema.validate(obj.get("register"), cls._register_schema)
        except schema.ObjectSchemaValidationError as e:
            log.info("Could not validate the structure of the file: " + e.message)
            return False, [e.message]

        return True, []
Beispiel #7
0
 def test_10_incomplete_error(self):
     correct = {
         "mybool1" : True,
         "mybool2" : False,
         "field1" : "stuff",
         "field2" : "other stuff",
         "list1" : [{
             "listbool" : True,
             "listfield" : "more stuff",
             "listlist" : ["plain string", "another string"],
             "listobj" : {
                 "objfield1" : "object property 1",
                 "objfield2" : "object property 2"
             }
         }],
         "list2" : ["string", u"unicode"],
         "obj1" : {
             "objbool" : False,
             "objfield" : "a field",
             "objlist" : [],
             "objobj" : {
                 "objfield3" : "3",
                 "objfield4" : "4"
             }
         },
         "obj2" : {
             "objfield5" : 5,
             "objfield6" : 6
         }
     }
     
     incomplete = deepcopy(_complete)
     del incomplete["object_entries"]["obj1"]
     
     with self.assertRaises(schema.ObjectSchemaValidationError):
         schema.validate(correct, incomplete)
     if fail:
         schema.validate(correct, incomplete)