diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-08-29 16:56:11 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-09-01 10:32:52 +0200 |
commit | 9666ede3c0f72fb1d8ccd38d3c957980b2f28efa (patch) | |
tree | f41266cb86c16edfbc94f1b78d9c63c9da3daf16 /ishtar_common/tests.py | |
parent | f61a128adca4cc9f8df3557d149137145a0d5885 (diff) | |
download | Ishtar-9666ede3c0f72fb1d8ccd38d3c957980b2f28efa.tar.bz2 Ishtar-9666ede3c0f72fb1d8ccd38d3c957980b2f28efa.zip |
Restoration: check version
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r-- | ishtar_common/tests.py | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 25be97692..03c2ad03a 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -25,8 +25,9 @@ import io import json import os import shutil -from io import StringIO +import tempfile import zipfile +from io import StringIO from django.apps import apps @@ -49,7 +50,8 @@ from ishtar_common import models from ishtar_common import views from ishtar_common.apps import admin_site from ishtar_common.serializers import type_serialization, \ - SERIALIZATION_VERSION + SERIALIZATION_VERSION, get_model_from_filename, serialization_info, \ + restore_serialized from ishtar_common.utils import post_save_geo, update_data, move_dict_data, \ rename_and_simplify_media_name, try_fix_file @@ -613,7 +615,21 @@ class SerializationTest(TestCase): self.assertIsNone(zip_file.testzip()) info = json.loads(zip_file.read("info.json").decode("utf-8")) self.assertEqual(info["serialize-version"], SERIALIZATION_VERSION) - print(info) + + def test_restore_version(self): + zip_filename = type_serialization(archive=True) + with tempfile.TemporaryDirectory() as tmpdirname: + with zipfile.ZipFile(zip_filename, "w") as zip_file: + base_filename = "info.json" + filename = tmpdirname + os.sep + base_filename + with open(filename, "w") as json_file: + info = serialization_info() + info["serialize-version"] = "-42" + json_file.write(json.dumps(info, indent=2)) + + zip_file.write(filename, arcname=base_filename) + with self.assertRaises(ValueError): + restore_serialized(zip_filename) def test_type_restore(self): zip_filename = type_serialization(archive=True) @@ -623,15 +639,9 @@ class SerializationTest(TestCase): path = json_filename.split(os.sep) if len(path) != 2 or path[0] != "types": continue - filename = path[-1].split(".")[0] - module_name, model_name = filename.split("__") - module = importlib.import_module(module_name + ".models") - model = getattr(module, model_name) + model = get_model_from_filename(path[-1]) initial_count[json_filename] = model.objects.count() model.objects.all().delete() - print(initial_count) - - class AccessControlTest(TestCase): |