diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-05-10 22:46:17 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-17 13:21:28 +0200 |
commit | 60d7d9edb2fe286fd6c1cf47b6df04cdadcc8a7c (patch) | |
tree | 614ce9bbf5b1982977ff55e17e4d21520959e3aa /archaeological_operations/tests.py | |
parent | fd2eea95940ef0a5ae98f95fbaab78e7fb46ebf7 (diff) | |
download | Ishtar-60d7d9edb2fe286fd6c1cf47b6df04cdadcc8a7c.tar.bz2 Ishtar-60d7d9edb2fe286fd6c1cf47b6df04cdadcc8a7c.zip |
Statistics - manage queries
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 29 |
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 |