diff options
Diffstat (limited to 'archaeological_context_records/tests.py')
| -rw-r--r-- | archaeological_context_records/tests.py | 53 | 
1 files changed, 13 insertions, 40 deletions
| diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index 87eb80c57..032861d5d 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -29,67 +29,40 @@ from django.test.client import Client  from ishtar_common.models import ImporterType, IshtarSiteProfile  from ishtar_common.tests import create_superuser  from archaeological_operations.tests import OperationInitTest, \ -    ImportOperationTest +    ImportTest, ImportOperationTest  from archaeological_operations import models as models_ope  from archaeological_context_records import models -from ishtar_common import forms_common -class ImportContextRecordTest(ImportOperationTest): -    test_operations = False -    test_context_records = True +class ImportContextRecordTest(ImportTest, TestCase):      fixtures = ImportOperationTest.fixtures + [          settings.ROOT_PATH +          '../archaeological_context_records/fixtures/initial_data-fr.json',      ] -    def testMCCImportContextRecords(self, test=True): -        if test and not self.test_context_records: -            return -        self.testMCCImportParcels(test=False) - +    def test_mcc_import_contextrecords(self):          old_nb = models.ContextRecord.objects.count() -        MCC = ImporterType.objects.get(name=u"MCC - UE") -        mcc_file = open( -            settings.ROOT_PATH + -            '../archaeological_context_records/tests/' -            'MCC-context-records-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()) +        mcc, form = self.init_context_record_import() + +        self.assertTrue(form.is_valid())          impt = form.save(self.ishtar_user)          impt.initialize() -        # doing manual connections -        hc = models.Unit.objects.get(txt_idx='not_in_context').pk -        self.setTargetKey('unit', 'hc', hc) -        self.setTargetKey('unit', 'hors-contexte', hc) -        layer = models.Unit.objects.get(txt_idx='layer').pk -        self.setTargetKey('unit', 'couche', layer) - +        self.init_cr_targetkey(impt)          impt.importation() -        if not test: -            return - -        # new ues has now been imported +        # new context records has now been imported          current_nb = models.ContextRecord.objects.count() -        self.assertTrue(current_nb == (old_nb + 4)) +        self.assertEqual(current_nb, old_nb + 4)          self.assertEqual( -            models.ContextRecord.objects.filter(unit__pk=hc).count(), 3) +            models.ContextRecord.objects.filter( +                unit__txt_idx='not_in_context').count(), 3)          self.assertEqual( -            models.ContextRecord.objects.filter(unit__pk=layer).count(), 1) +            models.ContextRecord.objects.filter( +                unit__txt_idx='layer').count(), 1)  class ContextRecordInit(OperationInitTest): -    test_operations = False -      def create_context_record(self, user=None, data={}, force=False):          if not getattr(self, 'context_records', None):              self.context_records = [] | 
