From ff4870730ab30466449c15c669a539bf7fd67ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Mon, 26 Feb 2024 11:44:23 +0100 Subject: [PATCH] chore: ensure old-format layers' versions are returned --- umap/models.py | 5 ++++- umap/tests/test_datalayer_views.py | 36 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/umap/models.py b/umap/models.py index 8257c8cb..f10fc876 100644 --- a/umap/models.py +++ b/umap/models.py @@ -449,7 +449,10 @@ class DataLayer(NamedModel): return new def is_valid_version(self, name): - return name.startswith("%s_" % self.pk) and name.endswith(".geojson") + valid_prefixes = [name.startswith("%s_" % self.pk)] + if self.id: + valid_prefixes.append(name.startswith("%s_" % self.id)) + return any(valid_prefixes) and name.endswith(".geojson") def version_metadata(self, name): els = name.split(".")[0].split("_") diff --git a/umap/tests/test_datalayer_views.py b/umap/tests/test_datalayer_views.py index c06f7d20..5cab92aa 100644 --- a/umap/tests/test_datalayer_views.py +++ b/umap/tests/test_datalayer_views.py @@ -225,6 +225,42 @@ def test_versions_should_return_versions(client, datalayer, map, settings): assert version in versions["versions"] +def test_versions_can_return_old_format(client, datalayer, map, settings): + map.share_status = Map.PUBLIC + map.save() + root = datalayer.storage_root() + datalayer.id = 123 # old datalayer id (now replaced by uuid) + datalayer.save() + + datalayer.geojson.storage.save( + "%s/%s_1440924889.geojson" % (root, datalayer.pk), ContentFile("{}") + ) + datalayer.geojson.storage.save( + "%s/%s_1440923687.geojson" % (root, datalayer.pk), ContentFile("{}") + ) + + # store with the id prefix (rather than the uuid) + old_format_version = "%s_1440918637.geojson" % (datalayer.id) + datalayer.geojson.storage.save( + ("%s/" % root) + old_format_version, ContentFile("{}") + ) + + url = reverse("datalayer_versions", args=(map.pk, datalayer.pk)) + versions = json.loads(client.get(url).content.decode()) + assert len(versions["versions"]) == 4 + version = { + "name": old_format_version, + "size": 2, + "at": "1440918637", + } + assert version in versions["versions"] + + # Check we can access the old format + client.get( + reverse("datalayer_version", args=(map.pk, datalayer.pk, old_format_version)) + ) + + def test_version_should_return_one_version_geojson(client, datalayer, map): map.share_status = Map.PUBLIC map.save()