diff --git a/src/pcapi/utils/pcapi_upgrade.py b/src/pcapi/utils/pcapi_upgrade.py index 021c018..f61714b 100644 --- a/src/pcapi/utils/pcapi_upgrade.py +++ b/src/pcapi/utils/pcapi_upgrade.py @@ -40,6 +40,15 @@ def rec2geojson(record): res["properties"] = record return res +def updateEditorExtension(record): + """ + updates the editor to be from .edtr to .json + """ + if record["properties"]["editor"].endswith(".edtr"): + record["properties"]["editor"] = record["properties"]["editor"].replace(".edtr", ".json") + return record + return None + def updateIdInGeojson(record): """ updates id of each field of the geojson to follow the updated format @@ -73,6 +82,13 @@ def upgrade_all_data(): print "Overwriting new version of %s" % f with open(f,'w') as fp: json.dump(new_gj,fp) + gj_new_ed_ext = updateEditorExtension(new_gj) + if not gj_new_ed_ext: + print "Ignoring %s which is already converted." % f + else: + print "Overwriting new version of %s" % f + with open(f,'w') as fp: + json.dump(gj_new_ed_ext,fp) if __name__ == "__main__": upgrade_all_data() diff --git a/src/test/upgrade_data.py b/src/test/upgrade_data.py index c4bce27..f1add7b 100644 --- a/src/test/upgrade_data.py +++ b/src/test/upgrade_data.py @@ -21,7 +21,7 @@ from pcapi.server import application from pcapi import config -from pcapi.utils.pcapi_upgrade import find_json, updateIdInGeojson +from pcapi.utils.pcapi_upgrade import find_json, updateIdInGeojson, updateEditorExtension userid = "testexport@domain.co.uk" @@ -47,3 +47,11 @@ def test_updateIdInGeojson(self): new_record = updateIdInGeojson(record) self.assertEquals(new_record["properties"]["fields"][0]["id"], record["properties"]["fields"][0]["id"].replace("fieldcontain-", "")) + + def test_updateEditorExtension(self): + """ read geojson and check if editor extension has changed""" + gen = find_json(envsys_records_dir) + record = json.load(open(gen.next())) + new_record = updateEditorExtension(record) + self.assertEquals(new_record["properties"]["editor"], + record["properties"]["editor"].replace(".edtr", ".json"))