-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5f8ad75
Showing
8 changed files
with
679 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def some_dependency() -> str: | ||
return "foo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from litestar import Litestar, get | ||
from litestar.di import Provide | ||
|
||
from mock_dependency_litestar.dependencies import some_dependency | ||
|
||
|
||
@get() | ||
def handler(dep: str) -> str: | ||
return dep | ||
|
||
def create_app() -> Litestar: | ||
return Litestar([handler], dependencies={"dep": Provide(some_dependency)}) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[tool.poetry] | ||
name = "mock-dependency-litestar" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["euri10 <benoit.barthelet@gmail.com>"] | ||
readme = "README.md" | ||
packages = [{include = "mock_dependency_litestar"}] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.11" | ||
litestar = "^2.0.0b1" | ||
pytest = "^7.3.2" | ||
|
||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
from litestar.testing import TestClient | ||
|
||
from mock_dependency_litestar.main import create_app | ||
|
||
|
||
def new_dependency(): | ||
return "bar" | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_db(): | ||
return mock.patch("dependencies.some_dependency", new=new_dependency) | ||
|
||
|
||
@pytest.fixture | ||
def app(): | ||
return create_app() | ||
|
||
|
||
def test(app): | ||
with TestClient(app) as client: | ||
assert client.get("/").text == "bar" |