chore: ensure old-format layers' versions are returned

This commit is contained in:
Alexis Métaireau 2024-02-26 11:44:23 +01:00
parent 99d7b8a6e1
commit ff4870730a
2 changed files with 40 additions and 1 deletions

View file

@ -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("_")

View file

@ -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()