summaryrefslogtreecommitdiff
path: root/archaeological_operations/tests.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-03-29 14:12:29 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-03-29 14:12:29 +0200
commit86dcac2bfb60cb9a59eaa30cb0d273595f3187a6 (patch)
tree6b0660d95e9ec53b9e8f77d01b267b4a9dd5df23 /archaeological_operations/tests.py
parent5741ce1ef25dc6e9c6e1296cb874eae2e183149b (diff)
downloadIshtar-86dcac2bfb60cb9a59eaa30cb0d273595f3187a6.tar.bz2
Ishtar-86dcac2bfb60cb9a59eaa30cb0d273595f3187a6.zip
Fixes for not imported columns on step by step import. Tests for this feature.
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r--archaeological_operations/tests.py105
1 files changed, 103 insertions, 2 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 4f9f73a43..612156df2 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -30,8 +30,8 @@ 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
-from django.contrib.auth.models import Permission
+from django.contrib.auth.models import User, Permission
+from django.utils.translation import ugettext_lazy as _
import models
from archaeological_operations import views
@@ -475,6 +475,107 @@ class ImportOperationTest(ImportTest, TestCase):
self.assertEqual(ope2.data, {u'autre_refs': {u'arbitraire': 456}})
+class ImportStepByStepTest(ImportTest, TestCase):
+ fixtures = OPERATION_TOWNS_FIXTURES
+
+ def test_step_by_step_import(self):
+ create_user()
+
+ importer, form = self.init_ope_import()
+ impt = form.save(self.ishtar_user)
+ impt.initialize()
+ self.init_ope_targetkey(imp=impt)
+ c = Client()
+
+ first_person_nb = Person.objects.count()
+ first_ope_nb = models.Operation.objects.count()
+ import_url = reverse('import_step_by_step',
+ kwargs={'pk': impt.pk, 'line_number': 2})
+ response = c.get(import_url)
+ # no login redirect
+ self.assertEqual(response.status_code, 302)
+ self.assertRedirects(response, "/accounts/login/?next=" + import_url)
+
+ c.login(username=self.username, password=self.password)
+ response = c.get(import_url)
+ self.assertEqual(response.status_code, 200)
+ # verify pagination for next link is OK
+ self.assertIn('href="/import-step-by-step/{}/3/"'.format(impt.pk),
+ response.content)
+ # creation have been evaluated
+ self.assertIn(
+ unicode(_(u"New objects will be created.")),
+ response.content.decode('utf-8')
+ )
+
+ # import this line
+ posted = {"valid": "import"}
+ response = c.post(import_url, posted)
+ self.assertEqual(response.status_code, 302)
+ # successful import - go to the next line
+ new_import_url = reverse('import_step_by_step',
+ kwargs={'pk': impt.pk, 'line_number': 3})
+ self.assertRedirects(response, new_import_url)
+ current_ope_nb = models.Operation.objects.count()
+ self.assertEqual(current_ope_nb, first_ope_nb + 1)
+ current_person_nb = Person.objects.count()
+ self.assertEqual(current_person_nb, first_person_nb)
+
+ # re-import
+ posted = {"valid": "import"}
+ c.post(import_url, posted)
+ # no changes
+ current_ope_nb = models.Operation.objects.count()
+ self.assertEqual(current_ope_nb, first_ope_nb + 1)
+ current_person_nb = Person.objects.count()
+ self.assertEqual(current_person_nb, first_person_nb)
+
+ # on import page, already imported is visible
+ response = c.get(import_url)
+ self.assertEqual(response.status_code, 200)
+ self.assertIn(
+ unicode(_(u"This line have been already imported.")),
+ response.content.decode('utf-8')
+ )
+
+ # import next page
+ next_import_url = reverse(
+ 'import_step_by_step', kwargs={'pk': impt.pk, 'line_number': 3})
+ posted = {"valid": "import"}
+ c.post(next_import_url, posted)
+ current_ope_nb = models.Operation.objects.count()
+ self.assertEqual(current_ope_nb, first_ope_nb + 2)
+ current_person_nb = Person.objects.count()
+ self.assertEqual(current_person_nb, first_person_nb + 1)
+
+ # modifiy CSV with an invalid date
+ posted = {
+ "valid": "change-csv",
+ "col-1": "4201",
+ "col-2": "Bourgogne",
+ "col-3": u"Fouille programmée",
+ "col-4": u"Oppìdum de Paris 2",
+ "col-5": u"L'opérateur",
+ "col-6": u"",
+ "col-7": "2000/01/32",
+ "col-8": "2002/12/31",
+ "col-9": "Age du Fer",
+ }
+ response = c.post(import_url, posted)
+ self.assertEqual(response.status_code, 200)
+ # modification have been made in the source CSV
+ with open(impt.imported_file.path) as fle:
+ fle.readline() # header
+ imported_line = fle.readline()
+ self.assertIn("2000/01/32", imported_line)
+ # error detected on the source file
+ error = unicode(_(
+ u"The following error(s) has been encountered while parsing "
+ u"the source file:")
+ )
+ self.assertIn(error, response.content.decode('utf-8'))
+
+
class ParcelTest(ImportTest, TestCase):
fixtures = OPERATION_TOWNS_FIXTURES