MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_viewonly

Method test_viewonly

test/orm/test_relationships.py:3181–3212  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3179 )
3180
3181 def test_viewonly(self):
3182 t1t2, t2, t1 = (self.tables.t1t2, self.tables.t2, self.tables.t1)
3183
3184 class A(ComparableEntity):
3185 pass
3186
3187 class B(ComparableEntity):
3188 pass
3189
3190 self.mapper_registry.map_imperatively(
3191 A,
3192 t1,
3193 properties={
3194 "bs": relationship(
3195 B, secondary=t1t2, backref=backref("as_", viewonly=True)
3196 )
3197 },
3198 )
3199 self.mapper_registry.map_imperatively(B, t2)
3200
3201 configure_mappers()
3202
3203 sess = fixture_session()
3204 a1 = A()
3205 b1 = B(as_=[a1])
3206
3207 assert not inspect(b1).attrs.as_.history.has_changes()
3208
3209 sess.add(a1)
3210 sess.flush()
3211 eq_(sess.query(A).first(), A(bs=[]))
3212 eq_(sess.query(B).first(), None)
3213
3214
3215class ViewOnlyOverlappingNames(fixtures.MappedTest):

Callers

nothing calls this directly

Calls 14

relationshipFunction · 0.90
backrefFunction · 0.90
configure_mappersFunction · 0.90
fixture_sessionFunction · 0.90
inspectFunction · 0.90
eq_Function · 0.90
map_imperativelyMethod · 0.80
has_changesMethod · 0.80
AClass · 0.70
BClass · 0.70
addMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected