diff options
Diffstat (limited to 'ishtar_common/tests.py')
| -rw-r--r-- | ishtar_common/tests.py | 67 | 
1 files changed, 48 insertions, 19 deletions
| diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 7be176c05..efa0188ff 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -53,7 +53,7 @@ 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 +    importer_serialization, IMPORT_MODEL_LIST, geo_serialization, GEO_MODEL_LIST  from ishtar_common.utils import post_save_geo, update_data, move_dict_data, \      rename_and_simplify_media_name, try_fix_file @@ -661,6 +661,26 @@ class SerializationTest(TestCase):          self.create_default_importer()          self.generic_serialization_test(importer_serialization) +    def create_geo_default(self): +        s = models.State.objects.create(label="test", number="999") +        d = models.Department.objects.create(label="test", number="999", +                                             state=s) +        t1 = models.Town.objects.create( +            name="Test town", +            center="SRID=4326;POINT(-44.3 60.1)", +            numero_insee="12345", departement=d +        ) +        t2 = models.Town.objects.create( +            name="Test town 2", +            center="SRID=4326;POINT(-44.2 60.2)", +            numero_insee="12346", departement=d +        ) +        t2.children.add(t1) + +    def test_geo_serialization(self): +        self.create_geo_default() +        self.generic_serialization_test(geo_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 @@ -723,40 +743,49 @@ class SerializationTest(TestCase):          self.assertTrue(OperationRT.objects.filter(              inverse_relation__isnull=False).count()) -    def test_conf_restore(self): -        values = self.create_default_conf() +    def generic_restore_test_genzip(self, model_list, serialization):          current_number = {} -        for model in CONF_MODEL_LIST: +        for model in model_list:              current_number[model.__name__] = model.objects.count() -        zip_filename = conf_serialization(archive=True) -        os.remove(values["document_template"].template.path) +        zip_filename = serialization(archive=True) +        return current_number, zip_filename +    def generic_restore_test(self, zip_filename, current_number, model_list):          restore_serialized(zip_filename, delete_existing=True) -        for model in CONF_MODEL_LIST: +        for model in model_list:              previous_nb = current_number[model.__name__]              current_nb = model.objects.count()              self.assertEqual(                  previous_nb, current_nb,                  msg="Restore for model {} failed. Initial: {}, restored: "                      "{}.".format(model.__name__, previous_nb, current_nb)) + +    def test_conf_restore(self): +        values = self.create_default_conf() +        current_number, zip_filename = self.generic_restore_test_genzip( +            CONF_MODEL_LIST, conf_serialization) +        os.remove(values["document_template"].template.path) +        self.generic_restore_test(zip_filename, current_number, CONF_MODEL_LIST)          self.assertTrue(              os.path.isfile(values["document_template"].template.path)          )      def test_importer_restore(self):          self.create_default_importer() -        current_number = {} -        for model in IMPORT_MODEL_LIST: -            current_number[model.__name__] = model.objects.count() -        zip_filename = importer_serialization(archive=True) -        restore_serialized(zip_filename, delete_existing=True) -        for model in IMPORT_MODEL_LIST: -            previous_nb = current_number[model.__name__] -            current_nb = model.objects.count() -            self.assertEqual( -                previous_nb, current_nb, -                msg="Restore for model {} failed. Initial: {}, restored: " -                    "{}.".format(model.__name__, previous_nb, current_nb)) +        current_number, zip_filename = self.generic_restore_test_genzip( +            IMPORT_MODEL_LIST, importer_serialization) +        self.generic_restore_test(zip_filename, current_number, +                                  IMPORT_MODEL_LIST) + +    def test_geo_restore(self): +        self.create_geo_default() +        self.assertTrue(models.Town.objects.get(numero_insee="12345").center) +        current_number, zip_filename = self.generic_restore_test_genzip( +            GEO_MODEL_LIST, geo_serialization) +        self.generic_restore_test(zip_filename, current_number, +                                  GEO_MODEL_LIST) +        # no geo restore +        self.assertFalse(models.Town.objects.get(numero_insee="12345").center)  class AccessControlTest(TestCase): | 
