Terarea  2
The automation project
Loading...
Searching...
No Matches
test_boilerplate_non_http.py
Go to the documentation of this file.
1"""_summary_
2 File in charge of testing the boilerplate Boilerplate non http class.
3"""
4import os
5import sys
6from datetime import datetime, timedelta
7
8import pytest
9from fastapi import FastAPI
10import constants as TCONST
11
12sys.path.append(os.getcwd())
13
14try:
15 from src.lib.sql import SQL
16 from src.lib.components import constants as CONST
17 from src.lib.components.runtime_data import RuntimeData
18 from src.lib.components.endpoints_routes import Endpoints
19 from src.lib.boilerplates.non_web import BoilerplateNonHTTP
20except ImportError as e:
21 raise ImportError("Failed to import the src module") from e
22
23ERROR = TCONST.ERROR
24DEBUG = TCONST.DEBUG
25SUCCESS = TCONST.SUCCESS
26RDI = RuntimeData(TCONST.SERVER_HOST, 5000, TCONST.PORT, ERROR, SUCCESS)
27RDI.app = FastAPI()
28RDI.endpoints_initialised = Endpoints(
29 runtime_data=RDI,
30 success=SUCCESS,
31 error=ERROR,
32 debug=DEBUG
33)
34RDI.database_link = SQL(
35 url=CONST.DB_HOST,
36 port=CONST.DB_PORT,
37 username=CONST.DB_USER,
38 password=CONST.DB_PASSWORD,
39 db_name=CONST.DB_DATABASE,
40 success=SUCCESS,
41 error=ERROR,
42 debug=DEBUG
43)
45 runtime_data_initialised=RDI,
46 success=SUCCESS,
47 error=ERROR,
48 debug=DEBUG
49)
50
51
52def test_pause(monkeypatch: pytest.MonkeyPatch) -> None:
53 """_summary_
54 Function in charge of testing the pause function.
55 """
56 test = "Charlie"
57 monkeypatch.setattr('builtins.input', lambda _: test)
58 data = BNHTTPI.pause()
59 assert data == test
60
61
62def test_set_lifespan() -> None:
63 """_summary_
64 Function in charge of testing the set lifespan function.
65 """
66 delay = 42
67 src: datetime = datetime.now() + timedelta(seconds=delay)
68 data: datetime = BNHTTPI.set_lifespan(delay)
69 assert data.strftime(
70 "%d/%m/%Y, %H:%M:%S") == src.strftime("%d/%m/%Y, %H:%M:%S")
71
72
73def test_generate_token() -> None:
74 """_summary_
75 Function in charge of testing the generate token function.
76 """
77 token = BNHTTPI.generate_token()
78 assert isinstance(token, str)
79 assert len(token) == 36
80 assert token.count("-") == 4
81
82
84 """_summary_
85 Function in charge of testing the check date function with a correct date.
86 """
87 assert BNHTTPI.check_date("11/09/2001") is True
88
89
91 """_summary_
92 Function in charge of testing the check date function with an incorrect date.
93 """
94 assert BNHTTPI.check_date("32/01/2021") is False
95
96
98 """_summary_
99 Function in charge of testing the check date function with an incorrect date.
100 """
101 assert BNHTTPI.check_date("12/13/2021") is False
102
103
105 """_summary_
106 Function in charge of testing the check date function with an incorrect date.
107 """
108 assert BNHTTPI.check_date("12/12/2O21") is False
109
110
112 """_summary_
113 Function in charge of testing the check date function with an incorrect date.
114 """
115 assert BNHTTPI.check_date("12-12-2021") is False
116
117
119 """_summary_
120 Function in charge of testing the generate_check_token function with 4.
121 """
122 code = BNHTTPI.generate_check_token(token_size=4)
123 assert isinstance(code, str)
124 assert code != ''
125 assert code.count('-') == 4
126
127
129 """_summary_
130 Function in charge of testing the generate_check_token function with 0.
131 """
132 code = BNHTTPI.generate_check_token(token_size=0)
133 assert isinstance(code, str)
134 assert code != ''
135 assert code.count('-') == 0
136
137
139 """_summary_
140 Function in charge of testing the generate_check_token function with a negative number.
141 """
142 code = BNHTTPI.generate_check_token(token_size=-1)
143 assert isinstance(code, str)
144 assert code != ''
145 assert code.count('-') == 0
146
147
149 """_summary_
150 Function in charge of testing the generate_check_token function with a string.
151 """
152 code = BNHTTPI.generate_check_token(token_size="e")
153 assert isinstance(code, str)
154 assert code != ''
155 assert code.count('-') == 4
156
157
159 """_summary_
160 Function in charge of testing the generate_check_token function with a floating number.
161 """
162 code = BNHTTPI.generate_check_token(token_size=4.8)
163 assert isinstance(code, str)
164 assert code != ''
165 assert code.count('-') == 4
166
167
169 """_summary_
170 Function in charge of testing the generate_check_token function with a negative floating number.
171 """
172 code = BNHTTPI.generate_check_token(token_size=-4.5)
173 assert isinstance(code, str)
174 assert code != ''
175 assert code.count('-') == 0
None test_pause(pytest.MonkeyPatch monkeypatch)