diff options
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 81 |
1 files changed, 78 insertions, 3 deletions
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()) + + |