def test_core_attrs(self): """ Ensure that sa_key and sa_lazy can be excluded """ a = adapter.SaMappedClassAlias(Address, exclude_attrs=['sa_lazy', 'sa_key']) u = Address() attrs = a.getEncodableAttributes(u) self.assertFalse('sa_key' in attrs) self.assertFalse('sa_lazy' in attrs)
def test_property(self): class Person(object): foo = 'bar' baz = 'gak' def _get_rw_property(self): return self.foo def _set_rw_property(self, val): self.foo = val def _get_ro_property(self): return self.baz rw = property(_get_rw_property, _set_rw_property) ro = property(_get_ro_property) self.mappers['person'] = mapper(Person, self.tables['users']) alias = adapter.SaMappedClassAlias(Person, 'person') obj = Person() attrs = alias.getEncodableAttributes(obj) self.assertEqual( attrs, { 'id': None, 'name': None, 'sa_key': [None], 'sa_lazy': [], 'rw': 'bar', 'ro': 'gak' }) self.assertEqual(obj.ro, 'gak') alias.applyAttributes( obj, { 'sa_key': [None], 'sa_lazy': [], 'id': None, 'name': None, 'rw': 'bar', 'ro': 'baz' }) self.assertEqual(obj.ro, 'gak')