Browse Source

Simplify tests for `dependency_testing` (#13223)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alejandra <[email protected]>
pull/13378/head
alv2017 2 months ago
committed by GitHub
parent
commit
1e6d95ce6d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 53
      tests/test_tutorial/test_testing_dependencies/test_tutorial001.py
  2. 56
      tests/test_tutorial/test_testing_dependencies/test_tutorial001_an.py
  3. 75
      tests/test_tutorial/test_testing_dependencies/test_tutorial001_an_py310.py
  4. 75
      tests/test_tutorial/test_testing_dependencies/test_tutorial001_an_py39.py
  5. 75
      tests/test_tutorial/test_testing_dependencies/test_tutorial001_py310.py

53
tests/test_tutorial/test_testing_dependencies/test_tutorial001.py

@ -1,25 +1,48 @@
from docs_src.dependency_testing.tutorial001 import (
app,
client,
test_override_in_items,
test_override_in_items_with_params,
test_override_in_items_with_q,
import importlib
from types import ModuleType
import pytest
from ...utils import needs_py39, needs_py310
@pytest.fixture(
name="test_module",
params=[
"tutorial001",
pytest.param("tutorial001_py310", marks=needs_py310),
"tutorial001_an",
pytest.param("tutorial001_an_py39", marks=needs_py39),
pytest.param("tutorial001_an_py310", marks=needs_py310),
],
)
def get_test_module(request: pytest.FixtureRequest) -> ModuleType:
mod: ModuleType = importlib.import_module(
f"docs_src.dependency_testing.{request.param}"
)
return mod
def test_override_in_items_run():
def test_override_in_items_run(test_module: ModuleType):
test_override_in_items = test_module.test_override_in_items
test_override_in_items()
def test_override_in_items_with_q_run():
def test_override_in_items_with_q_run(test_module: ModuleType):
test_override_in_items_with_q = test_module.test_override_in_items_with_q
test_override_in_items_with_q()
def test_override_in_items_with_params_run():
def test_override_in_items_with_params_run(test_module: ModuleType):
test_override_in_items_with_params = test_module.test_override_in_items_with_params
test_override_in_items_with_params()
def test_override_in_users():
def test_override_in_users(test_module: ModuleType):
client = test_module.client
response = client.get("/users/")
assert response.status_code == 200, response.text
assert response.json() == {
@ -28,7 +51,8 @@ def test_override_in_users():
}
def test_override_in_users_with_q():
def test_override_in_users_with_q(test_module: ModuleType):
client = test_module.client
response = client.get("/users/?q=foo")
assert response.status_code == 200, response.text
assert response.json() == {
@ -37,7 +61,8 @@ def test_override_in_users_with_q():
}
def test_override_in_users_with_params():
def test_override_in_users_with_params(test_module: ModuleType):
client = test_module.client
response = client.get("/users/?q=foo&skip=100&limit=200")
assert response.status_code == 200, response.text
assert response.json() == {
@ -46,7 +71,9 @@ def test_override_in_users_with_params():
}
def test_normal_app():
def test_normal_app(test_module: ModuleType):
app = test_module.app
client = test_module.client
app.dependency_overrides = None
response = client.get("/items/?q=foo&skip=100&limit=200")
assert response.status_code == 200, response.text

56
tests/test_tutorial/test_testing_dependencies/test_tutorial001_an.py

@ -1,56 +0,0 @@
from docs_src.dependency_testing.tutorial001_an import (
app,
client,
test_override_in_items,
test_override_in_items_with_params,
test_override_in_items_with_q,
)
def test_override_in_items_run():
test_override_in_items()
def test_override_in_items_with_q_run():
test_override_in_items_with_q()
def test_override_in_items_with_params_run():
test_override_in_items_with_params()
def test_override_in_users():
response = client.get("/users/")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Users!",
"params": {"q": None, "skip": 5, "limit": 10},
}
def test_override_in_users_with_q():
response = client.get("/users/?q=foo")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Users!",
"params": {"q": "foo", "skip": 5, "limit": 10},
}
def test_override_in_users_with_params():
response = client.get("/users/?q=foo&skip=100&limit=200")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Users!",
"params": {"q": "foo", "skip": 5, "limit": 10},
}
def test_normal_app():
app.dependency_overrides = None
response = client.get("/items/?q=foo&skip=100&limit=200")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Items!",
"params": {"q": "foo", "skip": 100, "limit": 200},
}

75
tests/test_tutorial/test_testing_dependencies/test_tutorial001_an_py310.py

