austial-testing 0.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: austial-testing
|
|
3
|
+
Version: 0.1.5
|
|
4
|
+
Summary: TestingModule builder for overriding providers in unit/e2e tests -- mirrors @nestjs/testing.
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Requires-Dist: austial-common
|
|
7
|
+
Requires-Dist: austial-core
|
|
8
|
+
Requires-Dist: fastapi>=0.115.0
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "austial-testing"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
description = "TestingModule builder for overriding providers in unit/e2e tests -- mirrors @nestjs/testing."
|
|
5
|
+
requires-python = ">=3.11"
|
|
6
|
+
dependencies = [
|
|
7
|
+
"austial-common",
|
|
8
|
+
"austial-core",
|
|
9
|
+
"fastapi>=0.115.0",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
14
|
+
build-backend = "hatchling.build"
|
|
15
|
+
|
|
16
|
+
[tool.hatch.build.targets.wheel]
|
|
17
|
+
packages = ["src/austial"]
|
|
18
|
+
|
|
19
|
+
[tool.uv.sources]
|
|
20
|
+
austial-common = { workspace = true }
|
|
21
|
+
austial-core = { workspace = true }
|
|
22
|
+
|
|
23
|
+
[tool.hatch.version]
|
|
24
|
+
source = "vcs"
|
|
25
|
+
|
|
26
|
+
[tool.hatch.version.raw-options]
|
|
27
|
+
root = "../.."
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""``Test.create_testing_module(...).compile()`` -- mirrors ``@nestjs/testing``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Sequence
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from fastapi import FastAPI
|
|
9
|
+
|
|
10
|
+
from austial.common.decorators.modules import Module
|
|
11
|
+
from austial.core.app import AustialApplication
|
|
12
|
+
from austial.core.container import Container
|
|
13
|
+
from austial.core.module_scanner import scan_module
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TestingModule:
|
|
17
|
+
def __init__(self, container: Container, controllers: list):
|
|
18
|
+
self._container = container
|
|
19
|
+
self._controllers = controllers
|
|
20
|
+
|
|
21
|
+
def get(self, token: Any) -> Any:
|
|
22
|
+
"""Fetches a resolved provider straight out of the DI container --
|
|
23
|
+
the whole point of testing modules: unit-test a service with its real
|
|
24
|
+
dependency graph, no manual mocking wiring required."""
|
|
25
|
+
return self._container.resolve(token)
|
|
26
|
+
|
|
27
|
+
def create_austial_application(self) -> AustialApplication:
|
|
28
|
+
"""Mirrors ``moduleRef.createNestApplication()``. Call ``await app.init()``
|
|
29
|
+
before making requests against it."""
|
|
30
|
+
fastapi_app = FastAPI(title="Austial (test)")
|
|
31
|
+
return AustialApplication(self._container, fastapi_app, self._controllers, [])
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class TestingModuleBuilder:
|
|
35
|
+
def __init__(
|
|
36
|
+
self,
|
|
37
|
+
*,
|
|
38
|
+
imports: Sequence[Any] = (),
|
|
39
|
+
controllers: Sequence[type] = (),
|
|
40
|
+
providers: Sequence[Any] = (),
|
|
41
|
+
):
|
|
42
|
+
@Module(imports=list(imports), controllers=list(controllers), providers=list(providers))
|
|
43
|
+
class _TestingRootModule:
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
self._root_module = _TestingRootModule
|
|
47
|
+
|
|
48
|
+
async def compile(self) -> TestingModule:
|
|
49
|
+
container = Container()
|
|
50
|
+
scan_result = scan_module(self._root_module, container)
|
|
51
|
+
return TestingModule(container, scan_result.controllers)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class Test:
|
|
55
|
+
"""Entry point, mirrors Nest's ``Test.createTestingModule({...})``."""
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def create_testing_module(
|
|
59
|
+
*,
|
|
60
|
+
imports: Sequence[Any] = (),
|
|
61
|
+
controllers: Sequence[type] = (),
|
|
62
|
+
providers: Sequence[Any] = (),
|
|
63
|
+
) -> TestingModuleBuilder:
|
|
64
|
+
return TestingModuleBuilder(imports=imports, controllers=controllers, providers=providers)
|