2This is the file in charge of storing the variable constants
5 ValueError: _description_
6 KeyError: _description_
7 KeyError: _description_
8 RuntimeError: _description_
16from random
import randint
17from typing
import Dict, Any
18from string
import ascii_letters, digits
22from display_tty
import IDISP
30IDISP.logger.name =
"Constants_tests"
36DB_DATABASE =
"terarea"
38SERVER_HOST =
"0.0.0.0"
39QUERY_HOST =
"http://127.0.0.1"
48APP_NAME =
"Area - Testing"
52SAFE_STRING = ascii_letters+digits
53SAFE_STRING_LENGTH = len(SAFE_STRING)
58 This function is in charge of generating a cache busting string.
59 This is done in order to avoid creating already existing accounts
68 cache +=
"startCacheBusting"
69 cache += str(getpid())
70 cache += str(uuid4()).replace(
"-",
"")
71 while iterations < length:
74 0, SAFE_STRING_LENGTH - 1
78 cache += str(getpid())
79 cache +=
"endCacheBusting"
85 Load the variable from the environement.
86 Otherwise, use the default value provided.
88 key (_type_): _description_
89 default (_type_): _description_
102 Get the content of an environement variable.
105 variable_name (str): _description_
108 str: _description_: the value of that variable, otherwise an exception is raised.
110 data = environement.get(variable_name)
113 f
"Variable {variable_name} not found in the environement"
120 Get the value of a configuration variable from the TOML file.
123 toml_conf (dict): The loaded TOML configuration as a dictionary.
124 section (str): The section of the TOML file to search in.
125 key (str): The key within the section to fetch.
126 default: The default value to return if the key is not found. Defaults to None.
129 str: The value of the configuration variable, or the default value if the key is not found.
132 KeyError: If the section is not found in the TOML configuration.
135 keys = section.split(
'.')
136 current_section = toml_conf
139 if k
in current_section:
140 current_section = current_section[k]
143 f
"Section '{section}' not found in TOML configuration."
146 if key
in current_section:
147 return current_section[key]
149 msg = f
"Key '{key}' not found in section '{section}' "
150 msg +=
"of TOML configuration."
154 except KeyError
as err:
155 IDISP.log_warning(f
"{err}",
"_get_toml_variable")
161 This is a function in charge of generating a password for on the fly accounts.
164 length (int, optional): _description_. Defaults to 20.
171 password += str(encapsulation_node)
175 while iterations < length:
176 password += SAFE_STRING[
179 SAFE_STRING_LENGTH - 1
184 password += str(encapsulation_node)
188def are_json_responses_identical(json_response1: Dict[str, Any], json_response2: Dict[str, Any], test_name: str =
"are_json_responses_identical") -> bool:
190 This function is in charge of comparing two json responses to see if they are identical.
193 json_response1 (Dict[str,Any]): _description_: The first json response you wish to compare
194 json_response2 (Dict[str,Any]): _description_: The json response that the first response will be compared against
197 bool: _description_: Returns True if they are identical, False otherwise.
200 json_response1_str = json.dumps(json_response1)
203 "Failed to convert json_response1 to json format", test_name
207 json_response2_str = json.dumps(json_response2)
210 "Failed to convert json_response2 to json format", test_name
213 if json_response1_str == json_response2_str:
215 msg =
"The content of json_response1 is different from json_response2:\n"
216 msg += f
"- json_response1_str = {json_response1_str}\n"
217 msg += f
"- json_response2_str = {json_response2_str}\n"
218 IDISP.log_warning(msg, test_name)
223CACHE_BUSTER_ADMIN = f
"admin_{get_cache_busting()}_admin"
227 dotenv.load_dotenv(TEST_ENV)
228 ENV = dict(dotenv.dotenv_values())
239 ENV,
"MINIO_ROOT_PASSWORD"
243except Exception
as e:
245 f
"Environement {TEST_ENV} failed to load, aborting"
248TOML_CONF = toml.load(
"config.toml")
252 TOML_CONF,
"Status_codes",
"success", SUCCESS
257 TOML_CONF,
"Test.host",
"server", SERVER_HOST
260 TOML_CONF,
"Test.host",
"client", QUERY_HOST
263 TOML_CONF,
"Test.host",
"port", PORT
268PATH_GET_API_HOME =
"/api/v1/"
269PATH_PUT_REGISTER =
"/api/v1/register"
270PATH_POST_LOGIN =
"/api/v1/login"
271PATH_PATCH_USER =
"/api/v1/user"
272PATH_PUT_USER =
"/api/v1/user"
273PATH_DELETE_USER =
"/api/v1/user"
274PATH_GET_USER =
"/api/v1/user"
275PATH_GET_USER_ID =
"/api/v1/user_id"
276PATH_POST_LOGOUT =
"/api/v1/logout"
279LAMBDA_USER_TOKEN_KEY: str =
"lambda_user"
280ADMIN_USER_TOKEN_KEY: str =
"admin_user"
281TOKEN_AUTH_ID_STR: str =
"Authorization"
282PRETTY_TOKEN_KEY: str =
"token_header"
283RAW_TOKEN_KEY: str =
"token_key"
286USER_DATA_EMAIL = f
"some_email_{CACHE_BUSTER}@company.example"
287USER_DATA_USERNAME = USER_DATA_EMAIL.split(
"@")[0]
289 length=20, encapsulation_node=
"some_user"
291USER_DATA_METHOD =
"local"
292USER_DATA_FAVICON =
"NULL"
294USER_DATA_TOKEN = f
"some_token_{CACHE_BUSTER}_some_token"
295USER_DATA_TOKEN_LIFESPAN = 3600
298USER_DATA_EMAIL_REBIND = f
"some_email_{CACHE_BUSTER}_rebind@company.example"
299USER_DATA_USERNAME_REBIND = USER_DATA_EMAIL_REBIND.split(
"@")[0]
301 length=20, encapsulation_node=
"some_user_rebind"
305USER_DATA_EMAIL_PATCH = f
"some_email_{CACHE_BUSTER}_patch@company.com"
306USER_DATA_USERNAME_PATCH = USER_DATA_EMAIL_PATCH.split(
"@")[0]
308 length=20, encapsulation_node=
"some_user_patch"
312ADMIN_DATA_EMAIL = f
"some_email_{CACHE_BUSTER_ADMIN}@company.example"
313ADMIN_DATA_USERNAME = ADMIN_DATA_EMAIL.split(
"@")[0]
315 length=20, encapsulation_node=
"some_admin"
317ADMIN_DATA_METHOD =
"local"
318ADMIN_DATA_FAVICON =
"NULL"
319ADMIN_DATA_ADMIN =
"1"
320ADMIN_DATA_TOKEN = f
"some_token_{CACHE_BUSTER_ADMIN}_some_token"
321ADMIN_DATA_TOKEN_LIFESPAN = 3600
324ADMIN_DATA_EMAIL_REBIND = f
"some_email_{CACHE_BUSTER_ADMIN}_"
325ADMIN_DATA_EMAIL_REBIND +=
"rebind@company.example"
326ADMIN_DATA_USERNAME_REBIND = ADMIN_DATA_EMAIL_REBIND.split(
"@")[0]
328 length=20, encapsulation_node=
"some_admin_rebind"
332ADMIN_DATA_EMAIL_PATCH = f
"some_email_{CACHE_BUSTER_ADMIN}_patch@company.com"
333ADMIN_DATA_USERNAME_PATCH = ADMIN_DATA_EMAIL_PATCH.split(
"@")[0]
335 length=20, encapsulation_node=
"some_admin_patch"
339UNODE_EMAIL_KEY =
"email"
340UNODE_PASSWORD_KEY =
"password"
341UNODE_USERNAME_KEY =
"username"
342UNODE_METHOD_KEY =
"method"
343UNODE_FAVICON_KEY =
"favicon"
344UNODE_ADMIN_KEY =
"admin"
347USER_NORMAL_MODE =
"normal"
349USER_PATCH_MODE =
"patch"
352RUNTIME_NODE_CRITICAL_KEY =
"critical"
355RESPONSE_GET_HOME_RESPONSE_NOT_LOGGED_IN = {
357 'msg':
'Welcome to the control server.',
361RESPONSE_GET_HOME_API_RESPONSE_NOT_LOGGED_IN = {
363 'msg':
'Welcome to the control server.',
367RESPONSE_POST_LOGIN = {
369 'msg':
'Welcome {name}',
374RESPONSE_POST_REGISTER = {
376 "msg":
"Account created successfully.",
382 "msg":
"The account information has been updated.",
386RESPONSE_PATCH_USER = {
387 "title":
"Patch user",
388 "msg":
"The account information has been updated.",
394 "msg":
"The user information has been retrieved.",
398RESPONSE_GET_USER_ID = {
399 "title":
"Get user id",
400 "msg":
"The user information has been retrieved.",
404RESPONSE_POST_LOGOUT = {
406 "msg":
"You have successfully logged out...",
410RESPONSE_DELETE_USER = {
411 "title":
"Delete user",
412 "msg":
"The account has successfully been deleted.",
Any _get_env_node(Dict[str, Any] env, str key, str default)
str _password_generator(int length=20, str encapsulation_node="password")
str _get_toml_variable(dict toml_conf, str section, str key, default=None)
str _get_environement_variable(dotenv environement, str variable_name)
bool are_json_responses_identical(Dict[str, Any] json_response1, Dict[str, Any] json_response2, str test_name="are_json_responses_identical")