2 File in charge of testing the logger class for the actions
7from typing
import List, Dict, Any, Union
9sys.path.append(os.path.join(
"..", os.getcwd()))
10sys.path.append(os.getcwd())
13 import constants
as TCONST
14except ImportError
as e:
15 raise ImportError(
"Failed to import the unit test constants module")
from e
26except ImportError
as e:
27 raise ImportError(
"Failed to import the src module")
from e
30SUCCESS = TCONST.SUCCESS
34RDI =
RuntimeData(TCONST.SERVER_HOST, TCONST.PORT,
"Area", ERROR, SUCCESS)
39RDI.boilerplate_responses_initialised = BRI
41 runtime_data_initialised=RDI,
50 username=CONST.DB_USER,
51 password=CONST.DB_PASSWORD,
52 db_name=CONST.DB_DATABASE,
55RDI.database_link = SQLI
57RDI.boilerplate_responses_initialised = BRI
75 "cache_busting": TCONST.CACHE_BUSTER_ADMIN
81 Function in charge of adding a dummy user to the database.
83 columns: List[str] = SQLI.get_table_column_names(CONST.TAB_ACCOUNTS)
85 msg = f
"Failed get data from table: {CONST.TAB_ACCOUNTS}"
86 raise RuntimeError(msg)
88 username = f
"test_user_{TEST_INFO['cache_busting']}"
89 email = f
"test_email_{TEST_INFO['cache_busting']}@combobox.ttk"
90 password = PHI.hash_password(f
"test_password_{TEST_INFO['cache_busting']}")
102 status = SQLI.insert_data_into_table(
103 table=CONST.TAB_ACCOUNTS,
108 msg = f
"Failed to add user {username}"
109 msg += f
"to the database {CONST.TAB_ACCOUNTS}"
110 raise RuntimeError(msg)
111 usr_id = SQLI.get_data_from_table(
112 table=CONST.TAB_ACCOUNTS,
114 where=f
"email='{email}'",
118 msg = f
"Failed to get user id for {username}"
119 raise RuntimeError(msg)
120 TEST_INFO[
"user_id"] = usr_id[0][0]
125 Function in charge of adding a dummy action to the database.
127 title =
"_add_dummy_action"
129 columns: List[str] = SQLI.get_table_column_names(CONST.TAB_ACTIONS)
131 msg = f
"Failed get data from table: {CONST.TAB_ACTIONS}"
132 raise RuntimeError(msg)
134 name = f
"test_action_name_{TEST_INFO['cache_busting']}"
135 trigger = f
"test_trigger_{TEST_INFO['cache_busting']}"
136 consequences = f
"test_consequences_{TEST_INFO['cache_busting']}"
137 user_id = str(TEST_INFO[
"user_id"])
138 tags =
"test_actions,will_not_run"
139 running = f
"{int(False)}"
140 description =
"This is an action that was generated during unit tests, it is thus not an action that can run."
156 status = SQLI.insert_data_into_table(
157 table=CONST.TAB_ACTIONS,
161 if status != SUCCESS:
162 msg = f
"Failed to add action {name}"
163 msg += f
"to the database {CONST.TAB_ACTIONS}"
164 raise RuntimeError(msg)
165 action_id = SQLI.get_data_from_table(
166 table=CONST.TAB_ACTIONS,
168 where=f
"name='{name}'",
171 if action_id == ERROR:
172 msg = f
"Failed to get action id for {name}"
173 raise RuntimeError(msg)
174 TCONST.IDISP.log_debug(f
"Gathered action: {action_id}", title)
175 TEST_INFO[
"action_id"] = action_id[0][0]
180 Function in charge of removing the dummy user from the database.
183 SQLI.remove_data_from_table(
185 where=f
"id={TEST_INFO['user_id']}"
191 Function in charge of removing the dummy action from the database.
193 SQLI.remove_data_from_table(
195 where=f
"id={TEST_INFO['action_id']}"
201 Function in charge of removing the log line from the database.
204 log_id (int): _description_
206 if isinstance(log_id, Dict):
208 SQLI.remove_data_from_table(
209 CONST.TAB_ACTION_LOGGING,
210 where=f
"id={log_id[i]}"
213 SQLI.remove_data_from_table(
214 CONST.TAB_ACTION_LOGGING,
221 Function in charge of getting the log line from the database.
224 log_line = SQLI.get_data_from_table(
225 table=CONST.TAB_ACTION_LOGGING,
227 where=f
"action_id='{node}'"
229 if log_line == ERROR:
230 msg = f
"Failed to get log line for {TEST_INFO['log_id']}"
231 raise RuntimeError(msg)
237 Function in charge of testing the log_event function.
239 title =
"test_log_event_info"
241 action_id = TEST_INFO[
"action_id"]
242 action_type = ACONST.TYPE_ACTION
243 action_code = ACONST.CODE_INFO
244 action_test_message =
"This is a test message"
245 action_resolved =
False
246 action_expected_level = ACONST.LEVEL_INFO
247 status = ACLI.log_event(
248 log_type=action_type,
251 message=action_test_message,
252 resolved=action_resolved,
254 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
256 msg =
"Failed to log the event."
257 TCONST.IDISP.log_error(msg, title)
259 assert status == SUCCESS
261 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
265 assert data[
"type"] == action_type
266 assert str(data[
"action_id"]) == str(action_id)
267 assert data[
"message"] == action_test_message
268 assert str(data[
"code"]) == str(action_code)
269 assert data[
"level"] == action_expected_level
270 assert str(data[
"resolved"]) == str(int(action_resolved))
275 Function in charge of testing the log_event function.
277 title =
"test_log_event_unknown"
279 action_id = TEST_INFO[
"action_id"]
280 action_type = ACONST.TYPE_ACTION
281 action_code = ACONST.CODE_UNKNOWN
282 action_test_message =
"This is a test message"
283 action_resolved =
False
284 action_expected_level = ACONST.LEVEL_UNKNOWN
285 status = ACLI.log_event(
286 log_type=action_type,
289 message=action_test_message,
290 resolved=action_resolved,
292 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
294 msg =
"Failed to log the event."
295 TCONST.IDISP.log_error(msg, title)
297 assert status == SUCCESS
299 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
303 assert data[
"type"] == action_type
304 assert str(data[
"action_id"]) == str(action_id)
305 assert data[
"message"] == action_test_message
306 assert str(data[
"code"]) == str(action_code)
307 assert data[
"level"] == action_expected_level
308 assert str(data[
"resolved"]) == str(int(action_resolved))
313 Function in charge of testing the log_event function.
315 title =
"test_log_event_success"
317 action_id = TEST_INFO[
"action_id"]
318 action_type = ACONST.TYPE_ACTION
319 action_code = ACONST.CODE_SUCCESS
320 action_test_message =
"This is a test message"
321 action_resolved =
False
322 action_expected_level = ACONST.LEVEL_SUCCESS
323 status = ACLI.log_event(
324 log_type=action_type,
327 message=action_test_message,
328 resolved=action_resolved,
330 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
332 msg =
"Failed to log the event."
333 TCONST.IDISP.log_error(msg, title)
335 assert status == SUCCESS
337 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
341 assert data[
"type"] == action_type
342 assert str(data[
"action_id"]) == str(action_id)
343 assert data[
"message"] == action_test_message
344 assert str(data[
"code"]) == str(action_code)
345 assert data[
"level"] == action_expected_level
346 assert str(data[
"resolved"]) == str(int(action_resolved))
351 Function in charge of testing the log_event function.
353 title =
"test_log_event_debug"
355 action_id = TEST_INFO[
"action_id"]
356 action_type = ACONST.TYPE_ACTION
357 action_code = ACONST.CODE_DEBUG
358 action_test_message =
"This is a test message"
359 action_resolved =
False
360 action_expected_level = ACONST.LEVEL_DEBUG
361 status = ACLI.log_event(
362 log_type=action_type,
365 message=action_test_message,
366 resolved=action_resolved,
368 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
370 msg =
"Failed to log the event."
371 TCONST.IDISP.log_error(msg, title)
373 assert status == SUCCESS
375 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
379 assert data[
"type"] == action_type
380 assert str(data[
"action_id"]) == str(action_id)
381 assert data[
"message"] == action_test_message
382 assert str(data[
"code"]) == str(action_code)
383 assert data[
"level"] == action_expected_level
384 assert str(data[
"resolved"]) == str(int(action_resolved))
389 Function in charge of testing the log_event function.
391 title =
"test_log_event_warning"
393 action_id = TEST_INFO[
"action_id"]
394 action_type = ACONST.TYPE_ACTION
395 action_code = ACONST.CODE_WARNING
396 action_test_message =
"This is a test message"
397 action_resolved =
False
398 action_expected_level = ACONST.LEVEL_WARNING
399 status = ACLI.log_event(
400 log_type=action_type,
403 message=action_test_message,
404 resolved=action_resolved,
406 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
408 msg =
"Failed to log the event."
409 TCONST.IDISP.log_error(msg, title)
411 assert status == SUCCESS
413 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
417 assert data[
"type"] == action_type
418 assert str(data[
"action_id"]) == str(action_id)
419 assert data[
"message"] == action_test_message
420 assert str(data[
"code"]) == str(action_code)
421 assert data[
"level"] == action_expected_level
422 assert str(data[
"resolved"]) == str(int(action_resolved))
427 Function in charge of testing the log_event function.
429 title =
"test_log_event_error"
431 action_id = TEST_INFO[
"action_id"]
432 action_type = ACONST.TYPE_ACTION
433 action_code = ACONST.CODE_ERROR
434 action_test_message =
"This is a test message"
435 action_resolved =
False
436 action_expected_level = ACONST.LEVEL_ERROR
437 status = ACLI.log_event(
438 log_type=action_type,
441 message=action_test_message,
442 resolved=action_resolved,
444 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
446 msg =
"Failed to log the event."
447 TCONST.IDISP.log_error(msg, title)
449 assert status == SUCCESS
451 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
455 assert data[
"type"] == action_type
456 assert str(data[
"action_id"]) == str(action_id)
457 assert data[
"message"] == action_test_message
458 assert str(data[
"code"]) == str(action_code)
459 assert data[
"level"] == action_expected_level
460 assert str(data[
"resolved"]) == str(int(action_resolved))
465 Function in charge of testing the log_event function.
467 title =
"test_log_event_critical"
469 action_id = TEST_INFO[
"action_id"]
470 action_type = ACONST.TYPE_ACTION
471 action_code = ACONST.CODE_CRITICAL
472 action_test_message =
"This is a test message"
473 action_resolved =
False
474 action_expected_level = ACONST.LEVEL_CRITICAL
475 status = ACLI.log_event(
476 log_type=action_type,
479 message=action_test_message,
480 resolved=action_resolved,
482 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
484 msg =
"Failed to log the event."
485 TCONST.IDISP.log_error(msg, title)
487 assert status == SUCCESS
489 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
493 assert data[
"type"] == action_type
494 assert str(data[
"action_id"]) == str(action_id)
495 assert data[
"message"] == action_test_message
496 assert str(data[
"code"]) == str(action_code)
497 assert data[
"level"] == action_expected_level
498 assert str(data[
"resolved"]) == str(int(action_resolved))
503 Function in charge of testing the log_event function.
505 title =
"test_log_event_fatal"
507 action_id = TEST_INFO[
"action_id"]
508 action_type = ACONST.TYPE_ACTION
509 action_code = ACONST.CODE_FATAL
510 action_test_message =
"This is a test message"
511 action_resolved =
False
512 action_expected_level = ACONST.LEVEL_FATAL
513 status = ACLI.log_event(
514 log_type=action_type,
517 message=action_test_message,
518 resolved=action_resolved,
520 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
522 msg =
"Failed to log the event."
523 TCONST.IDISP.log_error(msg, title)
525 assert status == SUCCESS
527 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
531 assert data[
"type"] == action_type
532 assert str(data[
"action_id"]) == str(action_id)
533 assert data[
"message"] == action_test_message
534 assert str(data[
"code"]) == str(action_code)
535 assert data[
"level"] == action_expected_level
536 assert str(data[
"resolved"]) == str(int(action_resolved))
541 Function in charge of testing the log_event function.
543 title =
"test_log_success"
545 action_id = TEST_INFO[
"action_id"]
546 action_type = ACONST.TYPE_ACTION
547 action_code = ACONST.CODE_SUCCESS
548 action_test_message =
"This is a test message"
549 action_resolved =
True
550 action_expected_level = ACONST.LEVEL_SUCCESS
551 status = ACLI.log_success(
552 log_type=action_type,
554 message=action_test_message,
555 resolved=action_resolved,
557 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
559 msg =
"Failed to log the event."
560 TCONST.IDISP.log_error(msg, title)
562 assert status == SUCCESS
564 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
568 assert data[
"type"] == action_type
569 assert str(data[
"action_id"]) == str(action_id)
570 assert data[
"message"] == action_test_message
571 assert str(data[
"code"]) == str(action_code)
572 assert data[
"level"] == action_expected_level
573 assert str(data[
"resolved"]) == str(int(action_resolved))
578 Function in charge of testing the log_event function.
580 title =
"test_log_debug"
582 action_id = TEST_INFO[
"action_id"]
583 action_type = ACONST.TYPE_ACTION
584 action_code = ACONST.CODE_DEBUG
585 action_test_message =
"This is a test message"
586 action_resolved =
True
587 action_expected_level = ACONST.LEVEL_DEBUG
588 status = ACLI.log_debug(
589 log_type=action_type,
591 message=action_test_message,
592 resolved=action_resolved,
594 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
596 msg =
"Failed to log the event."
597 TCONST.IDISP.log_error(msg, title)
599 assert status == SUCCESS
601 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
605 assert data[
"type"] == action_type
606 assert str(data[
"action_id"]) == str(action_id)
607 assert data[
"message"] == action_test_message
608 assert str(data[
"code"]) == str(action_code)
609 assert data[
"level"] == action_expected_level
610 assert str(data[
"resolved"]) == str(int(action_resolved))
615 Function in charge of testing the log_event function.
617 title =
"test_log_warning"
619 action_id = TEST_INFO[
"action_id"]
620 action_type = ACONST.TYPE_ACTION
621 action_code = ACONST.CODE_WARNING
622 action_test_message =
"This is a test message"
623 action_resolved =
True
624 action_expected_level = ACONST.LEVEL_WARNING
625 status = ACLI.log_warning(
626 log_type=action_type,
628 message=action_test_message,
629 resolved=action_resolved,
631 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
633 msg =
"Failed to log the event."
634 TCONST.IDISP.log_error(msg, title)
636 assert status == SUCCESS
638 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
642 assert data[
"type"] == action_type
643 assert str(data[
"action_id"]) == str(action_id)
644 assert data[
"message"] == action_test_message
645 assert str(data[
"code"]) == str(action_code)
646 assert data[
"level"] == action_expected_level
647 assert str(data[
"resolved"]) == str(int(action_resolved))
652 Function in charge of testing the log_event function.
654 title =
"test_log_error"
656 action_id = TEST_INFO[
"action_id"]
657 action_type = ACONST.TYPE_ACTION
658 action_code = ACONST.CODE_ERROR
659 action_test_message =
"This is a test message"
660 action_resolved =
True
661 action_expected_level = ACONST.LEVEL_ERROR
662 status = ACLI.log_error(
663 log_type=action_type,
665 message=action_test_message,
666 resolved=action_resolved,
668 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
670 msg =
"Failed to log the event."
671 TCONST.IDISP.log_error(msg, title)
673 assert status == SUCCESS
675 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
679 assert data[
"type"] == action_type
680 assert str(data[
"action_id"]) == str(action_id)
681 assert data[
"message"] == action_test_message
682 assert str(data[
"code"]) == str(action_code)
683 assert data[
"level"] == action_expected_level
684 assert str(data[
"resolved"]) == str(int(action_resolved))
689 Function in charge of testing the log_event function.
691 title =
"test_log_critical"
693 action_id = TEST_INFO[
"action_id"]
694 action_type = ACONST.TYPE_ACTION
695 action_code = ACONST.CODE_CRITICAL
696 action_test_message =
"This is a test message"
697 action_resolved =
True
698 action_expected_level = ACONST.LEVEL_CRITICAL
699 status = ACLI.log_critical(
700 log_type=action_type,
702 message=action_test_message,
703 resolved=action_resolved,
705 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
707 msg =
"Failed to log the event."
708 TCONST.IDISP.log_error(msg, title)
710 assert status == SUCCESS
712 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
716 assert data[
"type"] == action_type
717 assert str(data[
"action_id"]) == str(action_id)
718 assert data[
"message"] == action_test_message
719 assert str(data[
"code"]) == str(action_code)
720 assert data[
"level"] == action_expected_level
721 assert str(data[
"resolved"]) == str(int(action_resolved))
726 Function in charge of testing the log_event function.
728 title =
"test_log_fatal"
730 action_id = TEST_INFO[
"action_id"]
731 action_type = ACONST.TYPE_ACTION
732 action_code = ACONST.CODE_FATAL
733 action_test_message =
"This is a test message"
734 action_resolved =
True
735 action_expected_level = ACONST.LEVEL_FATAL
736 status = ACLI.log_fatal(
737 log_type=action_type,
739 message=action_test_message,
740 resolved=action_resolved,
742 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
744 msg =
"Failed to log the event."
745 TCONST.IDISP.log_error(msg, title)
747 assert status == SUCCESS
749 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
753 assert data[
"type"] == action_type
754 assert str(data[
"action_id"]) == str(action_id)
755 assert data[
"message"] == action_test_message
756 assert str(data[
"code"]) == str(action_code)
757 assert data[
"level"] == action_expected_level
758 assert str(data[
"resolved"]) == str(int(action_resolved))
763 Function in charge of testing the log_event function.
765 title =
"test_log_unknown"
767 action_id = TEST_INFO[
"action_id"]
768 action_type = ACONST.TYPE_ACTION
769 action_code = ACONST.CODE_UNKNOWN
770 action_test_message =
"This is a test message"
771 action_resolved =
True
772 action_expected_level = ACONST.LEVEL_UNKNOWN
773 status = ACLI.log_unknown(
774 log_type=action_type,
776 message=action_test_message,
777 resolved=action_resolved,
779 TCONST.IDISP.log_debug(f
"Log id = {status}", title)
781 msg =
"Failed to log the event."
782 TCONST.IDISP.log_error(msg, title)
784 assert status == SUCCESS
786 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
790 assert data[
"type"] == action_type
791 assert str(data[
"action_id"]) == str(action_id)
792 assert data[
"message"] == action_test_message
793 assert str(data[
"code"]) == str(action_code)
794 assert data[
"level"] == action_expected_level
795 assert str(data[
"resolved"]) == str(int(action_resolved))
800 Function in charge of testing the log_event function.
802 title =
"test_get_logs"
804 action_id = TEST_INFO[
"action_id"]
805 action_type = ACONST.TYPE_ACTION
806 action_test_message =
"This is a test message"
807 action_resolved =
True
809 for code
in ACONST.LIST_CODE:
810 status = ACLI.log_event(
811 log_type=action_type,
814 message=action_test_message,
815 resolved=action_resolved,
821 log_ids[code] = node[
'id']
823 msg =
"Failed to log the event."
824 TCONST.IDISP.log_error(msg, title)
827 assert status != ERROR
828 TCONST.IDISP.log_debug(f
"Log ids = {log_ids}", title)
830 TCONST.IDISP.log_debug(f
"Gathered data: {data}", title)
831 user_logs = ACLI.get_logs(
832 action_id=action_id, code=
None, beautify=
True
834 TCONST.IDISP.log_debug(f
"Gathered user logs = {user_logs}", title)
838 for log
in user_logs:
839 action_code = ACONST.LIST_CODE[index]
840 action_level = ACONST.LIST_LEVEL_INFO[index]
842 assert log[
"type"] == action_type
843 assert str(log[
"action_id"]) == str(action_id)
844 assert log[
"message"] == action_test_message
845 assert str(log[
"code"]) == str(action_code)
846 assert log[
"level"] == action_level
847 assert str(log[
"resolved"]) == str(int(action_resolved))
852 Function in charge of testing the log_event function.
854 title =
"test_get_logs_unknown"
856 action_id = TEST_INFO[
"action_id"]
857 action_type = ACONST.TYPE_ACTION
858 action_test_message =
"This is a test message"
859 action_resolved =
True
861 for code
in ACONST.LIST_CODE:
862 status = ACLI.log_event(
863 log_type=action_type,
866 message=action_test_message,
867 resolved=action_resolved,
873 log_ids[code] = node[
'id']
875 msg =
"Failed to log the event."
876 TCONST.IDISP.log_error(msg, title)
879 assert status != ERROR
880 TCONST.IDISP.log_debug(f
"Log ids = {log_ids}", title)
881 user_logs = ACLI.get_logs_unknown(
882 action_id=action_id, beautify=
True
884 print(f
"Gathered user logs = {user_logs}", title)
887 TCONST.IDISP.log_debug(f
"logs = {user_logs}", title)
888 for log
in user_logs:
889 action_code = ACONST.CODE_UNKNOWN
890 action_level = ACONST.LEVEL_UNKNOWN
891 assert log[
"type"] == action_type
892 assert str(log[
"action_id"]) == str(action_id)
893 assert log[
"message"] == action_test_message
894 assert str(log[
"code"]) == str(action_code)
895 assert log[
"level"] == action_level
896 assert str(log[
"resolved"]) == str(int(action_resolved))
901 Function in charge of testing the log_event function.
903 title =
"test_get_logs_info"
905 action_id = TEST_INFO[
"action_id"]
906 action_type = ACONST.TYPE_ACTION
907 action_test_message =
"This is a test message"
908 action_resolved =
True
910 for code
in ACONST.LIST_CODE:
911 status = ACLI.log_event(
912 log_type=action_type,
915 message=action_test_message,
916 resolved=action_resolved,
922 log_ids[code] = node[
'id']
924 msg =
"Failed to log the event."
925 TCONST.IDISP.log_error(msg, title)
928 assert status != ERROR
929 TCONST.IDISP.log_debug(f
"Log ids = {log_ids}", title)
930 user_logs = ACLI.get_logs_info(
931 action_id=action_id, beautify=
True
933 print(f
"Gathered user logs = {user_logs}", title)
936 TCONST.IDISP.log_debug(f
"logs = {user_logs}", title)
937 for log
in user_logs:
938 action_code = ACONST.CODE_INFO
939 action_level = ACONST.LEVEL_INFO
940 assert log[
"type"] == action_type
941 assert str(log[
"action_id"]) == str(action_id)
942 assert log[
"message"] == action_test_message
943 assert str(log[
"code"]) == str(action_code)
944 assert log[
"level"] == action_level
945 assert str(log[
"resolved"]) == str(int(action_resolved))
950 Function in charge of testing the log_event function.
952 title =
"test_get_logs_success"
954 action_id = TEST_INFO[
"action_id"]
955 action_type = ACONST.TYPE_ACTION
956 action_test_message =
"This is a test message"
957 action_resolved =
True
959 for code
in ACONST.LIST_CODE:
960 status = ACLI.log_event(
961 log_type=action_type,
964 message=action_test_message,
965 resolved=action_resolved,
971 log_ids[code] = node[
'id']
973 msg =
"Failed to log the event."
974 TCONST.IDISP.log_error(msg, title)
977 assert status != ERROR
978 TCONST.IDISP.log_debug(f
"Log ids = {log_ids}", title)
979 user_logs = ACLI.get_logs_success(
980 action_id=action_id, beautify=
True
982 print(f
"Gathered user logs = {user_logs}", title)
985 TCONST.IDISP.log_debug(f
"logs = {user_logs}", title)
986 for log
in user_logs:
987 action_code = ACONST.CODE_SUCCESS
988 action_level = ACONST.LEVEL_SUCCESS
989 assert log[
"type"] == action_type
990 assert str(log[
"action_id"]) == str(action_id)
991 assert log[
"message"] == action_test_message
992 assert str(log[
"code"]) == str(action_code)
993 assert log[
"level"] == action_level
994 assert str(log[
"resolved"]) == str(int(action_resolved))
999 Function in charge of testing the log_event function.
1001 title =
"test_get_logs_debug"
1003 action_id = TEST_INFO[
"action_id"]
1004 action_type = ACONST.TYPE_ACTION
1005 action_test_message =
"This is a test message"
1006 action_resolved =
True
1008 for code
in ACONST.LIST_CODE:
1009 status = ACLI.log_event(
1010 log_type=action_type,
1011 action_id=action_id,
1013 message=action_test_message,
1014 resolved=action_resolved,
1020 log_ids[code] = node[
'id']
1022 msg =
"Failed to log the event."
1023 TCONST.IDISP.log_error(msg, title)
1026 assert status != ERROR
1027 TCONST.IDISP.log_debug(f
"Log ids = {log_ids}", title)
1028 user_logs = ACLI.get_logs_debug(
1029 action_id=action_id, beautify=
True
1031 print(f
"Gathered user logs = {user_logs}", title)
1034 TCONST.IDISP.log_debug(f
"logs = {user_logs}", title)
1035 for log
in user_logs:
1036 action_code = ACONST.CODE_DEBUG
1037 action_level = ACONST.LEVEL_DEBUG
1038 assert log[
"type"] == action_type
1039 assert str(log[
"action_id"]) == str(action_id)
1040 assert log[
"message"] == action_test_message
1041 assert str(log[
"code"]) == str(action_code)
1042 assert log[
"level"] == action_level
1043 assert str(log[
"resolved"]) == str(int(action_resolved))
1048 Function in charge of testing the log_event function.
1050 title =
"test_get_logs_warning"
1052 action_id = TEST_INFO[
"action_id"]
1053 action_type = ACONST.TYPE_ACTION
1054 action_test_message =
"This is a test message"
1055 action_resolved =
True
1057 for code
in ACONST.LIST_CODE:
1058 status = ACLI.log_event(
1059 log_type=action_type,
1060 action_id=action_id,
1062 message=action_test_message,
1063 resolved=action_resolved,
1069 log_ids[code] = node[
'id']
1071 msg =
"Failed to log the event."
1072 TCONST.IDISP.log_error(msg, title)
1075 assert status != ERROR
1076 TCONST.IDISP.log_debug(f
"Log ids = {log_ids}", title)
1077 user_logs = ACLI.get_logs_warning(
1078 action_id=action_id, beautify=
True
1080 print(f
"Gathered user logs = {user_logs}", title)
1083 TCONST.IDISP.log_debug(f
"logs = {user_logs}", title)
1084 for log
in user_logs:
1085 action_code = ACONST.CODE_WARNING
1086 action_level = ACONST.LEVEL_WARNING
1087 assert log[
"type"] == action_type
1088 assert str(log[
"action_id"]) == str(action_id)
1089 assert log[
"message"] == action_test_message
1090 assert str(log[
"code"]) == str(action_code)
1091 assert log[
"level"] == action_level
1092 assert str(log[
"resolved"]) == str(int(action_resolved))
1097 Function in charge of testing the log_event function.
1099 title =
"test_get_logs_error"
1101 action_id = TEST_INFO[
"action_id"]
1102 action_type = ACONST.TYPE_ACTION
1103 action_test_message =
"This is a test message"
1104 action_resolved =
True
1106 for code
in ACONST.LIST_CODE:
1107 status = ACLI.log_event(
1108 log_type=action_type,
1109 action_id=action_id,
1111 message=action_test_message,
1112 resolved=action_resolved,
1118 log_ids[code] = node[
'id']
1120 msg =
"Failed to log the event."
1121 TCONST.IDISP.log_error(msg, title)
1124 assert status != ERROR
1125 TCONST.IDISP.log_debug(f
"Log ids = {log_ids}", title)
1126 user_logs = ACLI.get_logs_error(
1127 action_id=action_id, beautify=
True
1129 print(f
"Gathered user logs = {user_logs}", title)
1132 TCONST.IDISP.log_debug(f
"logs = {user_logs}", title)
1133 for log
in user_logs:
1134 action_code = ACONST.CODE_ERROR
1135 action_level = ACONST.LEVEL_ERROR
1136 assert log[
"type"] == action_type
1137 assert str(log[
"action_id"]) == str(action_id)
1138 assert log[
"message"] == action_test_message
1139 assert str(log[
"code"]) == str(action_code)
1140 assert log[
"level"] == action_level
1141 assert str(log[
"resolved"]) == str(int(action_resolved))
1146 Function in charge of testing the log_event function.
1148 title =
"test_get_logs_critical"
1150 action_id = TEST_INFO[
"action_id"]
1151 action_type = ACONST.TYPE_ACTION
1152 action_test_message =
"This is a test message"
1153 action_resolved =
True
1155 for code
in ACONST.LIST_CODE:
1156 status = ACLI.log_event(
1157 log_type=action_type,
1158 action_id=action_id,
1160 message=action_test_message,
1161 resolved=action_resolved,
1167 log_ids[code] = node[
'id']
1169 msg =
"Failed to log the event."
1170 TCONST.IDISP.log_error(msg, title)
1173 assert status != ERROR
1174 TCONST.IDISP.log_debug(f
"Log ids = {log_ids}", title)
1175 user_logs = ACLI.get_logs_critical(
1176 action_id=action_id, beautify=
True
1178 print(f
"Gathered user logs = {user_logs}", title)
1181 TCONST.IDISP.log_debug(f
"logs = {user_logs}", title)
1182 for log
in user_logs:
1183 action_code = ACONST.CODE_CRITICAL
1184 action_level = ACONST.LEVEL_CRITICAL
1185 assert log[
"type"] == action_type
1186 assert str(log[
"action_id"]) == str(action_id)
1187 assert log[
"message"] == action_test_message
1188 assert str(log[
"code"]) == str(action_code)
1189 assert log[
"level"] == action_level
1190 assert str(log[
"resolved"]) == str(int(action_resolved))
1195 Function in charge of testing the log_event function.
1197 title =
"test_get_logs_fatal"
1199 action_id = TEST_INFO[
"action_id"]
1200 action_type = ACONST.TYPE_ACTION
1201 action_test_message =
"This is a test message"
1202 action_resolved =
True
1204 for code
in ACONST.LIST_CODE:
1205 status = ACLI.log_event(
1206 log_type=action_type,
1207 action_id=action_id,
1209 message=action_test_message,
1210 resolved=action_resolved,
1216 log_ids[code] = node[
'id']
1218 msg =
"Failed to log the event."
1219 TCONST.IDISP.log_error(msg, title)
1222 assert status != ERROR
1223 TCONST.IDISP.log_debug(f
"Log ids = {log_ids}", title)
1224 user_logs = ACLI.get_logs_fatal(
1225 action_id=action_id, beautify=
True
1227 print(f
"Gathered user logs = {user_logs}", title)
1230 TCONST.IDISP.log_debug(f
"logs = {user_logs}", title)
1231 for log
in user_logs:
1232 action_code = ACONST.CODE_FATAL
1233 action_level = ACONST.LEVEL_FATAL
1234 assert log[
"type"] == action_type
1235 assert str(log[
"action_id"]) == str(action_id)
1236 assert log[
"message"] == action_test_message
1237 assert str(log[
"code"]) == str(action_code)
1238 assert log[
"level"] == action_level
1239 assert str(log[
"resolved"]) == str(int(action_resolved))
None test_get_logs_debug()
None test_log_event_unknown()
None test_log_event_debug()
None _remove_log_line(Union[int, Dict[str, int]] log_id)
None _remove_dummy_user()
None test_log_event_info()
None test_get_logs_info()
None test_get_logs_unknown()
None test_log_event_fatal()
None test_log_event_error()
None test_log_event_warning()
None test_log_event_critical()
Dict[str, Any] _get_log_lines(str action_id="")
None test_log_event_success()
None test_get_logs_critical()
None _remove_dummy_action()
None test_get_logs_fatal()
None test_get_logs_warning()
None test_get_logs_success()
None test_get_logs_error()