@ -1,75 +0,0 @@
from ...utils import needs_py310
@needs_py310
def test_override_in_items_run():
from docs_src.dependency_testing.tutorial001_an_py310 import test_override_in_items
test_override_in_items()
@needs_py310
def test_override_in_items_with_q_run():
from docs_src.dependency_testing.tutorial001_an_py310 import (
test_override_in_items_with_q,
)
test_override_in_items_with_q()
@needs_py310
def test_override_in_items_with_params_run():
from docs_src.dependency_testing.tutorial001_an_py310 import (
test_override_in_items_with_params,
)
test_override_in_items_with_params()
@needs_py310
def test_override_in_users():
from docs_src.dependency_testing.tutorial001_an_py310 import client
response = client.get("/users/")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Users!",
"params": {"q": None, "skip": 5, "limit": 10},
}
@needs_py310
def test_override_in_users_with_q():
from docs_src.dependency_testing.tutorial001_an_py310 import client
response = client.get("/users/?q=foo")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Users!",
"params": {"q": "foo", "skip": 5, "limit": 10},
}
@needs_py310
def test_override_in_users_with_params():
from docs_src.dependency_testing.tutorial001_an_py310 import client
response = client.get("/users/?q=foo&skip=100&limit=200")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Users!",
"params": {"q": "foo", "skip": 5, "limit": 10},
}
@needs_py310
def test_normal_app():
from docs_src.dependency_testing.tutorial001_an_py310 import app, client
app.dependency_overrides = None
response = client.get("/items/?q=foo&skip=100&limit=200")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Items!",
"params": {"q": "foo", "skip": 100, "limit": 200},
}

75
tests/test_tutorial/test_testing_dependencies/test_tutorial001_an_py39.py

@ -1,75 +0,0 @@
from ...utils import needs_py39
@needs_py39
def test_override_in_items_run():
from docs_src.dependency_testing.tutorial001_an_py39 import test_override_in_items
test_override_in_items()
@needs_py39
def test_override_in_items_with_q_run():
from docs_src.dependency_testing.tutorial001_an_py39 import (
test_override_in_items_with_q,
)
test_override_in_items_with_q()
@needs_py39
def test_override_in_items_with_params_run():
from docs_src.dependency_testing.tutorial001_an_py39 import (
test_override_in_items_with_params,
)
test_override_in_items_with_params()
@needs_py39
def test_override_in_users():
from docs_src.dependency_testing.tutorial001_an_py39 import client
response = client.get("/users/")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Users!",
"params": {"q": None, "skip": 5, "limit": 10},
}
@needs_py39
def test_override_in_users_with_q():
from docs_src.dependency_testing.tutorial001_an_py39 import client
response = client.get("/users/?q=foo")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Users!",
"params": {"q": "foo", "skip": 5, "limit": 10},
}
@needs_py39
def test_override_in_users_with_params():
from docs_src.dependency_testing.tutorial001_an_py39 import client
response = client.get("/users/?q=foo&skip=100&limit=200")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Users!",
"params": {"q": "foo", "skip": 5, "limit": 10},
}
@needs_py39
def test_normal_app():
from docs_src.dependency_testing.tutorial001_an_py39 import app, client
app.dependency_overrides = None
response = client.get("/items/?q=foo&skip=100&limit=200")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Items!",
"params": {"q": "foo", "skip": 100, "limit": 200},
}

75
tests/test_tutorial/test_testing_dependencies/test_tutorial001_py310.py

@ -1,75 +0,0 @@
from ...utils import needs_py310
@needs_py310
def test_override_in_items_run():
from docs_src.dependency_testing.tutorial001_py310 import test_override_in_items
test_override_in_items()
@needs_py310
def test_override_in_items_with_q_run():
from docs_src.dependency_testing.tutorial001_py310 import (
test_override_in_items_with_q,
)
test_override_in_items_with_q()
@needs_py310
def test_override_in_items_with_params_run():
from docs_src.dependency_testing.tutorial001_py310 import (
test_override_in_items_with_params,
)
test_override_in_items_with_params()
@needs_py310
def test_override_in_users():
from docs_src.dependency_testing.tutorial001_py310 import client
response = client.get("/users/")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Users!",
"params": {"q": None, "skip": 5, "limit": 10},
}
@needs_py310
def test_override_in_users_with_q():
from docs_src.dependency_testing.tutorial001_py310 import client
response = client.get("/users/?q=foo")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Users!",
"params": {"q": "foo", "skip": 5, "limit": 10},
}
@needs_py310
def test_override_in_users_with_params():
from docs_src.dependency_testing.tutorial001_py310 import client
response = client.get("/users/?q=foo&skip=100&limit=200")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Users!",
"params": {"q": "foo", "skip": 5, "limit": 10},
}
@needs_py310
def test_normal_app():
from docs_src.dependency_testing.tutorial001_py310 import app, client
app.dependency_overrides = None
response = client.get("/items/?q=foo&skip=100&limit=200")
assert response.status_code == 200, response.text
assert response.json() == {
"message": "Hello Items!",
"params": {"q": "foo", "skip": 100, "limit": 200},
}
Loading…
Cancel
Save