diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-03-11 20:05:04 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-04-24 19:41:37 +0200 |
commit | f9620956381f843fc5d341fd19cdf0fc0f68d1a7 (patch) | |
tree | d4dd0e61a429a660c7ec8776bf9287dab8d5610f /archaeological_operations | |
parent | e4454fdbf47a44de9de725ed733d12b604855da6 (diff) | |
download | Ishtar-f9620956381f843fc5d341fd19cdf0fc0f68d1a7.tar.bz2 Ishtar-f9620956381f843fc5d341fd19cdf0fc0f68d1a7.zip |
Import: manage pre-import function - test document import
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/tests.py | 57 | ||||
-rw-r--r-- | archaeological_operations/tests/document-example.csv | 3 |
2 files changed, 60 insertions, 0 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 14577e119..06898014c 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -498,6 +498,63 @@ class ImportOperationTest(ImportTest, TestCase): u"autre": 333}) +class ImportDocumentTest(ImportTest, TestCase): + fixtures = OPERATION_TOWNS_FIXTURES + + def init_doc_import(self, filename='document-example.csv'): + model, __ = ImporterModel.objects.get_or_create( + klass="ishtar_common.models.Document", + defaults={ + "name": "Documentation" + } + ) + doc_import, __ = ImporterType.objects.get_or_create( + name="Doc import", slug="doc-import", associated_models=model) + + col = ImporterColumn.objects.create(col_number=1, + importer_type_id=doc_import.pk) + formater = FormaterType.objects.filter( + formater_type='IntegerFormater').all()[0] + ImportTarget.objects.create(target='import_get_next_index', + formater_type_id=formater.pk, + column_id=col.pk) + col = ImporterColumn.objects.create(col_number=2, + importer_type_id=doc_import.pk) + formater, __ = FormaterType.objects.get_or_create( + formater_type='UnicodeFormater', options=None) + ImportTarget.objects.create(target='title', + formater_type_id=formater.pk, + column_id=col.pk) + + doc_import_file = open( + settings.ROOT_PATH + + '../archaeological_operations/tests/' + filename, + 'rb') + + file_dict = {'imported_file': SimpleUploadedFile( + doc_import_file.name, doc_import_file.read())} + + group, c = TargetKeyGroup.objects.get_or_create(name="My group") + post_dict = {'importer_type': doc_import.pk, 'skip_lines': 1, + "encoding": 'utf-8', "name": 'init_ope_import', + "associated_group": group.pk} + form = forms_common.NewImportForm(data=post_dict, files=file_dict, + user=self.user) + form.is_valid() + return doc_import, form + + def test_import_document(self): + doc_nb = Document.objects.count() + current_index = Document.get_next_index() - 1 + + importer, form = self.init_doc_import() + self.assertTrue(form.is_valid()) + impt = form.save(self.ishtar_user) + impt.importation() + self.assertEqual(doc_nb + 2, Document.objects.count()) + self.assertEqual(current_index + 2, Document.get_next_index() - 1) + + class ImportStepByStepTest(ImportTest, TestCase): fixtures = OPERATION_TOWNS_FIXTURES diff --git a/archaeological_operations/tests/document-example.csv b/archaeological_operations/tests/document-example.csv new file mode 100644 index 000000000..3dc13987f --- /dev/null +++ b/archaeological_operations/tests/document-example.csv @@ -0,0 +1,3 @@ +Index,title +1,Plouf 1 +1,Plouf 2 |