def validate_model(m: TeaModel, ) -> None: """ Validate model @return: void """ if isinstance(m, TeaModel): m.validate()
def test_validate_pattern(self): tm = TeaModel() tm.validate_pattern('test', 'prop_name', 't') self.assertRaises(Exception, tm.validate_pattern, prop='test', prop_name='prop_name', pattern='q')
def test_validate_min_length(self): tm = TeaModel() tm.validate_min_length('test', 'prop_name', 1) self.assertRaises(Exception, tm.validate_min_length, prop='test', prop_name='prop_name', min_length=10)
def test_validate_required(self): tm = TeaModel() n = tm.validate_required('test', 'prop_name') self.assertIsNone(n) self.assertRaises(Exception, tm.validate_required, prop=None, prop_name='None')
def from_map( model: TeaModel, dic: Dict[str, Any] ) -> TeaModel: if isinstance(model, TeaModel): try: return model.from_map(dic) except Exception: model._map = dic return model else: return model
def to_map(in_: TeaModel, ) -> Dict[str, Any]: """ Model transforms to map[string]any @return: map[string]any """ if isinstance(in_, TeaModel): return in_.to_map() else: return in_
def test_validate_pattern(self): tm = TeaModel() tm.validate_pattern('test', 'prop_name', 't') tm.validate_pattern(123.1, 'prop_name', '1') try: tm.validate_pattern('test', 'prop_name', '1') assert False except Exception as e: self.assertEqual('prop_name is not match: 1', str(e))
def test_validate_maximum(self): tm = TeaModel() tm.validate_maximum(1, 'count', 10) try: tm.validate_maximum(10, 'count', 1) assert False except Exception as e: self.assertEqual('count is greater than the maximum: 1', str(e))
def test_validate_min_length(self): tm = TeaModel() tm.validate_min_length('test', 'prop_name', 1) try: tm.validate_min_length('test', 'prop_name', 10) assert False except Exception as e: self.assertEqual('prop_name is less than min-length: 10', str(e))
def test_validate_max_length(self): tm = TeaModel() tm.validate_max_length('test', 'prop_name', 10) try: tm.validate_max_length('test', 'prop_name', 1) assert False except Exception as e: self.assertEqual('prop_name is exceed max-length: 1', str(e))
def test_validate_minimum(self): tm = TeaModel() tm.validate_minimum(10, 'count', 1) try: tm.validate_minimum( 1, 'count', 10, ) assert False except Exception as e: self.assertEqual('count is less than the minimum: 10', str(e))
def test_validate_required(self): tm = TeaModel() tm.validate() tm.to_map() tm.from_map() n = tm.validate_required('test', 'prop_name') self.assertIsNone(n) try: tm.validate_required(None, 'prop_name') assert False except Exception as e: self.assertEqual('"prop_name" is required.', str(e))
def test_str(self): model = str(self.TestRegModel()) tm = str(TeaModel()) self.assertTrue(model.startswith('{\'')) self.assertTrue(model.endswith('}')) self.assertTrue(tm.startswith('<Tea.model.TeaModel object'))
def test_validate_minimum(self): tm = TeaModel() tm.validate_minimum(10, 1) self.assertRaises(Exception, tm.validate_minimum, num=1, minimum=10)
def test_validate_maximum(self): tm = TeaModel() tm.validate_maximum(1, 10) self.assertRaises(Exception, tm.validate_maximum, num=10, maximum=1)