From a6c57dac661cff1beac7510532acccc7287ac636 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 12 Jan 2026 18:27:56 +0100 Subject: ✅ basic tests for all statistics modality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archaeological_context_records/tests.py | 4 +++- archaeological_files/tests.py | 12 ++++++++++++ archaeological_finds/tests.py | 4 +++- archaeological_operations/tests.py | 19 ++++++++++++++++--- archaeological_warehouse/tests.py | 19 +++++++++++++++++++ ishtar_common/tests.py | 30 ++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 5 deletions(-) diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index dc810bcab..a84abdd4f 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -65,6 +65,7 @@ from ishtar_common.tests import ( COMMON_FIXTURES, WAREHOUSE_FIXTURES, SearchText, + StatisticsTest ) from archaeological_operations.serializers import operation_serialization @@ -720,8 +721,9 @@ class ContextRecordQATest(ContextRecordInit, TestCase): self.assertNotEqual(cr_3.parcel, parcel) -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 ee323591a..4972d9735 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, \ @@ -264,6 +265,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 889742ba2..7c0c83575 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 from archaeological_context_records.tests import ContextRecordInit @@ -1359,9 +1360,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 d346b56e1..ec5c86ed7 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -110,11 +110,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 @@ -1952,7 +1953,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 @@ -3030,9 +3031,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) @@ -3547,6 +3549,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 OperationPermissionTest(TestCase, OperationInitTest): fixtures = FILE_FIXTURES diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py index c8e16a50c..e61afea49 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 @@ -331,6 +332,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 b4b1bb16e..7dd687873 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -268,6 +268,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"] -- cgit v1.2.3