MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_decl_attributes

Method test_decl_attributes

test/orm/test_mapper.py:66–112  ·  view source on GitHub ↗

declarative mapper() now sets up some of the convenience attributes

(self)

Source from the content-addressed store, hash-verified

64 __dialect__ = "default"
65
66 def test_decl_attributes(self):
67 """declarative mapper() now sets up some of the convenience
68 attributes"""
69
70 Address, addresses, users, User = (
71 self.classes.Address,
72 self.tables.addresses,
73 self.tables.users,
74 self.classes.User,
75 )
76
77 am = self.mapper(Address, addresses)
78 um = self.mapper(
79 User,
80 users,
81 properties={
82 "addresses": relationship(
83 "Address",
84 order_by="Address.id",
85 primaryjoin="User.id == remote(Address.user_id)",
86 backref="user",
87 )
88 },
89 )
90
91 assert not hasattr(User, "metadata")
92
93 is_(um, User.__mapper__)
94 is_(am, Address.__mapper__)
95
96 is_(um.local_table, User.__table__)
97 is_(am.local_table, Address.__table__)
98
99 assert um.attrs.addresses.primaryjoin.compare(
100 users.c.id == addresses.c.user_id
101 )
102 assert um.attrs.addresses.order_by[0].compare(Address.id.expression)
103
104 configure_mappers()
105
106 is_(um.attrs.addresses.mapper, am)
107 is_(am.attrs.user.mapper, um)
108
109 sa.orm.clear_mappers()
110
111 assert not hasattr(User, "__mapper__")
112 assert not hasattr(User, "__table__")
113
114 def test_default_constructor_imperative_map(self):
115 class Plain(ComparableMixin):

Callers

nothing calls this directly

Calls 5

relationshipFunction · 0.90
is_Function · 0.90
configure_mappersFunction · 0.90
mapperMethod · 0.45
compareMethod · 0.45

Tested by

no test coverage detected