MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_roundtrip

Method test_roundtrip

test/ext/test_horizontal_shard.py:423–473  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

421 )
422
423 def test_roundtrip(self):
424 sess = self._fixture_data()
425 tokyo = sess.query(WeatherLocation).filter_by(city="Tokyo").one()
426
427 eq_(tokyo.city, "Tokyo")
428 tokyo.city # reload 'city' attribute on tokyo
429 sess.expire_all()
430
431 t = sess.get(WeatherLocation, tokyo.id)
432 eq_(t.city, tokyo.city)
433 eq_(t.reports[0].temperature, 80.0)
434 north_american_cities = sess.query(WeatherLocation).filter(
435 WeatherLocation.continent == "North America"
436 )
437 eq_(
438 {c.city for c in north_american_cities},
439 {"New York", "Toronto"},
440 )
441 asia_and_europe = sess.query(WeatherLocation).filter(
442 WeatherLocation.continent.in_(["Europe", "Asia"])
443 )
444 eq_(
445 {c.city for c in asia_and_europe},
446 {"Tokyo", "London", "Dublin"},
447 )
448
449 # inspect the shard token stored with each instance
450 eq_(
451 {inspect(c).key[2] for c in asia_and_europe},
452 {"europe", "asia"},
453 )
454
455 eq_(
456 {inspect(c).identity_token for c in asia_and_europe},
457 {"europe", "asia"},
458 )
459
460 newyork = sess.query(WeatherLocation).filter_by(city="New York").one()
461 newyork_report = newyork.reports[0]
462 tokyo_report = tokyo.reports[0]
463
464 # same primary key, two identity keys
465 eq_(
466 inspect(newyork_report).identity_key,
467 (Report, (1,), "north_america"),
468 )
469 eq_(inspect(tokyo_report).identity_key, (Report, (1,), "asia"))
470
471 # the token representing the originating shard is available
472 eq_(inspect(newyork_report).identity_token, "north_america")
473 eq_(inspect(tokyo_report).identity_token, "asia")
474
475 def test_get_baked_query(self):
476 sess = self._fixture_data()

Callers

nothing calls this directly

Calls 10

_fixture_dataMethod · 0.95
eq_Function · 0.90
inspectFunction · 0.90
oneMethod · 0.45
filter_byMethod · 0.45
queryMethod · 0.45
expire_allMethod · 0.45
getMethod · 0.45
filterMethod · 0.45
in_Method · 0.45

Tested by

no test coverage detected