diff --git a/umap/tests/test_datalayer.py b/umap/tests/test_datalayer.py index 47bd63f7c..bb29c3d51 100644 --- a/umap/tests/test_datalayer.py +++ b/umap/tests/test_datalayer.py @@ -1,4 +1,3 @@ -import tempfile from pathlib import Path import pytest diff --git a/umap/tests/test_datalayer_views.py b/umap/tests/test_datalayer_views.py index 19c875ca9..9578ff530 100644 --- a/umap/tests/test_datalayer_views.py +++ b/umap/tests/test_datalayer_views.py @@ -1,6 +1,8 @@ import json from copy import deepcopy +from datetime import datetime, timedelta from pathlib import Path +from unittest import mock from uuid import uuid4 import pytest @@ -621,3 +623,17 @@ def test_optimistic_merge_conflicting_change_raises( modified_datalayer = DataLayer.objects.get(pk=datalayer.pk) merged_features = json.load(modified_datalayer.geojson)["features"] assert merged_features == client1_data["features"] + + +def test_saving_datalayer_should_change_map_last_modified( + client, datalayer, map, post_data +): + with mock.patch("django.utils.timezone.now") as mocked: + mocked.return_value = datetime.utcnow() - timedelta(days=8) + map.save() # Change last_modified to past + old_modified_at = map.modified_at.date() + url = reverse("datalayer_update", args=(map.pk, datalayer.pk)) + client.login(username=map.owner.username, password="123123") + response = client.post(url, post_data, follow=True) + assert response.status_code == 200 + assert Map.objects.get(pk=map.pk).modified_at.date() != old_modified_at diff --git a/umap/views.py b/umap/views.py index 08de5a7a3..8183b1c3c 100644 --- a/umap/views.py +++ b/umap/views.py @@ -1293,6 +1293,7 @@ def post(self, request, *args, **kwargs): def form_valid(self, form): self.object = form.save() + self.object.map.save(update_fields=["modified_at"]) data = {**self.object.metadata(self.request)} if self.request.session.get("needs_reload"): data["geojson"] = json.loads(self.object.geojson.read().decode())