summaryrefslogtreecommitdiff
path: root/archaeological_files/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_files/tests.py')
-rw-r--r--archaeological_files/tests.py87
1 files changed, 66 insertions, 21 deletions
diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py
index b30c39dc1..312c0402d 100644
--- a/archaeological_files/tests.py
+++ b/archaeological_files/tests.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2010-2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2010-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
@@ -20,26 +20,22 @@
"""
Unit tests
"""
-import json
+import json, datetime
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase
-from ishtar_common.models import PersonType
-from archaeological_files import models, data_importer
-
-class FileTest(TestCase):
- fixtures = [settings.ROOT_PATH + \
- '../fixtures/initial_data-auth-fr.json',
- settings.ROOT_PATH + \
- '../ishtar_common/fixtures/initial_data-fr.json']
- model = models.File
+from ishtar_common.models import PersonType, Town
+from archaeological_files import models
+from archaeological_operations.models import Parcel, ParcelOwner
+from archaeological_operations.tests import OperationInitTest
+class FileInit(object):
def login_as_superuser(self):
self.client.login(username='username', password='tralala')
- def setUp(self):
+ def create_file(self):
self.extra_models, self.model_list = {}, []
self.user, created = User.objects.get_or_create(username='username',
is_superuser=True)
@@ -70,11 +66,15 @@ class FileTest(TestCase):
self.item = self.model(**dct)
self.item.save()
- def tearDown(self):
- #self.item.delete()
- #for item in reversed(self.model_list):
- # item.delete()
- pass
+class FileTest(TestCase, FileInit):
+ fixtures = [settings.ROOT_PATH + \
+ '../fixtures/initial_data-auth-fr.json',
+ settings.ROOT_PATH + \
+ '../ishtar_common/fixtures/initial_data-fr.json']
+ model = models.File
+
+ def setUp(self):
+ self.create_file()
def testAddAndGetHistorized(self):
"""
@@ -176,7 +176,52 @@ class FileTest(TestCase):
self.assertTrue(data['records'] == 1)
self.assertEqual(data['rows'][0]['internal_reference'], initial_ref)
-class ImporterTest(TestCase):
- def testFormaters(self):
- for formater in [data_importer.SurfaceFormater]:
- formater().test()
+#class ImporterTest(TestCase):
+# def testFormaters(self):
+# from archaeological_files import data_importer
+# for formater in [data_importer.SurfaceFormater]:
+# formater().test()
+
+class FileOperationTest(TestCase, OperationInitTest, FileInit):
+ model = models.File
+ fixtures = [settings.ROOT_PATH + \
+ '../fixtures/initial_data-auth-fr.json',
+ settings.ROOT_PATH + \
+ '../ishtar_common/fixtures/initial_data-fr.json',
+ settings.ROOT_PATH +
+ '../ishtar_common/fixtures/test_towns.json',
+ settings.ROOT_PATH +
+ '../ishtar_common/fixtures/initial_importtypes-fr.json',
+ settings.ROOT_PATH +
+ '../archaeological_files/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_operations/fixtures/initial_data-fr.json']
+
+ def setUp(self):
+ self.create_file()
+ self.orgas = self.create_orgas(self.user)
+ self.operations = self.create_operation(self.user, self.orgas[0])
+ self.operation = self.operations[0]
+
+ def testFileAssociation(self):
+ # parcel association
+ default_town = Town.objects.all()[0]
+ for p in range(0, 10):
+ parcel = Parcel.objects.create(parcel_number=unicode(p),
+ section='YY',
+ town=default_town,
+ operation=self.operation)
+ if p == 1:
+ ParcelOwner.objects.create(
+ owner=self.extra_models['person'],
+ parcel=parcel, start_date=datetime.date.today(),
+ end_date=datetime.date.today())
+ initial_nb = self.item.parcels.count()
+ # no parcel on the file -> new parcels are copied from the
+ # operation
+ self.operation.associated_file = self.item
+ self.operation.save()
+ self.assertEqual(self.item.parcels.count(), initial_nb+10)
+ # parcel owner well attached
+ q = ParcelOwner.objects.filter(parcel__associated_file=self.item)
+ self.assertEqual(q.count(), 1)