summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2026-01-12 18:27:56 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2026-01-12 18:27:56 +0100
commit43339caea0a1bc7125740746c568fbe536c96d2e (patch)
treed710bb1bff6187bd8389e72641e545326f7a8df7
parent555868ac554938ce90e181b77971286d7170fdc6 (diff)
downloadIshtar-43339caea0a1bc7125740746c568fbe536c96d2e.tar.bz2
Ishtar-43339caea0a1bc7125740746c568fbe536c96d2e.zip
✅ basic tests for all statistics modality
-rw-r--r--archaeological_context_records/tests.py4
-rw-r--r--archaeological_files/tests.py12
-rw-r--r--archaeological_finds/tests.py4
-rw-r--r--archaeological_operations/tests.py19
-rw-r--r--archaeological_warehouse/tests.py19
-rw-r--r--ishtar_common/tests.py30
6 files changed, 83 insertions, 5 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index 0338a2f20..54b9922b0 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -68,6 +68,7 @@ from ishtar_common.tests import (
COMMON_FIXTURES,
WAREHOUSE_FIXTURES,
SearchText,
+ StatisticsTest
)
from archaeological_operations.serializers import operation_serialization
@@ -797,8 +798,9 @@ class ContextRecordQATest(ContextRecordInit, TestCase):
self.assertEqual(cr.datings.count(), nb_datings - 1) # deleted
-class ContextRecordSearchTest(ContextRecordInit, TestCase, SearchText):
+class ContextRecordSearchTest(ContextRecordInit, TestCase, SearchText, StatisticsTest):
fixtures = CONTEXT_RECORD_TOWNS_FIXTURES
+ MODEL = models.ContextRecord
SEARCH_URL = "get-contextrecord"
def setUp(self):
diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py
index 53e29c1cc..fd48127e8 100644
--- a/archaeological_files/tests.py
+++ b/archaeological_files/tests.py
@@ -33,6 +33,7 @@ from ishtar_common.tests import (
WizardTest,
WizardTestFormData as FormData,
FILE_TOWNS_FIXTURES,
+ StatisticsTest
)
from ishtar_common.models import Town, IshtarSiteProfile, Person, PersonType, \
@@ -262,6 +263,17 @@ class FileTest(TestCase, FileInit):
status_code=302)
+class FileSearchTest(TestCase, StatisticsTest):
+ fixtures = FILE_TOWNS_FIXTURES
+ SEARCH_URL = "get-file"
+ MODEL = models.File
+
+ def setUp(self):
+ IshtarSiteProfile.objects.get_or_create(slug="default", active=True)
+ self.username, self.password, self.user = create_superuser()
+ models.File.objects.create(file_type=models.FileType.objects.all()[0])
+
+
class FileCostTest(TestCase, FileInit):
fixtures = FILE_TOWNS_FIXTURES
model = models.File
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index dfb267564..aabfc268a 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -94,6 +94,7 @@ from ishtar_common.tests import (
COMMON_FIXTURES,
GenericSerializationTest,
SearchText,
+ StatisticsTest
)
from archaeological_operations.tests import ImportTest, create_operation, \
create_administrativact, TestPermissionQuery
@@ -1384,9 +1385,10 @@ class FindBasketTest(FindInit, TestCase):
self.assertEqual(res["recordsTotal"], 1)
-class FindSearchTest(FindInit, TestCase, SearchText):
+class FindSearchTest(FindInit, TestCase, SearchText, StatisticsTest):
fixtures = WAREHOUSE_FIXTURES
model = models.Find
+ MODEL = models.Find
SEARCH_URL = "get-find"
def setUp(self):
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 57950ddd2..e5ca04db0 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -114,11 +114,12 @@ from ishtar_common.tests import (
GenericSerializationTest,
WAREHOUSE_FIXTURES,
SearchText,
+ StatisticsTest
)
from ishtar_common.serializers import restore_serialized
-class FileInit(object):
+class FileInit:
def login_as_superuser(self):
# nosec: hard coded password for test purposes
self.client.login(username="username", password="tralala") # nosec
@@ -1953,7 +1954,7 @@ def create_operation(user, orga=None, values=None):
return models.Operation.objects.create(**dct)
-class OperationInitTest(object):
+class OperationInitTest:
def create_user(self):
username, password, self.user = create_user()
return self.user
@@ -3023,9 +3024,10 @@ class CustomFormTest(TestCase, OperationInitTest):
self.assertEqual(result["recordsTotal"], 1)
-class OperationSearchTest(TestCase, OperationInitTest, SearchText):
+class OperationSearchTest(TestCase, OperationInitTest, SearchText, StatisticsTest):
fixtures = FILE_FIXTURES
SEARCH_URL = "get-operation"
+ MODEL = models.Operation
def setUp(self):
IshtarSiteProfile.objects.get_or_create(slug="default", active=True)
@@ -3577,6 +3579,17 @@ class OperationSearchTest(TestCase, OperationInitTest, SearchText):
self.assertEqual(values["data"], expected_result)
+class SiteSearchTest(TestCase, StatisticsTest):
+ fixtures = FILE_FIXTURES
+ SEARCH_URL = "get-site"
+ MODEL = models.ArchaeologicalSite
+
+ def setUp(self):
+ IshtarSiteProfile.objects.get_or_create(slug="default", active=True)
+ self.username, self.password, self.user = create_superuser()
+ self.site = models.ArchaeologicalSite.objects.create(reference="ref-site")
+
+
class TestPermissionQuery:
def setup_permission_queries(self, prefix, model_name, permissions,
perm_requests=None, create_profiles=True):
diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py
index ba9c081b6..939145389 100644
--- a/archaeological_warehouse/tests.py
+++ b/archaeological_warehouse/tests.py
@@ -36,6 +36,7 @@ from ishtar_common.tests import (
COMMON_FIXTURES,
create_user,
create_superuser,
+ StatisticsTest
)
from ishtar_common.models import IshtarSiteProfile, ProfileType, UserProfile
@@ -333,6 +334,24 @@ class SerializationTest(GenericSerializationTest, FindInit, TestCase):
)
+class ContainerSearchTest(TestCase, StatisticsTest):
+ fixtures = WAREHOUSE_FIXTURES
+ SEARCH_URL = "get-container"
+ MODEL = models.Container
+
+ def setUp(self):
+ IshtarSiteProfile.objects.get_or_create(slug="default", active=True)
+ self.username, self.password, self.user = create_superuser()
+ ct1 = models.ContainerType.objects.order_by("id").all()[0]
+ self.main_warehouse = models.Warehouse.objects.create(
+ name="Main", warehouse_type=models.WarehouseType.objects.all()[0]
+ )
+ self.container_1 = models.Container.objects.create(
+ reference="1", container_type=ct1,
+ location=self.main_warehouse
+ )
+
+
class WarehouseWizardCreationTest(WizardTest, FindInit, TestCase):
fixtures = WAREHOUSE_FIXTURES
url_name = "warehouse_creation"
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 7582bf163..35184d561 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -266,6 +266,36 @@ class SearchText:
self.assertEqual(res["recordsTotal"], expected_result, msg=msg)
+class StatisticsTest:
+ MODEL = None
+ SEARCH_URL = None
+
+ def test_base_statistics(self):
+ if not self.MODEL:
+ raise NotImplementedError("MODEL attribute must be set on the class")
+ if not self.SEARCH_URL:
+ raise NotImplementedError("SEARCH_URL attribute must be set on the class")
+ c = Client()
+
+ base_extra = "json-stats?submited=1"
+ response = c.get(reverse(self.SEARCH_URL) + base_extra)
+ # empty when not allowed
+ if response.status_code == 200:
+ self.assertEqual(response.status_code, 200)
+ content = json.loads(response.content.decode("utf-8"))
+ self.assertEqual(content, [])
+ c.login(username=self.username, password=self.password)
+
+ base_extra += "&stats_sum_variable=pk&stats_modality_1="
+ for modality in self.MODEL.STATISTIC_MODALITIES_OPTIONS:
+ response = c.get(reverse(self.SEARCH_URL) + base_extra + modality)
+ self.assertEqual(response.status_code, 200)
+ # only verify a response is sent
+ # TODO: check more
+ content = json.loads(response.content.decode("utf-8"))
+ self.assertTrue(len(content["data"]) > 0)
+
+
class CommandsTestCase(TestCase):
fixtures = [LIB_BASE_PATH + "ishtar_common/fixtures/test_towns.json"]