diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-03-08 19:25:46 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-17 13:21:27 +0200 |
commit | bdf52a0d1792340fab01fbcc4f6926bfb1914168 (patch) | |
tree | 44bf18fffe30797db49889ed80f04835e9ab997b | |
parent | a5de883a9dd2e4aa8219e8973c935daf689f54e0 (diff) | |
download | Ishtar-bdf52a0d1792340fab01fbcc4f6926bfb1914168.tar.bz2 Ishtar-bdf52a0d1792340fab01fbcc4f6926bfb1914168.zip |
Fix document edit
-rw-r--r-- | .gitlab-ci.yml | 2 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 81 | ||||
-rw-r--r-- | ishtar_common/forms_common.py | 2 | ||||
-rw-r--r-- | ishtar_common/tests.py | 16 | ||||
-rw-r--r-- | ishtar_common/views.py | 2 |
5 files changed, 97 insertions, 6 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8f0ce5da2..65f39ebb3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ before_script: - apt-get update - apt-get install -q -y git sed python3-pip libpq-dev python3-dev libjpeg-dev zlib1g-dev libxml2-dev libxslt1-dev libgeos-dev python3-cairocffi tidy libtidy-dev binutils libproj-dev gdal-bin libpangocairo-1.0-0 pandoc - apt-get install -q -y locales - - 'sed -i -e "s/# fr_FR.UTF-8*/fr_FR.UTF-8 UTF-8/" /etc/locale.gen' + - echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen - dpkg-reconfigure --frontend=noninteractive locales && update-locale LANG=$LANG - pip3 install -r requirements.txt - cp Makefile.example Makefile diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 54386135c..3f35de73b 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -2158,6 +2158,7 @@ class RegisterTest(TestCase, OperationInitTest): self.assertEqual(response.content, b"") c.login(username=self.username, password=self.password) response = c.post(reverse('operation-administrativeact-document'), data) + content, z, f = None, None, None try: f = BytesIO(response.content) z = zipfile.ZipFile(f) @@ -2165,9 +2166,12 @@ class RegisterTest(TestCase, OperationInitTest): content = z.open('content.xml') self.assertIn(b'2014-05-12', content.read()) finally: - content.close() - z.close() - f.close() + if content: + content.close() + if z: + z.close() + if f: + f.close() class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): @@ -2730,3 +2734,74 @@ class GenerateQRCode(OperationInitTest, TestCase): "operation/2010/OP2010-1/qrcode" ) ) + + +class DocumentTest(OperationInitTest, TestCase): + fixtures = FILE_FIXTURES + + def setUp(self): + self.username, self.password, self.user = create_superuser() + self.operation = self.create_operation(self.user)[0] + + def test_create(self): + c = Client() + url = reverse('create-document') + nb_doc = models.Document.objects.count() + nb_doc_ope = self.operation.documents.count() + + response = c.get(url, {"operation": self.operation.pk}) + self.assertEqual(response.status_code, 302) + + c.login(username=self.username, password=self.password) + response = c.get(url, {"operation": self.operation.pk}) + self.assertEqual(response.status_code, 200) + self.assertIn('option value="{}" selected'.format(self.operation.pk), + response.content.decode()) + + posted = {'authors': []} + for related_key in models.Document.RELATED_MODELS: + posted[related_key] = [] + posted["operations"] = [str(self.operation.pk)] + + response = c.post(url, posted) + # at least a minimum info have to be given + self.assertEqual(response.status_code, 200) + self.assertIn("errorlist", response.content.decode()) + + posted["title"] = "hop" + response = c.post(url, posted) + self.assertEqual(nb_doc + 1, models.Document.objects.count()) + self.assertEqual(nb_doc_ope + 1, self.operation.documents.count()) + self.assertRedirects(response, '/display-document/{}/'.format( + self.operation.documents.order_by('-pk').all()[0].pk + )) + + def test_edit(self): + doc = models.Document.objects.create(title="hop2") + doc.operations.add(self.operation) + c = Client() + url = reverse('edit-document', args=[doc.pk]) + + response = c.get(url) + self.assertEqual(response.status_code, 302) + + c.login(username=self.username, password=self.password) + response = c.get(url) + self.assertEqual(response.status_code, 200) + self.assertIn('option value="{}" selected'.format(self.operation.pk), + response.content.decode()) + + posted = { + 'authors': [], + 'title': "hop2-is-back" + } + for related_key in models.Document.RELATED_MODELS: + posted[related_key] = [] + posted["operations"] = [str(self.operation.pk)] + response = c.post(url, posted) + self.assertRedirects( + response, '/display-document/{}/'.format(doc.pk)) + response = c.get('/show-document/{}/'.format(doc.pk)) + self.assertIn(posted["title"], response.content.decode()) + + diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 0f8b4d416..b2f7c01ee 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1227,6 +1227,8 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): u"to one item")) def save(self, commit=True): + if not self.cleaned_data.get('authors', None): + self.cleaned_data['authors'] = [] item = super(DocumentForm, self).save(commit=commit) for related_key in models.Document.RELATED_MODELS: related = getattr(item, related_key) diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 7443c271e..f6cd3eff4 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -361,7 +361,7 @@ class WizardTest(object): @classmethod def wizard_post(cls, client, url, current_step, form_data=None, - follow=True): + follow=True, extra_data=None): if not url: url = reverse(cls.url_name) data = { @@ -380,6 +380,8 @@ class WizardTest(object): else: for k in form_data: data['{}-{}'.format(current_step, k)] = form_data[k] + if extra_data: + data.update(extra_data) try: response = client.post(url, data, follow=follow) @@ -400,10 +402,22 @@ class WizardTest(object): test_form_data.inits(self) form_data = test_form_data.form_datas ignored = test_form_data.ignored + previous_step, back_tested = None, False for idx, step in enumerate(self.steps): current_step, current_form = step if current_step in ignored: continue + if not previous_step: + previous_step = idx + elif not back_tested: + # test going back on a form + response = self.wizard_post( + self.client, url, current_step, None, + extra_data={"form_previous_step": previous_step} + ) + self.assertEqual(response.status_code, 200) + back_tested = True + next_form_is_checked = len(self.steps) > idx + 1 and \ self.steps[idx + 1][0] not in ignored data = [] diff --git a/ishtar_common/views.py b/ishtar_common/views.py index e18d63101..a3bc0c034 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1778,7 +1778,7 @@ class DocumentEditView(DocumentFormMixin, UpdateView): except (AssertionError, models.Document.DoesNotExist): raise Http404() initial = {} - for k in self.form_class.base_fields.keys() + \ + for k in list(self.form_class.base_fields.keys()) + \ models.Document.RELATED_MODELS: value = getattr(document, k) if hasattr(value, 'all'): |