diff --git a/.coverage b/.coverage new file mode 100644 index 0000000000000000000000000000000000000000..947808bfdf95dfe02c7c8f3a2eb95b8642601207 Binary files /dev/null and b/.coverage differ diff --git a/server/map_handler/lake_relations/all_lake_names.json b/server/map_handler/lake_relations/all_lake_names.json index d1d3eb65a68c73e21a9996a2dbd03764de9777ac..2cf061bdda6b9fd504061d949daea14bd82ca10b 100644 --- a/server/map_handler/lake_relations/all_lake_names.json +++ b/server/map_handler/lake_relations/all_lake_names.json @@ -1,4 +1,5 @@ [ "Mjøsa", - "Skumsjøen" + "Skumsjøen", + "test_lake" ] \ No newline at end of file diff --git a/server/map_handler/lake_relations/test_lake_div.json b/server/map_handler/lake_relations/test_lake_div.json new file mode 100644 index 0000000000000000000000000000000000000000..653440158e2399415647e8d73637c1c6a78a00fb --- /dev/null +++ b/server/map_handler/lake_relations/test_lake_div.json @@ -0,0 +1 @@ +{"test-field1": "test-value1", "test-field2": ["test-value2", "testvalue3"]} \ No newline at end of file diff --git a/server/map_handler/unit_tests/__pycache__/test_add_new_lake.cpython-311-pytest-8.2.0.pyc b/server/map_handler/unit_tests/__pycache__/test_add_new_lake.cpython-311-pytest-8.2.0.pyc index 1f1035be606616e46806e57a11add5fc28a65bbd..c6733b1f387025c9507e38386f998e47bcb8bab2 100644 Binary files a/server/map_handler/unit_tests/__pycache__/test_add_new_lake.cpython-311-pytest-8.2.0.pyc and b/server/map_handler/unit_tests/__pycache__/test_add_new_lake.cpython-311-pytest-8.2.0.pyc differ diff --git a/server/map_handler/unit_tests/test_add_new_lake.py b/server/map_handler/unit_tests/test_add_new_lake.py index 8bde724889f7cf999af4c49f1a77632e36958798..2f7d4c6fb9aa4d3a6a7354920597bc77625d0c5e 100644 --- a/server/map_handler/unit_tests/test_add_new_lake.py +++ b/server/map_handler/unit_tests/test_add_new_lake.py @@ -1,16 +1,44 @@ +import json from shapely.geometry import Polygon, LineString -from server.map_handler.add_new_lake import create_grid +from server.consts import LAKE_RELATIONS_PATH +from server.map_handler.add_new_lake import create_grid, write_json_to_file -def test_create_grid_default(): +def test_create_grid_default() -> None: # Create a simple square polygon test_poly = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]) # Define the expected grid output coordinates = [[(0, 0), (0, 1)], [(0.5, 0), (0.5, 1)], [(1, 0), (1, 1)], - [(0, 0), (1, 0)], [(0, 0.4), (1, 0.4)], [(0, 0.8), (1, 0.8)]] + [(0, 0), (1, 0)], [(0, 0.4), (1, 0.4)], [(0, 0.8), (1, 0.8)]] expected = [LineString(coords) for coords in coordinates] grid = create_grid(test_poly, 0.5, 0.4) assert grid == expected + + +def test_write_json_to_file() -> None: + # Define some test data + test_lake_name = "test_lake" + test_data = { + 'test-field1': 'test-value1', + 'test-field2': [ + "test-value2", + "testvalue3" + ], + } + + # Call the function that is being tested + write_json_to_file(test_lake_name, test_data) + + # Try to read the data from the newly created file + with open(LAKE_RELATIONS_PATH + '/' + test_lake_name + '_div.json', 'r') as f: + result = json.load(f) + + assert result == test_data + + + + +