diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-09-01 16:25:20 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-09-01 16:25:20 +0000 |
| commit | 005603e2fb198c3f3328fa555e82a334f0f89d52 (patch) | |
| tree | bfec82270157f25d8335a44c21179a179614a257 /test/base | |
| parent | 2c1006534e2bb9e3e468e6ce47181f7a1f8a8de8 (diff) | |
| download | sqlalchemy-005603e2fb198c3f3328fa555e82a334f0f89d52.tar.gz | |
insure that "parent" pointers are set up on objects that were lazily loaded
Diffstat (limited to 'test/base')
| -rw-r--r-- | test/base/attributes.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/test/base/attributes.py b/test/base/attributes.py index d3ca34931..f281e487b 100644 --- a/test/base/attributes.py +++ b/test/base/attributes.py @@ -131,8 +131,8 @@ class AttributesTest(PersistTest): class Post(object):pass class Blog(object):pass - manager.register_attribute(Post, 'blog', uselist=False, extension=attributes.GenericBackrefExtension('posts')) - manager.register_attribute(Blog, 'posts', uselist=True, extension=attributes.GenericBackrefExtension('blog')) + manager.register_attribute(Post, 'blog', uselist=False, extension=attributes.GenericBackrefExtension('posts'), trackparent=True) + manager.register_attribute(Blog, 'posts', uselist=True, extension=attributes.GenericBackrefExtension('blog'), trackparent=True) b = Blog() (p1, p2, p3) = (Post(), Post(), Post()) b.posts.append(p1) @@ -165,6 +165,32 @@ class AttributesTest(PersistTest): j.port = None self.assert_(p.jack is None) + def testlazytrackparent(self): + """test that the "hasparent" flag works properly when lazy loaders and backrefs are used""" + manager = attributes.AttributeManager() + + class Post(object):pass + class Blog(object):pass + + # set up instrumented attributes with backrefs + manager.register_attribute(Post, 'blog', uselist=False, extension=attributes.GenericBackrefExtension('posts'), trackparent=True) + manager.register_attribute(Blog, 'posts', uselist=True, extension=attributes.GenericBackrefExtension('blog'), trackparent=True) + + # create objects as if they'd been freshly loaded from the database (without history) + b = Blog() + p1 = Post() + Blog.posts.set_callable(b, lambda:[p1]) + Post.blog.set_callable(p1, lambda:b) + + # assert connections + assert p1.blog is b + assert p1 in b.posts + + # no orphans + assert getattr(Blog, 'posts').hasparent(p1) + assert getattr(Post, 'blog').hasparent(b) + + def testinheritance(self): """tests that attributes are polymorphic""" class Foo(object):pass |
