diff options
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/models.py | 3 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 29 |
2 files changed, 32 insertions, 0 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index b3e137399..4f180c3d5 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -527,6 +527,9 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem, TABLE_COLS = ['code_patriarche', 'year', 'towns_label', 'common_name', 'operation_type', 'start_date', 'excavation_end_date', 'remains'] + # statistics + STATISTIC_MODALITIES = ["year", "operation_type__label", + "towns__cached_label"] # search parameters BOOL_FIELDS = ['end_date__isnull', 'virtual_operation', diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 10afc61f2..42ceea292 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -2006,6 +2006,35 @@ class OperationSearchTest(TestCase, OperationInitTest): self.assertEqual(json.loads(response.content.decode())['recordsTotal'], 1) + def test_statistics(self): + c = Client() + c.login(username=self.username, password=self.password) + q = {"stats_modality_1": "year", + "stats_modality_2": "operation_type__label"} + response = c.get(reverse('get-operation', args=['json-stats']), q) + self.assertEqual(response.status_code, 200) + + expected_result = [] + for ope in models.Operation.objects.all(): + years = [y for y, res in expected_result] + if ope.year in years: + year_idx = years.index(ope.year) + else: + expected_result.append([ope.year, []]) + year_idx = len(expected_result) - 1 + current_values = expected_result[year_idx][1] + values = [v for v, cnt in current_values] + val = ope.operation_type.label + if val in values: + val_idx = values.index(val) + else: + current_values.append([val, 0]) + val_idx = len(current_values) - 1 + current_values[val_idx][1] += 1 + + values = json.loads(response.content.decode()) + self.assertEqual(values['data'], expected_result) + class OperationPermissionTest(TestCase, OperationInitTest): fixtures = FILE_FIXTURES |