def test_app_ctx_globals_pop() -> None: g = _AppCtxGlobals() g.foo = 'bar' # type: ignore assert g.pop('foo') == 'bar' assert g.pop('foo', None) is None with pytest.raises(KeyError): g.pop('foo')
def test_app_ctx_globals_pop() -> None: g = _AppCtxGlobals() g.foo = "bar" # type: ignore assert g.pop("foo") == "bar" assert g.pop("foo", None) is None with pytest.raises(KeyError): g.pop("foo")
def test_app_ctx_globals_iter() -> None: g = _AppCtxGlobals() g.foo = 'bar' # type: ignore g.bar = 'foo' # type: ignore assert sorted(iter(g)) == ['bar', 'foo'] # type: ignore
def test_app_ctx_globals_contains() -> None: g = _AppCtxGlobals() g.foo = 'bar' # type: ignore assert 'foo' in g assert 'bar' not in g
def test_app_ctx_globals_setdefault() -> None: g = _AppCtxGlobals() g.setdefault('foo', []).append('bar') assert g.foo == ['bar'] # type: ignore
def test_app_ctx_globals_get() -> None: g = _AppCtxGlobals() g.foo = 'bar' # type: ignore assert g.get('foo') == 'bar' assert g.get('bar', 'something') == 'something'
def test_app_ctx_globals_iter() -> None: g = _AppCtxGlobals() g.foo = "bar" # type: ignore g.bar = "foo" # type: ignore assert sorted(iter(g)) == ["bar", "foo"]
def test_app_ctx_globals_contains() -> None: g = _AppCtxGlobals() g.foo = "bar" # type: ignore assert "foo" in g assert "bar" not in g
def test_app_ctx_globals_setdefault() -> None: g = _AppCtxGlobals() g.setdefault("foo", []).append("bar") assert g.foo == ["bar"] # type: ignore
def test_app_ctx_globals_get() -> None: g = _AppCtxGlobals() g.foo = "bar" # type: ignore assert g.get("foo") == "bar" assert g.get("bar", "something") == "something"
from unittest.mock import patch from quart.ctx import _AppCtxGlobals from app.total import get_api from app.numbers_api import NumbersAPI @patch('quart.g', _AppCtxGlobals()) def test_get_api_exists(): from quart import g g.numbers_api = 'potato' assert get_api() == 'potato' @patch('quart.g', _AppCtxGlobals()) def test_get_api_does_not_exist_creates_new(): assert get_api() == NumbersAPI()