From 6822016883796d8938bf74a1372222f44f91f16c Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 8 Sep 2013 12:12:33 +0200 Subject: Fix archaeological operation wizard when no town is available --- archaeological_files/tests.py | 125 +++++++++++++++++++++++++++++++++++++ archaeological_operations/forms.py | 2 +- ishtar_common/tests.py | 125 ------------------------------------- 3 files changed, 126 insertions(+), 126 deletions(-) create mode 100644 archaeological_files/tests.py delete mode 100644 ishtar_common/tests.py diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py new file mode 100644 index 000000000..5a433b381 --- /dev/null +++ b/archaeological_files/tests.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2010-2011 Étienne Loks + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +# See the file COPYING for details. + +""" +Unit tests +""" +import json + +from django.test import TestCase + +import models + +class FileTest(TestCase): + fixtures = ['user.json', 'person_type-fr.json', 'organization_type-fr.json', + 'treatment_type-fr.json'] + model = models.File + + def setUp(self): + self.extra_models, self.model_list = {}, [] + user = models.IshtarUser.objects.get(pk=1) + person_type = models.PersonType(label=u'Test person type', + txt_idx='test_person', available=True) + person_type.save() + self.extra_models['person_type'] = person_type + self.model_list.append(person_type) + + person = models.Person(title='Mr', surname='Surname', name='Name', + person_type=person_type, history_modifier=user) + person.save() + self.extra_models['person'] = person + self.model_list.append(person) + + file_type = models.FileType(label=u'Test file type', + txt_idx='test_file', available=True) + file_type.save() + self.extra_models['file_type'] = file_type + self.model_list.append(file_type) + + dct = {'year':2010, 'numeric_reference':1000, 'file_type':file_type, + 'internal_reference':u'UNIT_testÉ ?', 'in_charge':person, + 'history_modifier':user, 'total_surface':10000} + self.item = self.model(**dct) + self.item.save() + + def tearDown(self): + self.item.delete() + for item in reversed(self.model_list): + item.delete() + + def testAddAndGetHistorized(self): + """ + Test correct new version and correct access to history + """ + nb_hist = self.item.history.count() + self.assertTrue(self.item.history.count() >= 1) + base_label = self.item.internal_reference + self.item.internal_reference = u"Unité_Test" + self.item.save() + self.failUnlessEqual(self.item.history.count(), nb_hist+1) + self.failUnlessEqual(self.item.history.all()[1].internal_reference, + base_label) + + def testIntelligentHistorisation(self): + """ + Test that to identical version are not recorded twice in the history + """ + nb_hist = self.item.history.count() + self.item.internal_reference = u"Unité_Test" + self.item.save() + self.failUnlessEqual(self.item.history.count(), nb_hist+1) + nb_hist = self.item.history.count() + self.item.save() + self.failUnlessEqual(self.item.history.count(), nb_hist) + + def testRollbackFile(self): + nb_hist = self.item.history.count() + initial_values = self.item.values() + backup_date = self.item.history.all()[0].history_date + self.item.internal_reference = u"Unité_Test" + self.item.save() + self.item.rollback(backup_date) + self.failUnlessEqual(self.item.history.count(), nb_hist) + new_values = self.item.values() + for k in initial_values.keys(): + self.assertTrue(k in new_values) + self.assertEqual(new_values[k], initial_values[k]) + + def testRESTGetFile(self): + response = self.client.post('/get-file/', + {'numeric_reference':self.item.numeric_reference}) + self.assertEqual(response.status_code, 200) + data = json.loads(response.content) + self.assertTrue('records' in data) + self.assertTrue(data['records'] == 1) + + def testRESTGetOldFile(self): + initial_ref = self.item.internal_reference + new_ref = u"Unité_Test_old_file" + new_ref = initial_ref != new_ref and new_ref or new_ref + u"extra" + self.item.internal_reference = new_ref + self.item.save() + response = self.client.post('/get-file/', + {'numeric_reference':self.item.numeric_reference, 'old':1}) + self.assertEqual(response.status_code, 200) + data = json.loads(response.content) + self.assertTrue('records' in data) + self.assertTrue(data['records'] == 1) + self.assertEqual(data['rows'][0]['internal_reference'], initial_ref) + diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 2071dd00f..b971361d8 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -145,7 +145,7 @@ class ParcelFormSet(FormSet): if parcel.get('town'): last_town = parcel.get('town') break - if not last_town: + if not last_town and 'town' in self.forms[0].fields.keys(): towns = self.forms[0].fields['town'].choices if towns: towns.pop(0) # remove first empty diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py deleted file mode 100644 index 5a433b381..000000000 --- a/ishtar_common/tests.py +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (C) 2010-2011 Étienne Loks - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. - -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -# See the file COPYING for details. - -""" -Unit tests -""" -import json - -from django.test import TestCase - -import models - -class FileTest(TestCase): - fixtures = ['user.json', 'person_type-fr.json', 'organization_type-fr.json', - 'treatment_type-fr.json'] - model = models.File - - def setUp(self): - self.extra_models, self.model_list = {}, [] - user = models.IshtarUser.objects.get(pk=1) - person_type = models.PersonType(label=u'Test person type', - txt_idx='test_person', available=True) - person_type.save() - self.extra_models['person_type'] = person_type - self.model_list.append(person_type) - - person = models.Person(title='Mr', surname='Surname', name='Name', - person_type=person_type, history_modifier=user) - person.save() - self.extra_models['person'] = person - self.model_list.append(person) - - file_type = models.FileType(label=u'Test file type', - txt_idx='test_file', available=True) - file_type.save() - self.extra_models['file_type'] = file_type - self.model_list.append(file_type) - - dct = {'year':2010, 'numeric_reference':1000, 'file_type':file_type, - 'internal_reference':u'UNIT_testÉ ?', 'in_charge':person, - 'history_modifier':user, 'total_surface':10000} - self.item = self.model(**dct) - self.item.save() - - def tearDown(self): - self.item.delete() - for item in reversed(self.model_list): - item.delete() - - def testAddAndGetHistorized(self): - """ - Test correct new version and correct access to history - """ - nb_hist = self.item.history.count() - self.assertTrue(self.item.history.count() >= 1) - base_label = self.item.internal_reference - self.item.internal_reference = u"Unité_Test" - self.item.save() - self.failUnlessEqual(self.item.history.count(), nb_hist+1) - self.failUnlessEqual(self.item.history.all()[1].internal_reference, - base_label) - - def testIntelligentHistorisation(self): - """ - Test that to identical version are not recorded twice in the history - """ - nb_hist = self.item.history.count() - self.item.internal_reference = u"Unité_Test" - self.item.save() - self.failUnlessEqual(self.item.history.count(), nb_hist+1) - nb_hist = self.item.history.count() - self.item.save() - self.failUnlessEqual(self.item.history.count(), nb_hist) - - def testRollbackFile(self): - nb_hist = self.item.history.count() - initial_values = self.item.values() - backup_date = self.item.history.all()[0].history_date - self.item.internal_reference = u"Unité_Test" - self.item.save() - self.item.rollback(backup_date) - self.failUnlessEqual(self.item.history.count(), nb_hist) - new_values = self.item.values() - for k in initial_values.keys(): - self.assertTrue(k in new_values) - self.assertEqual(new_values[k], initial_values[k]) - - def testRESTGetFile(self): - response = self.client.post('/get-file/', - {'numeric_reference':self.item.numeric_reference}) - self.assertEqual(response.status_code, 200) - data = json.loads(response.content) - self.assertTrue('records' in data) - self.assertTrue(data['records'] == 1) - - def testRESTGetOldFile(self): - initial_ref = self.item.internal_reference - new_ref = u"Unité_Test_old_file" - new_ref = initial_ref != new_ref and new_ref or new_ref + u"extra" - self.item.internal_reference = new_ref - self.item.save() - response = self.client.post('/get-file/', - {'numeric_reference':self.item.numeric_reference, 'old':1}) - self.assertEqual(response.status_code, 200) - data = json.loads(response.content) - self.assertTrue('records' in data) - self.assertTrue(data['records'] == 1) - self.assertEqual(data['rows'][0]['internal_reference'], initial_ref) - -- cgit v1.2.3