summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
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
commitb095faf494f3b8599f22db27ec19d12fa8508037 (patch)
tree445db0a06f6bb425b81e4902f4e796ae9d7cf54b /ishtar_common
parent7722226080b8a248a7e63699fe01e64466011253 (diff)
downloadIshtar-b095faf494f3b8599f22db27ec19d12fa8508037.tar.bz2
Ishtar-b095faf494f3b8599f22db27ec19d12fa8508037.zip
Serializers: test all types
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/serializers.py10
-rw-r--r--ishtar_common/tests.py25
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")