Terarea  2
The automation project
Loading...
Searching...
No Matches
test_paths.py
Go to the documentation of this file.
1"""_summary_
2 File in charge of testing the paths class.
3"""
4import os
5import sys
6from fastapi import Request, Response, FastAPI
7import constants as TCONST
8
9sys.path.append(os.getcwd())
10try:
11 from src.lib.components.paths import ServerPaths
12 from src.lib.components.runtime_data import RuntimeData
13 from src.lib.components.endpoints_routes import Endpoints
14 from src.lib.components.oauth_authentication import OAuthAuthentication
15 from src.lib.components.constants import PATH_KEY, ENDPOINT_KEY, METHOD_KEY, ALLOWED_METHODS
16except ImportError as e:
17 raise ImportError("Failed to import the src module") from e
18
19
20def dummy_path(request: Request) -> Response:
21 """_summary_
22 Function in charge of testing if the current password is the same as the hashed version.
23 """
24 return {"msg": "Hello World !"}
25
26
27ERROR = TCONST.ERROR
28SUCCESS = TCONST.SUCCESS
29DEBUG = TCONST.DEBUG
30RDI = RuntimeData(TCONST.SERVER_HOST, TCONST.PORT, "Area", ERROR, SUCCESS)
31RDI.app = FastAPI()
32RDI.endpoints_initialised = Endpoints(
33 runtime_data=RDI,
34 success=SUCCESS,
35 error=ERROR,
36 debug=DEBUG
37)
38RDI.oauth_authentication_initialised = OAuthAuthentication(
39 runtime_data=RDI,
40 success=SUCCESS,
41 error=ERROR,
42 debug=DEBUG
43)
45 runtime_data=RDI,
46 success=SUCCESS,
47 error=ERROR,
48 debug=DEBUG
49)
50RDI.paths_initialised = SPI
51
52
53def test_path_adding() -> None:
54 """_summary_
55 Function in charge of testing if the current password is the same as the hashed version.
56 """
57 status = SPI.add_path(
58 "/dummy_path",
59 dummy_path,
60 "GET"
61 )
62 assert status == SUCCESS
63 assert len(SPI.routes) == 1
64 assert SPI.routes[0][PATH_KEY] == "/dummy_path"
65 assert SPI.routes[0][ENDPOINT_KEY] is dummy_path
66 assert SPI.routes[0][METHOD_KEY] == ["GET"]
67
68
70 """_summary_
71 Function in charge of testing the load_default_paths_initialised
72 """
73 SPI.load_default_paths_initialised()
74 assert len(SPI.routes) > 0
75 for i in SPI.routes:
76 assert isinstance(i[PATH_KEY], str) is True
77 assert callable(i[ENDPOINT_KEY]) is True
78 assert isinstance(i[METHOD_KEY], list) is True
79 assert len(i[METHOD_KEY]) > 0
80 for methods in i[METHOD_KEY]:
81 assert isinstance(methods, str) is True
82 assert methods in ALLOWED_METHODS
83
84
85def test_inject_routes() -> None:
86 """_summary_
87 Function in charge of testing the inject_routes
88 """
89 SPI.add_path("/dd", dummy_path, "GET")
90 SPI.load_default_paths_initialised()
91 try:
92 SPI.inject_routes()
93 except Exception as e:
94 print(f"error: {str(e)}")
95 assert False
None test_path_adding()
Definition test_paths.py:53
None test_inject_routes()
Definition test_paths.py:85
Response dummy_path(Request request)
Definition test_paths.py:20
None test_load_default_paths()
Definition test_paths.py:69