summaryrefslogtreecommitdiff
path: root/ishtar_common/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r--ishtar_common/tests.py51
1 files changed, 44 insertions, 7 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index a4d354eb1..8c918b5a9 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2015 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2015-2016 É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
@@ -24,6 +24,7 @@ from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.core.cache import cache
from django.core.exceptions import ValidationError
+from django.core.files.base import File as DjangoFile
from django.core.urlresolvers import reverse
from django.template.defaultfilters import slugify
from django.test import TestCase
@@ -175,12 +176,14 @@ class MergeTest(TestCase):
self.author_1_pk = models.Author.objects.create(
person=self.person_1, author_type=self.author_types[0]).pk
+ self.title = models.TitleType.objects.create(label='Test')
+
self.company_2 = models.Organization.objects.create(
history_modifier=self.user, name='Goscinny Corp.',
organization_type=self.organisation_types[1])
self.person_2 = models.Person.objects.create(
name='Bill', history_modifier=self.user, surname='Peyo',
- title='Mr', attached_to=self.company_2)
+ title=self.title, attached_to=self.company_2)
self.person_2.person_types.add(self.person_types[1])
self.author_2_pk = models.Author.objects.create(
person=self.person_2, author_type=self.author_types[1]).pk
@@ -193,7 +196,7 @@ class MergeTest(TestCase):
# preserve existing fields
self.assertEqual(self.person_1.name, 'Boule')
# fill missing fields
- self.assertEqual(self.person_1.title, 'Mr')
+ self.assertEqual(self.person_1.title, self.title)
# string field with only spaces is an empty field
self.assertEqual(self.person_1.surname, 'Peyo')
# preserve existing foreign key
@@ -215,8 +218,42 @@ class MergeTest(TestCase):
self.assertTrue(self.person_types[1]
in self.person_3.person_types.all())
+ def testPersonMergeCandidate(self):
+ init_mc = self.person_1.merge_candidate.count()
+ person = models.Person.objects.create(
+ name=self.person_1.name,
+ surname=self.person_1.surname, history_modifier=self.user,
+ attached_to=self.person_1.attached_to)
+ self.assertEqual(self.person_1.merge_candidate.count(),
+ init_mc + 1)
+ person.archive()
+ self.assertEqual(self.person_1.merge_candidate.count(),
+ init_mc)
+
+
+class ImportTest(TestCase):
+ def testDeleteRelated(self):
+ town = models.Town.objects.create(name='my-test')
+ self.assertEqual(models.Town.objects.filter(name='my-test').count(), 1)
+
+ # create an import, fields are not relevant...
+ create_user()
+ importer_type = models.ImporterType.objects.create(
+ associated_models='ishtar_common.models.Person')
+ mcc_operation_file = DjangoFile(file(
+ settings.ROOT_PATH +
+ '../archaeological_operations/tests/MCC-operations-example.csv',
+ 'rb'))
+ imprt = models.Import.objects.create(
+ user=models.IshtarUser.objects.all()[0],
+ importer_type=importer_type,
+ imported_file=mcc_operation_file)
+
+ town.imports.add(imprt)
+ imprt.delete()
+ # town should be deleted
+ self.assertEqual(models.Town.objects.filter(name='my-test').count(), 0)
-class ImportKeyTest(TestCase):
def testKeys(self):
content_type = ContentType.objects.get_for_model(
models.OrganizationType)
@@ -291,12 +328,12 @@ class IshtarSiteProfileTest(TestCase):
self.assertTrue(profile2.context_record and profile2.find)
def testDefaultProfile(self):
- cache.set('default-ishtarsiteprofile-is-current-profile', None,
+ cache.set('default-ishtar_common-IshtarSiteProfile', None,
settings.CACHE_TIMEOUT)
self.assertFalse(models.IshtarSiteProfile.objects.count())
- profile = models.get_current_profile()
+ profile = models.get_current_profile(force=True)
self.assertTrue(profile)
- self.assertTrue(models.IshtarSiteProfile.objects.count())
+ self.assertEqual(models.IshtarSiteProfile.objects.count(), 1)
def testMenuFiltering(self):
cache.set('default-ishtarsiteprofile-is-current-profile', None,