diff --git a/swh/web/tests/views.py b/swh/web/tests/views.py --- a/swh/web/tests/views.py +++ b/swh/web/tests/views.py @@ -17,7 +17,6 @@ from swh.model.hashutil import hash_to_hex from swh.model.model import Content from swh.web.common.highlightjs import get_hljs_language_from_filename -from swh.web.config import get_config from swh.web.tests.data import get_tests_data _content_code_data_exts = {} # type: Dict[str, Dict[str, str]] @@ -68,9 +67,10 @@ a code content example. """ global _content_code_data_exts - _init_content_tests_data( - "resources/contents/code/extensions", _content_code_data_exts, True - ) + if not _content_code_data_exts: + _init_content_tests_data( + "resources/contents/code/extensions", _content_code_data_exts, True + ) def _init_content_other_data_exts(): @@ -79,9 +79,10 @@ a content example. """ global _content_other_data_exts - _init_content_tests_data( - "resources/contents/other/extensions", _content_other_data_exts, True - ) + if not _content_other_data_exts: + _init_content_tests_data( + "resources/contents/other/extensions", _content_other_data_exts, True + ) def _init_content_code_data_filenames(): @@ -90,15 +91,10 @@ a content example. """ global _content_code_data_filenames - _init_content_tests_data( - "resources/contents/code/filenames", _content_code_data_filenames, False - ) - - -if get_config()["e2e_tests_mode"]: - _init_content_code_data_exts() - _init_content_other_data_exts() - _init_content_code_data_filenames() + if not _content_code_data_filenames: + _init_content_tests_data( + "resources/contents/code/filenames", _content_code_data_filenames, False + ) @api_view(["GET"]) @@ -107,6 +103,7 @@ Endpoint implementation returning a list of all source file extensions to test for highlighting using cypress. """ + _init_content_code_data_exts() return Response( sorted(_content_code_data_exts.keys()), status=200, @@ -122,6 +119,7 @@ """ data = None status = 404 + _init_content_code_data_exts() if ext in _content_code_data_exts: data = _content_code_data_exts[ext] status = 200 @@ -149,6 +147,7 @@ Endpoint implementation returning a list of all source filenames to test for highlighting using cypress. """ + _init_content_code_data_filenames() return Response( sorted(_content_code_data_filenames.keys()), status=200, @@ -164,6 +163,7 @@ """ data = None status = 404 + _init_content_code_data_filenames() if filename in _content_code_data_filenames: data = _content_code_data_filenames[filename] status = 200