Better way to set DataLayer.geojson content during tests

This commit is contained in:
Yohan Boniface 2023-09-25 13:40:01 +02:00
parent 9cf2bf1578
commit e0e7fc5844

View file

@ -103,17 +103,14 @@ class DataLayerFactory(factory.django.DjangoModelFactory):
description = "test description" description = "test description"
display_on_load = True display_on_load = True
settings = {"displayOnLoad": True, "browsable": True, "name": name} settings = {"displayOnLoad": True, "browsable": True, "name": name}
geojson = factory.django.FileField()
@factory.post_generation @classmethod
def geojson_data(obj, create, extracted, **kwargs): def _adjust_kwargs(cls, **kwargs):
# Make sure DB settings and file settings are aligned. data = kwargs.pop("data", DATALAYER_DATA).copy()
# At some point, file settings should be removed, but we are not there yet. kwargs["settings"]["name"] = kwargs["name"]
data = DATALAYER_DATA.copy() data["_umap_options"] = kwargs["settings"]
obj.settings["name"] = obj.name kwargs["geojson"] = ContentFile(json.dumps(data), "foo.json")
data["_umap_options"] = obj.settings return kwargs
with open(obj.geojson.path, mode="w") as f:
f.write(json.dumps(data))
class Meta: class Meta:
model = DataLayer model = DataLayer