def test_property_setget(self): """Checker all properties' getter and setter""" for class_name, data in entity.items(): instance = getattr(entities, class_name)() for name, stype, doc in data['fields']: if stype == 'date': setattr(instance, name, date.min) self.assertEqual(getattr(instance, name), date.min) if stype == 'string': setattr(instance, name, 'testing') self.assertEqual(getattr(instance, name), 'testing') setattr(instance, name, 123) # automatic convert to string self.assertEqual(getattr(instance, name), '123') if stype == 'int': setattr(instance, name, 232) self.assertEqual(getattr(instance, name), 232) setattr(instance, name, 12.3) # automiatic convert to int self.assertEqual(getattr(instance, name), 12) # raise exception if caonnot convert with self.assertRaises(ValueError): setattr(instance, name, 'abc') if stype == 'decimal': setattr(instance, name, 232) self.assertEqual(getattr(instance, name), 232.0) setattr(instance, name, 12.3) # automiatic convert to int self.assertEqual(getattr(instance, name), 12.3) # raise exception if caonnot convert with self.assertRaises(ValueError): setattr(instance, name, 'abc')
def test_propertylist(self): """Checker if generated all properties.""" for class_name, data in entity.items(): instance = getattr(entities, class_name)() for name, stype, doc in data['fields']: a = getattr(instance, name) self.assertIsNone(a) self.assertIsNotNone(instance.typeof)