diff options
-rw-r--r-- | archaeological_operations/tests.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index eba0d296a..71b912f89 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -2100,6 +2100,62 @@ class OperationPermissionTest(TestCase, OperationInitTest): self.assertRedirects(response, "/") +class LabelTest(TestCase, OperationInitTest): + fixtures = FILE_FIXTURES + + def setUp(self): + IshtarSiteProfile.objects.get_or_create( + slug='default', active=True) + self.username, self.password, self.user = create_superuser() + self.orgas = self.create_orgas(self.user) + self.operations = self.create_operation(self.user, self.orgas[0]) + + def test_label_generation(self): + ope = self.operations[0] + ope.year = 1789 + ope.save() + + tpl = open( + settings.ROOT_PATH + + '../archaeological_operations/tests/labels-8.odt', + 'rb') + template = SimpleUploadedFile(tpl.name, tpl.read()) + model, __ = ImporterModel.objects.get_or_create( + klass='archaeological_operations.models.Operation' + ) + doc = DocumentTemplate.objects.create( + name="Labels", + slug="labels", + associated_model=model, + available=True, + for_labels=True, + label_per_page=8, + template=template + ) + c = Client() + url = reverse("generate-labels", args=[doc.slug]) + + response = c.get(url) + # no result when no authentication + self.assertEqual(response.content, b"") + c.login(username=self.username, password=self.password) + response = c.get(url) + content, z, f = None, None, None + try: + f = BytesIO(response.content) + z = zipfile.ZipFile(f) + self.assertIsNone(z.testzip()) + content = z.open('content.xml') + self.assertIn(b'1789', content.read()) + finally: + if content: + content.close() + if z: + z.close() + if f: + f.close() + + class DashboardTest(TestCase, OperationInitTest): fixtures = FILE_FIXTURES @@ -2164,6 +2220,7 @@ class RegisterTest(TestCase, OperationInitTest): ) doc = DocumentTemplate.objects.create( name="Test", + slug=True, associated_model=model, available=True, template=template |