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

Method test_scalar_proxy

test/ext/test_associationproxy.py:988–1105  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

986class ScalarTest(fixtures.MappedTest):
987 @testing.provide_metadata
988 def test_scalar_proxy(self):
989 metadata = self.metadata
990
991 parents_table = Table(
992 "Parent",
993 metadata,
994 Column(
995 "id", Integer, primary_key=True, test_needs_autoincrement=True
996 ),
997 Column("name", String(128)),
998 )
999 children_table = Table(
1000 "Children",
1001 metadata,
1002 Column(
1003 "id", Integer, primary_key=True, test_needs_autoincrement=True
1004 ),
1005 Column("parent_id", Integer, ForeignKey("Parent.id")),
1006 Column("foo", String(128)),
1007 Column("bar", String(128)),
1008 Column("baz", String(128)),
1009 )
1010
1011 class Parent:
1012 foo = association_proxy("child", "foo")
1013 bar = association_proxy(
1014 "child", "bar", creator=lambda v: Child(bar=v)
1015 )
1016 baz = association_proxy(
1017 "child", "baz", creator=lambda v: Child(baz=v)
1018 )
1019
1020 def __init__(self, name):
1021 self.name = name
1022
1023 class Child:
1024 def __init__(self, **kw):
1025 for attr in kw:
1026 setattr(self, attr, kw[attr])
1027
1028 self.mapper_registry.map_imperatively(
1029 Parent,
1030 parents_table,
1031 properties={
1032 "child": relationship(
1033 Child, lazy="joined", backref="parent", uselist=False
1034 )
1035 },
1036 )
1037 self.mapper_registry.map_imperatively(Child, children_table)
1038
1039 metadata.create_all(testing.db)
1040 session = fixture_session()
1041
1042 def roundtrip(obj):
1043 if obj not in session:
1044 session.add(obj)
1045 session.flush()

Callers

nothing calls this directly

Calls 13

TableClass · 0.90
ColumnClass · 0.90
StringClass · 0.90
ForeignKeyClass · 0.90
relationshipFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
assert_raisesFunction · 0.90
map_imperativelyMethod · 0.80
create_allMethod · 0.80
ParentClass · 0.70
ChildClass · 0.70

Tested by

no test coverage detected