diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/serializers.py | 22 | ||||
-rw-r--r-- | ishtar_common/tests.py | 24 |
2 files changed, 42 insertions, 4 deletions
diff --git a/ishtar_common/serializers.py b/ishtar_common/serializers.py index 6d25efdb6..03433df89 100644 --- a/ishtar_common/serializers.py +++ b/ishtar_common/serializers.py @@ -161,7 +161,7 @@ def generic_get_results(model_list, dirname, no_geo=True): new_result += result_to_add result[key] = json.dumps(new_result, indent=2) - excluded_fields = [] + excluded_fields = ["history_modifier", "history_creator"] if hasattr(model, "SERIALIZATION_EXCLUDE"): excluded_fields = list(model.SERIALIZATION_EXCLUDE) if no_geo: @@ -269,6 +269,20 @@ def geo_serialization(archive=False, return_empty_types=False, return full_archive +DIRECTORY_MODEL_LIST = [ + models.Organization, models.Person, models.Author +] + + +def directory_serialization(archive=False, return_empty_types=False, + archive_name=None): + result = generic_get_results(DIRECTORY_MODEL_LIST, "common_directory") + full_archive = archive_serialization( + result, archive_dir="common_directory", archive=archive, + return_empty_types=return_empty_types, archive_name=archive_name) + return full_archive + + def restore_serialized(archive_name, delete_existing=False): with zipfile.ZipFile(archive_name, "r") as zip_file: # check version @@ -280,9 +294,11 @@ def restore_serialized(archive_name, delete_existing=False): ) DIRS = ( - ("types", [None]), ("common_configuration", CONF_MODEL_LIST), + ("types", [None]), + ("common_configuration", CONF_MODEL_LIST), ("common_imports", IMPORT_MODEL_LIST), - ("common_geo", GEO_MODEL_LIST) + ("common_geo", GEO_MODEL_LIST), + ("common_directory", DIRECTORY_MODEL_LIST), ) namelist = zip_file.namelist() for current_dir, model_list in DIRS: diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index efa0188ff..99840ddaa 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -53,7 +53,8 @@ from ishtar_common.apps import admin_site from ishtar_common.serializers import type_serialization, \ SERIALIZATION_VERSION, serialization_info, \ restore_serialized, conf_serialization, CONF_MODEL_LIST, \ - importer_serialization, IMPORT_MODEL_LIST, geo_serialization, GEO_MODEL_LIST + importer_serialization, IMPORT_MODEL_LIST, geo_serialization, \ + GEO_MODEL_LIST, directory_serialization, DIRECTORY_MODEL_LIST from ishtar_common.utils import post_save_geo, update_data, move_dict_data, \ rename_and_simplify_media_name, try_fix_file @@ -681,6 +682,20 @@ class SerializationTest(TestCase): self.create_geo_default() self.generic_serialization_test(geo_serialization) + def create_directory_default(self): + org = models.Organization.objects.create( + name="Test", + organization_type=models.OrganizationType.objects.all()[0]) + person = models.Person.objects.create( + name="Test", attached_to=org + ) + models.Author.objects.create( + person=person, author_type=models.AuthorType.objects.all()[0]) + + def test_directory_serialization(self): + self.create_directory_default() + self.generic_serialization_test(directory_serialization) + def test_serialization_zip(self): zip_filename = type_serialization(archive=True) # only check the validity of the zip, the type content is tested above @@ -787,6 +802,13 @@ class SerializationTest(TestCase): # no geo restore self.assertFalse(models.Town.objects.get(numero_insee="12345").center) + def test_directory_restore(self): + self.create_directory_default() + current_number, zip_filename = self.generic_restore_test_genzip( + DIRECTORY_MODEL_LIST, directory_serialization) + self.generic_restore_test(zip_filename, current_number, + DIRECTORY_MODEL_LIST) + class AccessControlTest(TestCase): def test_administrator(self): |