summaryrefslogtreecommitdiff
path: root/archaeological_operations/tests.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-09-19 11:37:42 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-09-19 11:37:42 +0200
commit782b857248435767cc4868a472ce27211596614a (patch)
tree8b0099c79567f3aa32a222a1ecbf6fd17e686b9a /archaeological_operations/tests.py
parent37ad2699ac330364895d58a5fcbf4300998f370c (diff)
downloadIshtar-782b857248435767cc4868a472ce27211596614a.tar.bz2
Ishtar-782b857248435767cc4868a472ce27211596614a.zip
Importers: fix user target key management (refs #3725)
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r--archaeological_operations/tests.py54
1 files changed, 42 insertions, 12 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 0d17acb8b..60078b7e2 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -25,6 +25,7 @@ import zipfile
from django.conf import settings
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.urlresolvers import reverse
+from django.db.models import Q
from django.test.client import Client
from django.contrib.auth.models import User
@@ -125,6 +126,11 @@ class ImportTest(object):
def init_ope_targetkey(self, imp):
# doing manually connections
+ q = Q(importer=imp) | Q(user=imp.user)
+ if imp.associated_group:
+ q |= Q(group=imp.associated_group)
+ for ik in ItemKey.objects.filter(q).all():
+ ik.delete()
# target for this import
target = TargetKey.objects.filter(
@@ -136,39 +142,56 @@ class ImportTest(object):
target.save()
# target for all users
- target2 = TargetKey.objects.get(key='gallo-romain')
+ tgs = list(TargetKey.objects.filter(key='gallo-romain').all())
+ for tg in tgs[1:]:
+ tg.delete()
+ target2 = tgs[0]
gallo = models.Period.objects.get(txt_idx='gallo-roman')
target2.value = gallo.pk
target2.is_set = True
target2.associated_import = None
+ target2.associated_group = None
+ target2.associated_user = None
target2.save()
# target for this user
- target3 = TargetKey.objects.get(key='age-du-fer')
+ tgs = list(TargetKey.objects.filter(key='age-du-fer').all())
+ for tg in tgs[1:]:
+ tg.delete()
+ target3 = tgs[0]
iron = models.Period.objects.get(txt_idx='iron_age')
target3.value = iron.pk
target3.is_set = True
target3.associated_import = None
target3.associated_user = self.ishtar_user
+ target3.associated_group = None
target3.save()
# target for another user
username, password, user = create_user()
another_user = IshtarUser.objects.get(pk=user.pk)
- target4 = TargetKey.objects.get(key='neolithique')
+ tgs = list(TargetKey.objects.filter(key='neolithik').all())
+ for tg in tgs[1:]:
+ tg.delete()
+ target4 = tgs[0]
neo = models.Period.objects.get(txt_idx='neolithic')
target4.value = neo.pk
target4.is_set = True
target4.associated_import = None
+ target4.associated_group = None
target4.associated_user = another_user
target4.save()
# target for the current group
- target5 = TargetKey.objects.get(key='moderne')
+ tgs = list(TargetKey.objects.filter(key='moderne').all())
+ for tg in tgs[1:]:
+ tg.delete()
+ target5 = tgs[0]
modern = models.Period.objects.get(txt_idx='modern')
target5.value = modern.pk
target5.is_set = True
target5.associated_import = None
+ target5.associated_user = None
target5.associated_group = imp.associated_group
target5.save()
@@ -271,13 +294,12 @@ class ImportOperationTest(ImportTest, TestCase):
self.assertEqual(last_ope.code_patriarche, '4200')
self.assertEqual(last_ope.operation_type.txt_idx, 'prog_excavation')
- # self.assertEqual(last_ope.periods.count(), 3)
- self.assertEqual(last_ope.periods.count(), 4)
+ self.assertEqual(last_ope.periods.count(), 3)
periods = [period.txt_idx for period in last_ope.periods.all()]
self.assertIn('iron_age', periods)
self.assertIn('gallo-roman', periods)
# target key set for another user
- # self.assertNotIn('neolithic', periods)
+ self.assertNotIn('neolithic', periods)
# a second importation will be not possible: no two same patriarche
# code
@@ -298,12 +320,20 @@ class ImportOperationTest(ImportTest, TestCase):
importer, form = self.init_ope_import()
other_imp = form.save(self.ishtar_user)
- # associate with another import
- for ik in ItemKey.objects.filter(importer=impt).all():
- ik.importer = other_imp
- ik.save()
- for tg in TargetKey.objects.filter(associated_import=impt).all():
+ # re-associate with another import
+ q = Q(importer=impt) | Q(user=impt.user)
+ if impt.associated_group:
+ q |= Q(group=impt.associated_group)
+ for ik in ItemKey.objects.filter(q).all():
+ ik.delete()
+
+ q = Q(associated_import=impt) | Q(associated_user=impt.user)
+ if impt.associated_group:
+ q |= Q(associated_group=impt.associated_group)
+ for tg in TargetKey.objects.filter(q).all():
+ tg.associated_user = None
+ tg.associated_group = None
tg.associated_import = other_imp
tg.save()