Skip to content

Commit

Permalink
Initial non working
Browse files Browse the repository at this point in the history
  • Loading branch information
euri10 committed Jun 22, 2023
0 parents commit 5f8ad75
Show file tree
Hide file tree
Showing 8 changed files with 679 additions and 0 deletions.
Empty file added README.md
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions mock_dependency_litestar/dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def some_dependency() -> str:
return "foo"
12 changes: 12 additions & 0 deletions mock_dependency_litestar/main.py
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)})
623 changes: 623 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions pyproject.toml
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 added tests/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions tests/test_deps.py
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"

0 comments on commit 5f8ad75

Please sign in to comment.