summaryrefslogtreecommitdiff
path: root/archaeological_operations/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r--archaeological_operations/tests.py29
1 files changed, 29 insertions, 0 deletions
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