summaryrefslogtreecommitdiff
path: root/archaeological_finds/tests.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-16 19:44:31 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-28 12:15:24 +0100
commit4640d3649bd73b62dd2b1c301f7f1ebacba8fe4f (patch)
treed4597cfe77cc7854749d41f980e2bde18b3134af /archaeological_finds/tests.py
parent06790f9bb9dc079d170a30ab10414f790e97edc0 (diff)
downloadIshtar-4640d3649bd73b62dd2b1c301f7f1ebacba8fe4f.tar.bz2
Ishtar-4640d3649bd73b62dd2b1c301f7f1ebacba8fe4f.zip
Improve document generation perf
Diffstat (limited to 'archaeological_finds/tests.py')
-rw-r--r--archaeological_finds/tests.py67
1 files changed, 65 insertions, 2 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index 2ef551253..bede89b51 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -49,8 +49,7 @@ from archaeological_context_records.models import Period, Dating, \
ContextRecord, DatingType, DatingQuality
from archaeological_finds import models, views
from archaeological_warehouse.models import Warehouse, WarehouseType, \
- ContainerType, Container, WarehouseDivision, WarehouseDivisionLink, \
- ContainerLocalisation
+ ContainerType, Container, WarehouseDivisionLink
from archaeological_operations.models import Operation, OperationType
from ishtar_common import forms_common
@@ -2579,3 +2578,67 @@ class LabelTest(FindInit, TestCase):
self.templates.append(doc.template.path)
else:
self.assertFalse(doc.template.name, msg=msg)
+
+
+class TemplateTest(FindInit, TestCase):
+ fixtures = FIND_FIXTURES
+ model = models.Find
+
+ def setUp(self):
+ template = settings.ROOT_PATH + \
+ '../archaeological_finds/tests/notices-panier.odt'
+ filename = template.split("/")[-1]
+ shutil.copy(template,
+ os.path.join(settings.MEDIA_ROOT, filename),
+ follow_symlinks=True)
+ self.template = os.path.join(settings.MEDIA_ROOT, filename)
+ self.templates = [self.template]
+ ope1 = self.create_operation()[0]
+ ope2 = self.create_operation()[1]
+ cr = self.create_context_record(
+ data={"label": "CR 1", "operation": ope1}
+ )[0]
+ cr2 = self.create_context_record(
+ data={"label": "CR 2", "operation": ope2}
+ )[1]
+ self.create_finds(data_base={"context_record": cr})[0]
+ self.create_finds(data_base={"context_record": cr2})[1]
+ self.basket = models.FindBasket.objects.create(label="Hophop")
+ self.basket.items.add(self.finds[0])
+ self.basket.items.add(self.finds[1])
+ wt, __ = WarehouseType.objects.get_or_create(label="WT", txt_idx="WT")
+ location = Warehouse.objects.create(name="Warehouse", warehouse_type=wt)
+ ct, __ = ContainerType.objects.get_or_create(label="CT", txt_idx="CT")
+ self.container = Container.objects.create(
+ location=location,
+ reference="Reférence",
+ container_type=ct
+ )
+
+ def test_label(self):
+ with open(self.template, 'rb') as tpl:
+ template = SimpleUploadedFile("template.odt",
+ tpl.read())
+ model, __ = ImporterModel.objects.get_or_create(
+ klass='archaeological_finds.models.Find'
+ )
+ q = DocumentTemplate.objects.filter(slug="test")
+ if q.count():
+ q.all()[0].delete()
+ doc = DocumentTemplate.objects.create(
+ name="Test",
+ slug="test",
+ associated_model=model,
+ available=True,
+ template=template)
+ self.templates.append(doc.template.path)
+ doc = DocumentTemplate.objects.get(pk=doc.pk)
+
+ result = doc.publish(self.basket)
+ if result:
+ self.templates.append(result)
+
+ def tearDown(self):
+ for tpl in self.templates:
+ if os.path.exists(tpl):
+ os.remove(tpl)