|
4 | 4 |
|
5 | 5 | # Third party imports |
6 | 6 | import flask |
| 7 | +import shutil |
7 | 8 |
|
8 | 9 | # Local application imports |
9 | 10 | from src.opengeodeweb_back import geode_functions, utils_functions |
@@ -71,6 +72,44 @@ def test_handle_exception(client): |
71 | 72 | assert type(data["code"]) is int |
72 | 73 |
|
73 | 74 |
|
| 75 | +def test_create_unique_data_folder(): |
| 76 | + base_data_folder = "./tests/data" |
| 77 | + generated_id, data_path = utils_functions.create_unique_data_folder(base_data_folder) |
| 78 | + assert isinstance(generated_id, str) |
| 79 | + assert re.fullmatch(r"[0-9a-f]{32}", generated_id), "ID should be 32 hex characters" |
| 80 | + assert os.path.exists(data_path) |
| 81 | + assert data_path.startswith(base_data_folder) |
| 82 | + assert generated_id in data_path |
| 83 | + shutil.rmtree(data_path, ignore_errors=True) |
| 84 | + assert not os.path.exists(data_path) |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +def test_save_all_viewables_and_return_info(client): |
| 89 | + app = client.application |
| 90 | + with app.app_context(): |
| 91 | + geode_object = "BRep" |
| 92 | + data = geode_functions.load(geode_object, "./tests/data/test.og_brep") |
| 93 | + generated_id, data_path = utils_functions.create_unique_data_folder( |
| 94 | + flask.current_app.config["DATA_FOLDER_PATH"] |
| 95 | + ) |
| 96 | + additional_files = ["additional_file.txt"] |
| 97 | + |
| 98 | + result = utils_functions.save_all_viewables_and_return_info( |
| 99 | + geode_object, data, generated_id, data_path, additional_files |
| 100 | + ) |
| 101 | + |
| 102 | + assert isinstance(result, dict) |
| 103 | + assert result["name"] == data.name() |
| 104 | + assert result["native_file_name"].startswith("native.") |
| 105 | + assert result["viewable_file_name"].endswith(".vtm") |
| 106 | + assert re.match(r"[0-9a-f]{32}", result["id"]) |
| 107 | + assert isinstance(result["object_type"], str) |
| 108 | + assert isinstance(result["binary_light_viewable"], str) |
| 109 | + assert result["geode_object"] == geode_object |
| 110 | + assert result["input_files"] == additional_files |
| 111 | + |
| 112 | + |
74 | 113 | def test_generate_native_viewable_and_light_viewable_from_object(client): |
75 | 114 | app = client.application |
76 | 115 | with app.app_context(): |
|
0 commit comments