diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-09-06 11:20:52 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-09-06 11:20:52 +0200 |
commit | 2b53f8c6b5e685b501f2b180bd0000d72ac4016f (patch) | |
tree | 445db0a06f6bb425b81e4902f4e796ae9d7cf54b /ishtar_common | |
parent | d0c41db15d9bc583a639a6f46b9376092dda1e11 (diff) | |
download | Ishtar-2b53f8c6b5e685b501f2b180bd0000d72ac4016f.tar.bz2 Ishtar-2b53f8c6b5e685b501f2b180bd0000d72ac4016f.zip |
Serializers: test all types
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/serializers.py | 10 | ||||
-rw-r--r-- | ishtar_common/tests.py | 25 |
2 files changed, 28 insertions, 7 deletions
diff --git a/ishtar_common/serializers.py b/ishtar_common/serializers.py index 409051ec0..8dca370f5 100644 --- a/ishtar_common/serializers.py +++ b/ishtar_common/serializers.py @@ -166,7 +166,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 = ["history_modifier", "history_creator"] + excluded_fields = ["history_modifier", "history_creator", "imports"] if hasattr(model, "SERIALIZATION_EXCLUDE"): excluded_fields = list(model.SERIALIZATION_EXCLUDE) if no_geo: @@ -206,11 +206,15 @@ def generic_archive_files(model_list, archive_name=None): return archive_name +TYPE_MODEL_EXCLUDE = ["Area", "OperationTypeOld"] + + def type_serialization(archive=False, return_empty_types=False, archive_name=None): TYPE_MODEL_LIST = [ model for model in apps.get_models() - if isinstance(model(), models.GeneralType) + if isinstance(model(), models.GeneralType) and ( + model.__name__ not in TYPE_MODEL_EXCLUDE) ] result = generic_get_results(TYPE_MODEL_LIST, "types") return archive_serialization(result, archive_dir="types", archive=archive, @@ -261,7 +265,7 @@ def importer_serialization(archive=False, return_empty_types=False, GEO_MODEL_LIST = [ - models.State, models.Department, models.Town + models.State, models.Department, models.Town, models.Area ] diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index aa67d2e6b..9c7beb28a 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -614,10 +614,15 @@ class GenericSerializationTest: result = json.loads(json_result[key]) serialization_count = len(result) # all serialization have to be tested - self.assertTrue(serialization_count) + self.assertTrue(serialization_count, + msg="No data to test for {}".format(key)) # only "natural" serialization - self.assertNotIn("pk", result[0]) - self.assertNotIn("id", result[0]) + self.assertNotIn( + "pk", result[0], + msg="Serialization for {} do not use natural keys".format(key)) + self.assertNotIn( + "id", result[0], + msg="Serialization for {} do not use natural keys".format(key)) # has to be at least equal (can be superior for model with # recursion) self.assertTrue( @@ -652,12 +657,23 @@ class GenericSerializationTest: class SerializationTest(GenericSerializationTest, TestCase): fixtures = COMMON_FIXTURES + WAREHOUSE_FIXTURES + def create_types(self): + from archaeological_finds.models import MaterialTypeQualityType, \ + ObjectTypeQualityType, AlterationType, AlterationCauseType, \ + TreatmentEmergencyType, CommunicabilityType + for model in (models.LicenseType, MaterialTypeQualityType, + ObjectTypeQualityType, AlterationType, + AlterationCauseType, TreatmentEmergencyType, + CommunicabilityType): + model.objects.create(txt_idx="test", label="Test") + def test_type_serialization(self): + self.create_types() self.generic_serialization_test(type_serialization) def create_default_conf(self): values = {} - models.get_current_profile() # create a default profile + models.get_current_profile(force=True) # create a default profile models.GlobalVar.objects.create(slug="test") cform = models.CustomForm.objects.create( name="Test", form='ishtar_common.forms.TestForm') @@ -758,6 +774,7 @@ class SerializationTest(GenericSerializationTest, TestCase): from archaeological_operations.models import RelationType as OperationRT cr_rel_type_nb = CRRT.objects.count() ope_rel_type_nb = OperationRT.objects.count() + self.create_types() models.AuthorType.objects.create(label="Test", txt_idx="test") |