MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _test_composite_mapped

Method _test_composite_mapped

test/orm/test_collection.py:2120–2170  ·  view source on GitHub ↗
(self, collection_class)

Source from the content-addressed store, hash-verified

2118 )
2119
2120 def _test_composite_mapped(self, collection_class):
2121 parents, children, Parent, Child = (
2122 self.tables.parents,
2123 self.tables.children,
2124 self.classes.Parent,
2125 self.classes.Child,
2126 )
2127
2128 self.mapper_registry.map_imperatively(Child, children)
2129 self.mapper_registry.map_imperatively(
2130 Parent,
2131 parents,
2132 properties={
2133 "children": relationship(
2134 Child,
2135 collection_class=collection_class,
2136 cascade="all, delete-orphan",
2137 )
2138 },
2139 )
2140
2141 p = Parent()
2142 p.children[("foo", "1")] = Child("foo", "1", "value 1")
2143 p.children[("foo", "2")] = Child("foo", "2", "value 2")
2144
2145 session = fixture_session()
2146 session.add(p)
2147 session.flush()
2148 pid = p.id
2149 session.expunge_all()
2150
2151 p = session.get(Parent, pid)
2152
2153 self.assert_(set(p.children.keys()) == {("foo", "1"), ("foo", "2")})
2154 cid = p.children[("foo", "1")].id
2155
2156 collections.collection_adapter(p.children).append_with_event(
2157 Child("foo", "1", "newvalue")
2158 )
2159
2160 session.flush()
2161 session.expunge_all()
2162
2163 p = session.get(Parent, pid)
2164
2165 self.assert_(set(p.children.keys()) == {("foo", "1"), ("foo", "2")})
2166 self.assert_(p.children[("foo", "1")].id != cid)
2167
2168 self.assert_(
2169 len(list(collections.collection_adapter(p.children))) == 2
2170 )
2171
2172 def test_mapped_collection(self):
2173 collection_class = collections.keyfunc_mapping(lambda c: c.a)

Callers 3

test_mixin2Method · 0.95

Calls 12

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
map_imperativelyMethod · 0.80
append_with_eventMethod · 0.80
ParentClass · 0.70
ChildClass · 0.70
addMethod · 0.45
flushMethod · 0.45
expunge_allMethod · 0.45
getMethod · 0.45
assert_Method · 0.45
keysMethod · 0.45

Tested by

no test coverage detected