Better way to set DataLayer.geojson content during tests
This commit is contained in:
parent
9cf2bf1578
commit
e0e7fc5844
1 changed files with 7 additions and 10 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue