summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-06-25 18:24:56 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2015-06-25 18:24:56 +0200
commitc1af8517f3758694069df23448f22633ffb0d352 (patch)
tree55a74abbbd6390732c28656fa1dbc7f138ac5c45 /archaeological_finds
parent050f9dcaa43f5a613005c99d92288e85fda9bb95 (diff)
parent01db23a883983912d6998f6be71d3bd6a9a61b8d (diff)
downloadIshtar-c1af8517f3758694069df23448f22633ffb0d352.tar.bz2
Ishtar-c1af8517f3758694069df23448f22633ffb0d352.zip
Merge branch 'stable'
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/models.py8
-rw-r--r--archaeological_finds/tests.py67
-rw-r--r--archaeological_finds/tests/MCC-finds-example.csv5
3 files changed, 80 insertions, 0 deletions
diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py
index 8aae745e6..dd4b20b39 100644
--- a/archaeological_finds/models.py
+++ b/archaeological_finds/models.py
@@ -166,6 +166,14 @@ class BaseFind(BaseHistorizedItem, OwnPerms):
def name(self):
return self.label
+ @classmethod
+ def get_extra_fields(cls):
+ fields = {}
+ for field in Find._meta.many_to_many:
+ if field.name == 'base_finds':
+ fields['find'] = field.related.model
+ return fields
+
WEIGHT_UNIT = (('g', _(u"g")),
('kg', _(u"kg")),)
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
new file mode 100644
index 000000000..f61807637
--- /dev/null
+++ b/archaeological_finds/tests.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (C) 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
+# 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 <http://www.gnu.org/licenses/>.
+
+# See the file COPYING for details.
+
+from django.conf import settings
+from django.core.files.uploadedfile import SimpleUploadedFile
+from ishtar_common.models import ImporterType
+
+from archaeological_finds import models
+
+from archaeological_context_records.tests import ImportContextRecordTest
+
+from ishtar_common import forms_common
+
+class ImportFindTest(ImportContextRecordTest):
+ test_context_records = False
+
+ fixtures = ImportContextRecordTest.fixtures + [
+ settings.ROOT_PATH +
+ '../archaeological_finds/fixtures/initial_data-fr.json',
+ ]
+
+ def testMCCImportFinds(self, test=True):
+ self.testMCCImportContextRecords(test=False)
+
+ old_nb = models.BaseFind.objects.count()
+ MCC = ImporterType.objects.get(name=u"MCC - Mobilier")
+ mcc_file = open(settings.ROOT_PATH + \
+ '../archaeological_finds/tests/MCC-finds-example.csv', 'rb')
+ file_dict = {'imported_file': SimpleUploadedFile(mcc_file.name,
+ mcc_file.read())}
+ post_dict = {'importer_type':MCC.pk, 'skip_lines':1,
+ "encoding":'utf-8'}
+ form = forms_common.NewImportForm(data=post_dict, files=file_dict,
+ instance=None)
+ form.is_valid()
+ if test:
+ self.assertTrue(form.is_valid())
+ impt = form.save(self.ishtar_user)
+ impt.initialize()
+
+ # doing manual connections
+ ceram = models.MaterialType.objects.get(txt_idx='ceramic').pk
+ self.setTargetKey('find__material_type', 'ceramique', ceram)
+ impt.importation()
+ if not test:
+ return
+ # new finds has now been imported
+ current_nb = models.BaseFind.objects.count()
+ self.assertTrue(current_nb == (old_nb + 4))
+ self.assertEqual(
+ models.Find.objects.filter(material_type__pk=ceram).count(), 4)
diff --git a/archaeological_finds/tests/MCC-finds-example.csv b/archaeological_finds/tests/MCC-finds-example.csv
new file mode 100644
index 000000000..67971132f
--- /dev/null
+++ b/archaeological_finds/tests/MCC-finds-example.csv
@@ -0,0 +1,5 @@
+code OA,identifiant materiel,objet lot,partage,composite,matiere,type,determination,numero contenant,nombre fragment,poids,unite poids,identifiant UE,date decouverte,identifiant parcelle,etat sanitaire,type preservation a envisager,commentaire,chronologie,localisation topographique,interet particulier,description,remontage
+4200,1,lot,non,,terre cuite,céramique,sfq,1,76,4040,g,HC,,XXXXXX,sais pas,,Blah,med,,,,
+4200,1,lot,non,,terre cuite,céramique,qsdfsqfd,1,56,2280,g,H.-C.,,XXXXXX,,,,med,,,,
+4200,1,lot,non,,terre cuite,céramique,sqfdsq,2,44,5210,g,HC,,YY55,stable,,,GR,,,,
+4200,2,lot,non,,terre cuite,céramique,sqfdsq,45,43,1500,g,US17,,YY55,,,,,,,,