summaryrefslogtreecommitdiff
path: root/archaeological_operations/tests.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-06-18 12:26:10 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-06-18 12:26:10 +0200
commit46c9fa2536524f1ca07e0f142136848098fff8af (patch)
treed9181dbfad1ea1aae456b8796e67ba9a45f4f5f9 /archaeological_operations/tests.py
parentc228fdc8c6e498dc306f45f28c3475d8ca42f4a1 (diff)
downloadIshtar-46c9fa2536524f1ca07e0f142136848098fff8af.tar.bz2
Ishtar-46c9fa2536524f1ca07e0f142136848098fff8af.zip
✨ Media exporter: filter with a query
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r--archaeological_operations/tests.py65
1 files changed, 54 insertions, 11 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index b8db7e2c7..385337213 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -91,7 +91,8 @@ from ishtar_common.models import (
Document,
ValueFormater,
Regexp,
- MediaExporter
+ MediaExporter,
+ SourceType
)
from ishtar_common.models_rest import ApiUser, ApiSearchModel, ApiSheetFilter
from archaeological_files.models import File, FileType
@@ -4101,7 +4102,8 @@ class OperationExportMediaTest(TestCase, TestPermissionQuery, OperationInitTest)
response = c.get(self.export_url)
self.assertEqual(response.status_code, 200)
- def _test_files(self, response, filenames):
+ def _test_files(self, response, filenames, exclude=None):
+ exclude = exclude or []
with tempfile.TemporaryDirectory() as tmpdir:
f, z = None, None
try:
@@ -4117,6 +4119,8 @@ class OperationExportMediaTest(TestCase, TestPermissionQuery, OperationInitTest)
image = f"{tmpdir}/{filename}"
with Image.open(image) as im:
self.assertIsNone(im.verify())
+ for excluded in exclude:
+ self.assertNotIn(exclude, name_list)
finally:
if z:
z.close()
@@ -4124,27 +4128,37 @@ class OperationExportMediaTest(TestCase, TestPermissionQuery, OperationInitTest)
f.close()
def test_content(self):
+ document = self.documents[0]
+ document.pk = None
+ document.save()
+ self.operation.documents.add(document)
+
c = Client()
c.login(username=self.username, password=self.password)
response = c.get(self.export_url)
- self._test_files(response, [('operation_image_00001.png', True)])
+ self._test_files(response, [
+ ('operation_image_00001.png', True),
+ ('operation_image_00002.png', True),
+ ])
self.exporter.files_to_export = 'A'
self.exporter.save()
response = c.get(self.export_url)
- self._test_files(
- response,
- [('operation_image_00001.png', True), ('operation_file_00001.txt', False), ]
- )
+ self._test_files(response, [
+ ('operation_image_00001.png', True),
+ ('operation_image_00002.png', True),
+ ('operation_file_00001.txt', False),
+ ])
self.exporter.thumbnail_for_images = True
self.exporter.save()
response = c.get(self.export_url)
- self._test_files(
- response,
- [('operation_image_00001.jpg', True), ('operation_file_00001.txt', False), ]
- )
+ self._test_files(response, [
+ ('operation_image_00001.jpg', True),
+ ('operation_image_00002.jpg', True),
+ ('operation_file_00001.txt', False),
+ ])
def _add_find(self):
cr_data = {
@@ -4189,6 +4203,35 @@ class OperationExportMediaTest(TestCase, TestPermissionQuery, OperationInitTest)
('find_image_00001.png', True),]
)
+ def test_query(self):
+ document_type = SourceType.objects.all()[0]
+ document = self.documents[0]
+ document.pk = None
+ document.source_type = document_type
+ document.save()
+ self.operation.documents.add(document)
+
+ c = Client()
+ c.login(username=self.username, password=self.password)
+
+ # classic export
+ response = c.get(self.export_url)
+ self._test_files(
+ response,
+ [('operation_image_00001.png', True),
+ ('operation_image_00002.png', True)]
+ )
+
+ # filter: only one document is relevant
+ self.exporter.query = f"type={document_type.label}"
+ self.exporter.save()
+ response = c.get(self.export_url)
+ self._test_files(
+ response,
+ [('operation_image_00001.png', True)],
+ exclude=[('operation_image_00002.png', True)]
+ )
+
class LabelTest(TestCase, OperationInitTest):
fixtures = FILE_FIXTURES