Newer
Older
from shapely.geometry import Polygon, LineString
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() -> 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)]]
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