austial-testing 0.1.5__py3-none-any.whl

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,3 @@
1
+ from austial.testing.testing_module import Test, TestingModule, TestingModuleBuilder
2
+
3
+ __all__ = ["Test", "TestingModule", "TestingModuleBuilder"]
@@ -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)
@@ -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,5 @@
1
+ austial/testing/__init__.py,sha256=nvnEOYST0Umvi6o-pvru0bZmD3dL8N_CekTKr8BWuKU,146
2
+ austial/testing/testing_module.py,sha256=nJMaVpnsgUGaQn-1xut4f0AIamDscODPw3e1EQBwxlA,2211
3
+ austial_testing-0.1.5.dist-info/METADATA,sha256=UB_pGSzLdZW4GZiDxSrRWH-I957i-t9cziRc3YGZkyA,275
4
+ austial_testing-0.1.5.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
5
+ austial_testing-0.1.5.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.31.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any