예제 #1
0
	def _validate(self, model):
		"""
		Validate the data model.
		:param model: The data model as JSON object or string.
		:returns: None.
		"""
		schema = openmediavault.json.Schema({
			"type":"object",
			"properties":{
				"type":{"type":"string","enum":["config"],"required":True},
				"id":{"type":"string","required":True},
				"alias":{"type":"string","required":False},
				"persistent":{"type":"boolean","required":False},
				"title":{"type":"string","required":False},
				"description":{"type":"string","required":False},
				"notificationid":{"type":"string","required":False},
				"properties":{"type":"any","required":True},
				"queryinfo":{
					"type":"object",
					"required":False,
					"properties":{
						"xpath":{"type":"string","required":True},
						"iterable":{"type":"boolean","required":True},
						"idproperty":{"type":"string","required":False},
						"refproperty":{"type":"string","required":False}
					}
				}
			}
		})
		try:
			schema.validate(model)
		except openmediavault.json.SchemaValidationException as e:
			raise Exception("The data model is invalid: %s" % str(e))
예제 #2
0
	def _validate(self, model):
		"""
		Validate the data model.
		:param model: The data model as JSON object or string.
		:returns: None.
		"""
		schema = openmediavault.json.Schema({
			"type":"object",
			"properties":{
				"type":{"type":"string","enum":["config"],"required":True},
				"id":{"type":"string","required":True},
				"alias":{"type":"string","required":False},
				"persistent":{"type":"boolean","required":False},
				"title":{"type":"string","required":False},
				"description":{"type":"string","required":False},
				"notificationid":{"type":"string","required":False},
				"properties":{"type":"any","required":True},
				"queryinfo":{
					"type":"object",
					"required":False,
					"properties":{
						"xpath":{"type":"string","required":True},
						"iterable":{"type":"boolean","required":True},
						"idproperty":{"type":"string","required":False},
						"refproperty":{"type":"string","required":False}
					}
				}
			}
		})
		try:
			schema.validate(model)
		except openmediavault.json.SchemaValidationException as e:
			raise Exception("The data model is invalid: %s" % str(e))
 def test_validate_pattern_fail(self):
     schema = self._get_schema()
     self.assertRaises(
         openmediavault.json.SchemaValidationException,
         lambda: schema.validate({
             "name": "Eggs",
             "slaves": "xyz0"
         }))
 def test_validate_minimum_fail(self):
     schema = self._get_schema()
     self.assertRaises(
         openmediavault.json.SchemaValidationException,
         lambda: schema.validate({
             "name": "Eggs",
             "price": 34.99
         }))
예제 #5
0
 def test_validate_maximum(self):
     schema = self._get_schema()
     self.assertRaises(
         openmediavault.json.SchemaValidationException,
         lambda: schema.validate({
             "name": "Apple",
             "price": 41
         }))
 def test_validate_fail(self):
     schema = self._get_schema()
     self.assertRaises(openmediavault.json.SchemaValidationException,
                       lambda: schema.validate({"price": 38}))
 def test_validate_pattern(self):
     schema = self._get_schema()
     schema.validate({"name": "Eggs", "slaves": "eth0"})
	def test_validate_maximum(self):
		schema = self._get_schema()
		self.assertRaises(openmediavault.json.SchemaValidationException,
			lambda: schema.validate({ "name": "Apple", "price": 41 }))
	def test_validate(self):
		schema = self._get_schema()
		self.assertRaises(openmediavault.json.SchemaValidationException,
			lambda: schema.validate({ "price": 38 }))
	def test_validate_minimum(self):
		schema = self._get_schema()
		self.assertRaises(openmediavault.json.SchemaValidationException,
			lambda: schema.validate({ "name": "Eggs", "price": 34.99 }))