MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / test_basic

Method test_basic

test/orm/declarative/test_basic.py:1216–1263  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1214 testing.config.skip_test("current base has no metaclass")
1215
1216 def test_basic(self):
1217 class User(Base, ComparableEntity):
1218 __tablename__ = "users"
1219
1220 id = Column(
1221 "id", Integer, primary_key=True, test_needs_autoincrement=True
1222 )
1223 name = Column("name", String(50))
1224 addresses = relationship("Address", backref="user")
1225
1226 class Address(Base, ComparableEntity):
1227 __tablename__ = "addresses"
1228
1229 id = Column(
1230 Integer, primary_key=True, test_needs_autoincrement=True
1231 )
1232 email = Column(String(50), key="_email")
1233 user_id = Column(
1234 "user_id", Integer, ForeignKey("users.id"), key="_user_id"
1235 )
1236
1237 Base.metadata.create_all(testing.db)
1238
1239 eq_(Address.__table__.c["id"].name, "id")
1240 eq_(Address.__table__.c["_email"].name, "email")
1241 eq_(Address.__table__.c["_user_id"].name, "user_id")
1242
1243 u1 = User(
1244 name="u1", addresses=[Address(email="one"), Address(email="two")]
1245 )
1246 sess = fixture_session()
1247 sess.add(u1)
1248 sess.flush()
1249 sess.expunge_all()
1250
1251 eq_(
1252 sess.query(User).all(),
1253 [
1254 User(
1255 name="u1",
1256 addresses=[Address(email="one"), Address(email="two")],
1257 )
1258 ],
1259 )
1260
1261 a1 = sess.query(Address).filter(Address.email == "two").one()
1262 eq_(a1, Address(email="two"))
1263 eq_(a1.user, User(name="u1"))
1264
1265 @testing.variation("mora", ["mixin", "abstract"])
1266 def test_abstract_and_or_mixin(self, mora):

Callers

nothing calls this directly

Calls 12

eq_Function · 0.90
fixture_sessionFunction · 0.90
create_allMethod · 0.80
UserClass · 0.70
AddressClass · 0.70
addMethod · 0.45
flushMethod · 0.45
expunge_allMethod · 0.45
allMethod · 0.45
queryMethod · 0.45
oneMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected