2 File in charge of testing the boilerplate Boilerplate non http class.
7from fastapi
import FastAPI
8import constants
as TCONST
10sys.path.append(os.getcwd())
21except ImportError
as e:
22 raise ImportError(
"Failed to import the src module")
from e
25SUCCESS = TCONST.SUCCESS
29RDI =
RuntimeData(TCONST.SERVER_HOST, TCONST.PORT,
"Area", ERROR, SUCCESS)
41RDI.boilerplate_responses_initialised = BRI
43 runtime_data_initialised=RDI,
49RDI.database_link =
SQL(
52 username=CONST.DB_USER,
53 password=CONST.DB_PASSWORD,
54 db_name=CONST.DB_DATABASE,
58RDI.boilerplate_responses_initialised = BRI
69 Function in charge of registering a fake user.
72 TCONST.USER_DATA_USERNAME,
73 TCONST.USER_DATA_EMAIL,
74 PHI.hash_password(str(TCONST.USER_DATA_PASSWORD)),
75 TCONST.USER_DATA_METHOD,
76 TCONST.USER_DATA_FAVICON,
77 TCONST.USER_DATA_ADMIN
79 column_names = RDI.database_link.get_table_column_names(CONST.TAB_ACCOUNTS)
81 RDI.database_link.insert_or_update_data_into_table(
82 table=CONST.TAB_ACCOUNTS,
90 Function in charge of deregistering a fake user.
92 RDI.database_link.remove_data_from_table(
93 table=CONST.TAB_ACCOUNTS,
94 where=f
"email='{TCONST.USER_DATA_EMAIL}'"
100 Function in charge of signing in a fake user.
103 user_id = RDI.database_link.get_data_from_table(
104 table=CONST.TAB_ACCOUNTS,
106 where=f
"email='{TCONST.USER_DATA_EMAIL}'",
109 table_columns = RDI.database_link.get_table_column_names(
110 CONST.TAB_CONNECTIONS
114 TCONST.USER_DATA_TOKEN,
116 RDI.database_link.datetime_to_string(
117 RDI.boilerplate_non_http_initialised.set_lifespan(
118 TCONST.USER_DATA_TOKEN_LIFESPAN
122 RDI.database_link.insert_or_update_data_into_table(
123 table=CONST.TAB_CONNECTIONS,
125 columns=table_columns
131 Function in charge of signing out a fake user.
133 RDI.database_link.remove_data_from_table(
134 table=CONST.TAB_CONNECTIONS,
135 where=f
"token='{TCONST.USER_DATA_TOKEN}'"
142 Function in charge of testing the build response body function.
144 title =
"Hello World"
145 message =
"Some hello world !"
149 data = BRI.build_response_body(
157 resp[CONST.JSON_TITLE] = title
158 resp[CONST.JSON_MESSAGE] = message
159 resp[CONST.JSON_RESP] = response
160 resp[CONST.JSON_LOGGED_IN] =
False
166 Function in charge of testing the build response body function.
168 title =
"Hello World"
169 message =
"Some hello world !"
173 data = BRI.build_response_body(
181 resp[CONST.JSON_TITLE] = title
182 resp[CONST.JSON_MESSAGE] = message
183 resp[CONST.JSON_ERROR] = response
184 resp[CONST.JSON_LOGGED_IN] =
False
190 Function in charge of testing the build response body function.
193 title =
"Hello World"
194 message =
"Some hello world !"
197 data = BRI.build_response_body(
201 token=TCONST.USER_DATA_TOKEN,
205 resp[CONST.JSON_TITLE] = title
206 resp[CONST.JSON_MESSAGE] = message
207 resp[CONST.JSON_RESP] = response
208 resp[CONST.JSON_LOGGED_IN] =
True
215 Function in charge of testing the build response body function.
218 title =
"Hello World"
219 message =
"Some hello world !"
222 data = BRI.build_response_body(
226 token=TCONST.USER_DATA_TOKEN,
230 resp[CONST.JSON_TITLE] = title
231 resp[CONST.JSON_MESSAGE] = message
232 resp[CONST.JSON_ERROR] = response
233 resp[CONST.JSON_LOGGED_IN] =
True
240 Function in charge of testing the invalid token function.
242 title =
"Hello World"
243 data = BRI.invalid_token(title)
245 resp[CONST.JSON_TITLE] = title
246 resp[CONST.JSON_MESSAGE] =
"The token you entered is invalid."
247 resp[CONST.JSON_ERROR] =
"Invalid token"
248 resp[CONST.JSON_LOGGED_IN] =
False
249 compiled_response = HCI.invalid_token(
251 content_type=CONST.CONTENT_TYPE,
252 headers=RDI.json_header
254 assert data.status_code == compiled_response.status_code
255 assert data.headers == compiled_response.headers
256 assert data.body == compiled_response.body
261 Function in charge of testing the not logged in function.
263 title =
"Hello World"
264 data = BRI.not_logged_in(title)
266 resp[CONST.JSON_TITLE] = title
267 resp[CONST.JSON_MESSAGE] =
"You need to be logged in to be able to run this endpoint."
268 resp[CONST.JSON_ERROR] =
"User not logged in"
269 resp[CONST.JSON_LOGGED_IN] =
False
270 compiled_response = HCI.unauthorized(
272 content_type=CONST.CONTENT_TYPE,
273 headers=RDI.json_header
275 assert data.status_code == compiled_response.status_code
276 assert data.headers == compiled_response.headers
277 assert data.body == compiled_response.body
282 Function in charge of testing the login failed function.
284 title =
"Hello World"
285 data = BRI.login_failed(title)
287 resp[CONST.JSON_TITLE] = title
288 resp[CONST.JSON_MESSAGE] =
"Login failed, invalid credentials or username."
289 resp[CONST.JSON_ERROR] =
"Invalid credentials or username."
290 resp[CONST.JSON_LOGGED_IN] =
False
291 compiled_response = HCI.unauthorized(
293 content_type=CONST.CONTENT_TYPE,
294 headers=RDI.json_header
296 assert data.status_code == compiled_response.status_code
297 assert data.headers == compiled_response.headers
298 assert data.body == compiled_response.body
303 Function in charge of testing the insuffisant rights function.
305 title =
"Hello World"
306 data = BRI.insuffisant_rights(title,
"not_a_token")
308 resp[CONST.JSON_TITLE] = title
309 resp[CONST.JSON_MESSAGE] =
"You do not have enough permissions to execute this endpoint."
310 resp[CONST.JSON_ERROR] =
"Insufficient rights for given account."
311 resp[CONST.JSON_LOGGED_IN] =
False
312 compiled_response = HCI.forbidden(
314 content_type=CONST.CONTENT_TYPE,
315 headers=RDI.json_header
317 assert data.status_code == compiled_response.status_code
318 assert data.headers == compiled_response.headers
319 assert data.body == compiled_response.body
324 Function in charge of testing the insuffisant rights function.
327 title =
"Hello World"
328 data = BRI.insuffisant_rights(title, TCONST.USER_DATA_TOKEN)
330 resp[CONST.JSON_TITLE] = title
331 resp[CONST.JSON_MESSAGE] =
"You do not have enough permissions to execute this endpoint."
332 resp[CONST.JSON_ERROR] =
"Insufficient rights for given account."
333 resp[CONST.JSON_LOGGED_IN] =
True
334 compiled_response = HCI.forbidden(
336 content_type=CONST.CONTENT_TYPE,
337 headers=RDI.json_header
340 assert data.status_code == compiled_response.status_code
341 assert data.headers == compiled_response.headers
342 assert data.body == compiled_response.body
347 Function in charge of testing the insuffisant rights function.
349 title =
"Hello World"
350 data = BRI.bad_request(title,
"not_a_token")
352 resp[CONST.JSON_TITLE] = title
353 resp[CONST.JSON_MESSAGE] =
"The request was not formatted correctly."
354 resp[CONST.JSON_ERROR] =
"Bad request"
355 resp[CONST.JSON_LOGGED_IN] =
False
356 compiled_response = HCI.bad_request(
358 content_type=CONST.CONTENT_TYPE,
359 headers=RDI.json_header
361 assert data.status_code == compiled_response.status_code
362 assert data.headers == compiled_response.headers
363 assert data.body == compiled_response.body
368 Function in charge of testing the insuffisant rights function.
371 title =
"Hello World"
372 data = BRI.bad_request(title, TCONST.USER_DATA_TOKEN)
374 resp[CONST.JSON_TITLE] = title
375 resp[CONST.JSON_MESSAGE] =
"The request was not formatted correctly."
376 resp[CONST.JSON_ERROR] =
"Bad request"
377 resp[CONST.JSON_LOGGED_IN] =
True
378 compiled_response = HCI.bad_request(
380 content_type=CONST.CONTENT_TYPE,
381 headers=RDI.json_header
384 assert data.status_code == compiled_response.status_code
385 assert data.headers == compiled_response.headers
386 assert data.body == compiled_response.body
391 Function in charge of testing the insuffisant rights function.
393 title =
"Hello World"
394 data = BRI.internal_server_error(title,
"not_a_token")
396 resp[CONST.JSON_TITLE] = title
397 resp[CONST.JSON_MESSAGE] =
"The server has encountered an error."
398 resp[CONST.JSON_ERROR] =
"Internal server error"
399 resp[CONST.JSON_LOGGED_IN] =
False
400 compiled_response = HCI.internal_server_error(
402 content_type=CONST.CONTENT_TYPE,
403 headers=RDI.json_header
405 assert data.status_code == compiled_response.status_code
406 assert data.headers == compiled_response.headers
407 assert data.body == compiled_response.body
412 Function in charge of testing the insuffisant rights function.
415 title =
"Hello World"
416 data = BRI.internal_server_error(title, TCONST.USER_DATA_TOKEN)
418 resp[CONST.JSON_TITLE] = title
419 resp[CONST.JSON_MESSAGE] =
"The server has encountered an error."
420 resp[CONST.JSON_ERROR] =
"Internal server error"
421 resp[CONST.JSON_LOGGED_IN] =
True
422 compiled_response = HCI.internal_server_error(
424 content_type=CONST.CONTENT_TYPE,
425 headers=RDI.json_header
428 assert data.status_code == compiled_response.status_code
429 assert data.headers == compiled_response.headers
430 assert data.body == compiled_response.body
435 Function in charge of testing the insuffisant rights function.
437 title =
"Hello World"
438 data = BRI.unauthorized(title,
"not_a_token")
440 resp[CONST.JSON_TITLE] = title
441 resp[CONST.JSON_MESSAGE] =
"You do not have permission to run this endpoint."
442 resp[CONST.JSON_ERROR] =
"Access denied"
443 resp[CONST.JSON_LOGGED_IN] =
False
444 compiled_response = HCI.unauthorized(
446 content_type=CONST.CONTENT_TYPE,
447 headers=RDI.json_header
449 assert data.status_code == compiled_response.status_code
450 assert data.headers == compiled_response.headers
451 assert data.body == compiled_response.body
456 Function in charge of testing the insuffisant rights function.
459 title =
"Hello World"
460 data = BRI.unauthorized(title, TCONST.USER_DATA_TOKEN)
462 resp[CONST.JSON_TITLE] = title
463 resp[CONST.JSON_MESSAGE] =
"You do not have permission to run this endpoint."
464 resp[CONST.JSON_ERROR] =
"Access denied"
465 resp[CONST.JSON_LOGGED_IN] =
True
466 compiled_response = HCI.unauthorized(
468 content_type=CONST.CONTENT_TYPE,
469 headers=RDI.json_header
472 assert data.status_code == compiled_response.status_code
473 assert data.headers == compiled_response.headers
474 assert data.body == compiled_response.body
479 Function in charge of testing the insuffisant rights function.
481 title =
"Hello World"
482 data = BRI.invalid_verification_code(title,
"not_a_token")
484 resp[CONST.JSON_TITLE] = title
485 resp[CONST.JSON_MESSAGE] =
"The verification code you have entered is incorrect."
486 resp[CONST.JSON_ERROR] =
"Invalid verification code"
487 resp[CONST.JSON_LOGGED_IN] =
False
488 compiled_response = HCI.bad_request(
490 content_type=CONST.CONTENT_TYPE,
491 headers=RDI.json_header
493 assert data.status_code == compiled_response.status_code
494 assert data.headers == compiled_response.headers
495 assert data.body == compiled_response.body
500 Function in charge of testing the insuffisant rights function.
503 title =
"Hello World"
504 data = BRI.invalid_verification_code(title, TCONST.USER_DATA_TOKEN)
506 resp[CONST.JSON_TITLE] = title
507 resp[CONST.JSON_MESSAGE] =
"The verification code you have entered is incorrect."
508 resp[CONST.JSON_ERROR] =
"Invalid verification code"
509 resp[CONST.JSON_LOGGED_IN] =
True
510 compiled_response = HCI.bad_request(
512 content_type=CONST.CONTENT_TYPE,
513 headers=RDI.json_header
516 assert data.status_code == compiled_response.status_code
517 assert data.headers == compiled_response.headers
518 assert data.body == compiled_response.body
523 Function in charge of testing the insuffisant rights function.
525 title =
"Hello World"
526 data = BRI.user_not_found(title,
"not_a_token")
528 resp[CONST.JSON_TITLE] = title
529 resp[CONST.JSON_MESSAGE] =
"The current user was not found."
530 resp[CONST.JSON_ERROR] =
"Not found"
531 resp[CONST.JSON_LOGGED_IN] =
False
532 compiled_response = HCI.not_found(
534 content_type=CONST.CONTENT_TYPE,
535 headers=RDI.json_header
537 assert data.status_code == compiled_response.status_code
538 assert data.headers == compiled_response.headers
539 assert data.body == compiled_response.body
544 Function in charge of testing the insuffisant rights function.
547 title =
"Hello World"
548 data = BRI.user_not_found(title, TCONST.USER_DATA_TOKEN)
550 resp[CONST.JSON_TITLE] = title
551 resp[CONST.JSON_MESSAGE] =
"The current user was not found."
552 resp[CONST.JSON_ERROR] =
"Not found"
553 resp[CONST.JSON_LOGGED_IN] =
True
554 compiled_response = HCI.not_found(
556 content_type=CONST.CONTENT_TYPE,
557 headers=RDI.json_header
560 assert data.status_code == compiled_response.status_code
561 assert data.headers == compiled_response.headers
562 assert data.body == compiled_response.body
567 Function in charge of testing the insuffisant rights function.
569 title =
"Hello World"
570 data = BRI.no_access_token(title,
"not_a_token")
572 resp[CONST.JSON_TITLE] = title
573 resp[CONST.JSON_MESSAGE] =
"Access token not found."
574 resp[CONST.JSON_ERROR] =
"No access token"
575 resp[CONST.JSON_LOGGED_IN] =
False
576 compiled_response = HCI.bad_request(
578 content_type=CONST.CONTENT_TYPE,
579 headers=RDI.json_header
581 assert data.status_code == compiled_response.status_code
582 assert data.headers == compiled_response.headers
583 assert data.body == compiled_response.body
588 Function in charge of testing the insuffisant rights function.
591 title =
"Hello World"
592 data = BRI.no_access_token(title, TCONST.USER_DATA_TOKEN)
594 resp[CONST.JSON_TITLE] = title
595 resp[CONST.JSON_MESSAGE] =
"Access token not found."
596 resp[CONST.JSON_ERROR] =
"No access token"
597 resp[CONST.JSON_LOGGED_IN] =
True
598 compiled_response = HCI.bad_request(
600 content_type=CONST.CONTENT_TYPE,
601 headers=RDI.json_header
604 assert data.status_code == compiled_response.status_code
605 assert data.headers == compiled_response.headers
606 assert data.body == compiled_response.body
611 Function in charge of testing the insuffisant rights function.
613 title =
"Hello World"
614 data = BRI.provider_not_found(title,
"not_a_token")
616 resp[CONST.JSON_TITLE] = title
617 resp[CONST.JSON_MESSAGE] =
"The provider you are looking for was not found."
618 resp[CONST.JSON_ERROR] =
"Provider not found"
619 resp[CONST.JSON_LOGGED_IN] =
False
620 compiled_response = HCI.not_found(
622 content_type=CONST.CONTENT_TYPE,
623 headers=RDI.json_header
625 assert data.status_code == compiled_response.status_code
626 assert data.headers == compiled_response.headers
627 assert data.body == compiled_response.body
632 Function in charge of testing the insuffisant rights function.
635 title =
"Hello World"
636 data = BRI.provider_not_found(title, TCONST.USER_DATA_TOKEN)
638 resp[CONST.JSON_TITLE] = title
639 resp[CONST.JSON_MESSAGE] =
"The provider you are looking for was not found."
640 resp[CONST.JSON_ERROR] =
"Provider not found"
641 resp[CONST.JSON_LOGGED_IN] =
True
642 compiled_response = HCI.not_found(
644 content_type=CONST.CONTENT_TYPE,
645 headers=RDI.json_header
648 assert data.status_code == compiled_response.status_code
649 assert data.headers == compiled_response.headers
650 assert data.body == compiled_response.body
655 Function in charge of testing the insuffisant rights function.
657 title =
"Hello World"
658 data = BRI.provider_not_given(title,
"not_a_token")
660 resp[CONST.JSON_TITLE] = title
661 resp[CONST.JSON_MESSAGE] =
"You have not given a provider."
662 resp[CONST.JSON_ERROR] =
"Provider missing"
663 resp[CONST.JSON_LOGGED_IN] =
False
664 compiled_response = HCI.bad_request(
666 content_type=CONST.CONTENT_TYPE,
667 headers=RDI.json_header
669 assert data.status_code == compiled_response.status_code
670 assert data.headers == compiled_response.headers
671 assert data.body == compiled_response.body
676 Function in charge of testing the insuffisant rights function.
679 title =
"Hello World"
680 data = BRI.provider_not_given(title, TCONST.USER_DATA_TOKEN)
682 resp[CONST.JSON_TITLE] = title
683 resp[CONST.JSON_MESSAGE] =
"You have not given a provider."
684 resp[CONST.JSON_ERROR] =
"Provider missing"
685 resp[CONST.JSON_LOGGED_IN] =
True
686 compiled_response = HCI.bad_request(
688 content_type=CONST.CONTENT_TYPE,
689 headers=RDI.json_header
692 assert data.status_code == compiled_response.status_code
693 assert data.headers == compiled_response.headers
694 assert data.body == compiled_response.body
699 Function in charge of testing the insuffisant rights function.
701 title =
"Hello World"
702 data = BRI.missing_variable_in_body(title,
"not_a_token")
704 resp[CONST.JSON_TITLE] = title
705 resp[CONST.JSON_MESSAGE] =
"A variable is missing in the body of the request."
706 resp[CONST.JSON_ERROR] =
"Missing variable"
707 resp[CONST.JSON_LOGGED_IN] =
False
708 compiled_response = HCI.bad_request(
710 content_type=CONST.CONTENT_TYPE,
711 headers=RDI.json_header
713 assert data.status_code == compiled_response.status_code
714 assert data.headers == compiled_response.headers
715 assert data.body == compiled_response.body
720 Function in charge of testing the insuffisant rights function.
723 title =
"Hello World"
724 data = BRI.missing_variable_in_body(title, TCONST.USER_DATA_TOKEN)
726 resp[CONST.JSON_TITLE] = title
727 resp[CONST.JSON_MESSAGE] =
"A variable is missing in the body of the request."
728 resp[CONST.JSON_ERROR] =
"Missing variable"
729 resp[CONST.JSON_LOGGED_IN] =
True
730 compiled_response = HCI.bad_request(
732 content_type=CONST.CONTENT_TYPE,
733 headers=RDI.json_header
736 assert data.status_code == compiled_response.status_code
737 assert data.headers == compiled_response.headers
738 assert data.body == compiled_response.body
None test_missing_variable_in_body_invalid_token()
None test_build_response_body_error()
None _register_fake_user()
None test_no_access_token_invalid_token()
None test_insuffisant_rights_invalid_token()
None test_user_not_found_valid_token()
None test_missing_variable_in_body_valid_token()
None _sing_fake_user_in()
None test_internal_server_error_valid_token()
None test_provider_not_given_invalid_token()
None test_no_access_token_valid_token()
None test_build_response_body_no_error()
None test_bad_request_valid_token()
None test_provider_not_found_invalid_token()
None test_invalid_token()
None test_invalid_verification_code_valid_token()
None test_not_logged_in()
None test_provider_not_given_valid_token()
None test_unauthorized_valid_token()
None test_internal_server_error_invalid_token()
None test_user_not_found_invalid_token()
None test_bad_request_invalid_token()
None test_unauthorized_invalid_token()
None test_provider_not_found_valid_token()
None test_insuffisant_rights_valid_token()
None test_build_response_body_error_logged_in()
None _sign_fake_user_out()
None test_invalid_verification_code_invalid_token()
None _unregister_fake_user()
None test_build_response_body_no_error_logged_in()