Пример #1
0
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')
Пример #2
0
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")
Пример #3
0
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
Пример #4
0
def test_app_ctx_globals_contains() -> None:
    g = _AppCtxGlobals()
    g.foo = 'bar'  # type: ignore
    assert 'foo' in g
    assert 'bar' not in g
Пример #5
0
def test_app_ctx_globals_setdefault() -> None:
    g = _AppCtxGlobals()
    g.setdefault('foo', []).append('bar')
    assert g.foo == ['bar']  # type: ignore
Пример #6
0
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'
Пример #7
0
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"]
Пример #8
0
def test_app_ctx_globals_contains() -> None:
    g = _AppCtxGlobals()
    g.foo = "bar"  # type: ignore
    assert "foo" in g
    assert "bar" not in g
Пример #9
0
def test_app_ctx_globals_setdefault() -> None:
    g = _AppCtxGlobals()
    g.setdefault("foo", []).append("bar")
    assert g.foo == ["bar"]  # type: ignore
Пример #10
0
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"
Пример #11
0
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()