summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-05-01 15:29:29 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-17 13:21:28 +0200
commitb69789fac685745ae7bcb144262eb9dfea44286d (patch)
tree86aeeacd3faf8d064ce6aee668157bec5c3f901e
parent1603aaf09fcab2de0c70dc9a751c829cb2cc6b32 (diff)
downloadIshtar-b69789fac685745ae7bcb144262eb9dfea44286d.tar.bz2
Ishtar-b69789fac685745ae7bcb144262eb9dfea44286d.zip
Labels generation: test
-rw-r--r--archaeological_operations/tests.py57
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