diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2015-01-26 11:52:36 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2015-01-26 11:52:36 +0100 |
commit | f468cb6bc7bde671b78c076daaf73a92a8f33a69 (patch) | |
tree | d3911ac791217dc5a0ff556afce9743067d1cd1e /ishtar_common/tests.py | |
parent | fea70ced145dcfd326c8846bffa0004009c8daa4 (diff) | |
download | Ishtar-f468cb6bc7bde671b78c076daaf73a92a8f33a69.tar.bz2 Ishtar-f468cb6bc7bde671b78c076daaf73a92a8f33a69.zip |
GeneralType keys: add importer field for specific key association - better management of keys
* new importer field definition and creation
* manage manual association of keys
* manage overload of keys
* manage automatic deletion of keys
* change ImportFormater for new management of keys
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r-- | ishtar_common/tests.py | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 000abc268..b22d27169 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2014 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2015 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -21,6 +21,8 @@ import tempfile from zipfile import ZipFile, ZIP_DEFLATED from django.contrib.auth.models import User +from django.contrib.contenttypes.models import ContentType +from django.template.defaultfilters import slugify from django.test import TestCase from ishtar_common import models, ooo_replace @@ -91,3 +93,46 @@ class MergeTest(TestCase): self.person_3.merge(self.person_1) # manage well empty many to many fields self.assertTrue(self.person_types[1] in self.person_3.person_types.all()) + +class ImportKeyTest(TestCase): + + def testKeys(self): + content_type = ContentType.objects.get_for_model(models.OrganizationType) + + # creation + label = u"Ploufé" + ot = models.OrganizationType.objects.create(label=label) + self.assertEqual(models.ItemKey.objects.filter(object_id=ot.pk, + key=slugify(label), + content_type=content_type).count(), 1) + label_2 = u"Plif" + ot_2 = models.OrganizationType.objects.create(label=label_2) + self.assertEqual(models.ItemKey.objects.filter(object_id=ot_2.pk, + key=slugify(label_2), + content_type=content_type).count(), 1) + + # replace key + ot_2.add_key(slugify(label), force=True) + # one key point to only one item + self.assertEqual(models.ItemKey.objects.filter(key=slugify(label), + content_type=content_type).count(), 1) + # this key point to the right item + self.assertEqual(models.ItemKey.objects.filter(object_id=ot_2.pk, + key=slugify(label), content_type=content_type).count(), 1) + + # modification + label_3 = "Yop" + ot_2.label = label_3 + ot_2.save() + # old label not referenced anymore + self.assertEqual(models.ItemKey.objects.filter(object_id=ot_2.pk, + key=slugify(label_2), content_type=content_type).count(), 0) + # forced key association is always here + self.assertEqual(models.ItemKey.objects.filter(object_id=ot_2.pk, + key=slugify(label), content_type=content_type).count(), 1) + # new key is here + self.assertEqual(models.ItemKey.objects.filter(object_id=ot_2.pk, + key=slugify(label_3), content_type=content_type).count(), 1) + + + |