Add unit testcases for toscalib_elements_constraints.py
This patch covers InvalidSchemaError for greater_than, less_than, greater_or_equal and less_or_equal. Change-Id: I22f381398009de8aa170e7d45aefcbd4e0e0bc57
This commit is contained in:
parent
40f8c94c9f
commit
6c88022e74
@ -160,6 +160,14 @@ class ConstraintTest(TestCase):
|
|||||||
constraint.validate, 4)
|
constraint.validate, 4)
|
||||||
self.assertEqual('prop: 4 must be greater than "4".', str(error))
|
self.assertEqual('prop: 4 must be greater than "4".', str(error))
|
||||||
|
|
||||||
|
def test_greater_than_invalid(self):
|
||||||
|
snippet = 'greater_than: {4}'
|
||||||
|
schema = yaml.load(snippet)
|
||||||
|
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||||
|
'prop', Schema.INTEGER,
|
||||||
|
schema)
|
||||||
|
self.assertEqual('greater_than must be comparable.', str(error))
|
||||||
|
|
||||||
def test_greater_or_equal_validate(self):
|
def test_greater_or_equal_validate(self):
|
||||||
schema = {'greater_or_equal': 3.9}
|
schema = {'greater_or_equal': 3.9}
|
||||||
constraint = Constraint('prop', Schema.FLOAT, schema)
|
constraint = Constraint('prop', Schema.FLOAT, schema)
|
||||||
@ -179,6 +187,14 @@ class ConstraintTest(TestCase):
|
|||||||
self.assertEqual('prop: 3.8 must be greater or equal to "3.9".',
|
self.assertEqual('prop: 3.8 must be greater or equal to "3.9".',
|
||||||
str(error))
|
str(error))
|
||||||
|
|
||||||
|
def test_greater_or_equal_invalid(self):
|
||||||
|
snippet = 'greater_or_equal: {3.9}'
|
||||||
|
schema = yaml.load(snippet)
|
||||||
|
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||||
|
'prop', Schema.INTEGER,
|
||||||
|
schema)
|
||||||
|
self.assertEqual('greater_or_equal must be comparable.', str(error))
|
||||||
|
|
||||||
def test_less_than_validate(self):
|
def test_less_than_validate(self):
|
||||||
schema = {'less_than': datetime.date(2014, 0o7, 25)}
|
schema = {'less_than': datetime.date(2014, 0o7, 25)}
|
||||||
constraint = Constraint('prop', Schema.TIMESTAMP, schema)
|
constraint = Constraint('prop', Schema.TIMESTAMP, schema)
|
||||||
@ -202,6 +218,14 @@ class ConstraintTest(TestCase):
|
|||||||
'less than "2014-07-25".',
|
'less than "2014-07-25".',
|
||||||
str(error))
|
str(error))
|
||||||
|
|
||||||
|
def test_less_than_invalid(self):
|
||||||
|
snippet = 'less_than: {3.9}'
|
||||||
|
schema = yaml.load(snippet)
|
||||||
|
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||||
|
'prop', Schema.INTEGER,
|
||||||
|
schema)
|
||||||
|
self.assertEqual('less_than must be comparable.', str(error))
|
||||||
|
|
||||||
def test_less_or_equal_validate(self):
|
def test_less_or_equal_validate(self):
|
||||||
schema = {'less_or_equal': 4}
|
schema = {'less_or_equal': 4}
|
||||||
constraint = Constraint('prop', Schema.INTEGER, schema)
|
constraint = Constraint('prop', Schema.INTEGER, schema)
|
||||||
@ -215,6 +239,14 @@ class ConstraintTest(TestCase):
|
|||||||
constraint.validate, 5)
|
constraint.validate, 5)
|
||||||
self.assertEqual('prop: 5 must be less or equal to "4".', str(error))
|
self.assertEqual('prop: 5 must be less or equal to "4".', str(error))
|
||||||
|
|
||||||
|
def test_less_or_equal_invalid(self):
|
||||||
|
snippet = 'less_or_equal: {3.9}'
|
||||||
|
schema = yaml.load(snippet)
|
||||||
|
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||||
|
'prop', Schema.INTEGER,
|
||||||
|
schema)
|
||||||
|
self.assertEqual('less_or_equal must be comparable.', str(error))
|
||||||
|
|
||||||
def test_invalid_length(self):
|
def test_invalid_length(self):
|
||||||
schema = {'length': 'four'}
|
schema = {'length': 'four'}
|
||||||
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user