def test_includeme(monkeypatch): class FakeRegistry(dict): settings = {"database.url": pretend.stub()} engine = pretend.stub() create_engine = pretend.call_recorder(lambda url: engine) config = pretend.stub( add_directive=pretend.call_recorder(lambda *a: None), registry=FakeRegistry(), add_request_method=pretend.call_recorder(lambda f, name, reify: None), add_route_predicate=pretend.call_recorder(lambda *a, **kw: None), ) monkeypatch.setattr(db, "_create_engine", create_engine) includeme(config) assert config.add_directive.calls == [ pretend.call("alembic_config", _configure_alembic) ] assert create_engine.calls == [ pretend.call(config.registry.settings["database.url"]) ] assert config.registry["sqlalchemy.engine"] is engine assert config.add_request_method.calls == [ pretend.call(_create_session, name="db", reify=True), pretend.call(_readonly, name="read_only", reify=True), ] assert config.add_route_predicate.calls == [ pretend.call("read_only", db.ReadOnlyPredicate) ]
def test_includeme(monkeypatch): class FakeRegistry(dict): settings = {"database.url": pretend.stub()} engine = pretend.stub() create_engine = pretend.call_recorder(lambda url: engine) config = pretend.stub( add_directive=pretend.call_recorder(lambda *a: None), registry=FakeRegistry(), add_request_method=pretend.call_recorder(lambda f, name, reify: None), add_route_predicate=pretend.call_recorder(lambda *a, **kw: None), ) monkeypatch.setattr(db, "_create_engine", create_engine) includeme(config) assert config.add_directive.calls == [ pretend.call("alembic_config", _configure_alembic), ] assert create_engine.calls == [ pretend.call(config.registry.settings["database.url"]), ] assert config.registry["sqlalchemy.engine"] is engine assert config.add_request_method.calls == [ pretend.call(_create_session, name="db", reify=True), pretend.call(_readonly, name="read_only", reify=True), ] assert config.add_route_predicate.calls == [ pretend.call("read_only", db.ReadOnlyPredicate), ]
def test_includeme(monkeypatch): class FakeRegistry(dict): settings = {"database.url": pretend.stub()} engine = pretend.stub() create_engine = pretend.call_recorder(lambda url, isolation_level: engine) config = pretend.stub( add_directive=pretend.call_recorder(lambda *a: None), registry=FakeRegistry(), add_request_method=pretend.call_recorder(lambda f, name, reify: None), ) monkeypatch.setattr(sqlalchemy, "create_engine", create_engine) includeme(config) assert config.add_directive.calls == [ pretend.call("alembic_config", _configure_alembic), ] assert create_engine.calls == [ pretend.call( config.registry.settings["database.url"], isolation_level="SERIALIZABLE", ), ] assert config.registry["sqlalchemy.engine"] is engine assert config.add_request_method.calls == [ pretend.call(_create_session, name="db", reify=True), ]