From 887a3552b440c3e135b2f7095cf82885de9884f9 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Tue, 19 Apr 2022 14:04:20 +0200 Subject: [PATCH] #140 Tests * adds workflow tests for major datatypes --- .../tests/compensation/test_workflow.py | 26 ++++++++++++++++++- .../tests/ecoaccount/test_workflow.py | 24 +++++++++++++++++ ema/tests/test_workflow.py | 26 +++++++++++++++++++ intervention/tests/test_workflow.py | 24 +++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) diff --git a/compensation/tests/compensation/test_workflow.py b/compensation/tests/compensation/test_workflow.py index 5b7decff..570045f2 100644 --- a/compensation/tests/compensation/test_workflow.py +++ b/compensation/tests/compensation/test_workflow.py @@ -60,8 +60,9 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase): # Preserve the current number of intervention's compensations num_compensations = self.intervention.compensations.count() - self.client_user.post(new_url, post_data) + response = self.client_user.post(new_url, post_data) + self.assertEqual(302, response.status_code) self.intervention.refresh_from_db() self.assertEqual(num_compensations + 1, self.intervention.compensations.count()) new_compensation = self.intervention.compensations.get(identifier=test_id) @@ -261,3 +262,26 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase): self.assertIn(recorded, self.compensation.log.all()) self.assertEqual(pre_record_log_count + 1, self.compensation.log.count()) + def test_non_editable_after_recording(self): + """ Tests that the compensation can not be edited after being recorded + + User must be redirected to another page + + Returns: + + """ + self.assertIsNotNone(self.compensation) + self.assertFalse(self.compensation.is_recorded) + edit_url = reverse("compensation:edit", args=(self.compensation.id,)) + response = self.client_user.get(edit_url) + has_redirect = response.status_code == 302 + self.assertFalse(has_redirect) + + self.compensation.intervention.set_recorded(self.user) + self.assertTrue(self.compensation.is_recorded) + + edit_url = reverse("compensation:edit", args=(self.compensation.id,)) + response = self.client_user.get(edit_url) + has_redirect = response.status_code == 302 + self.assertTrue(has_redirect) + self.compensation.intervention.set_unrecorded(self.user) diff --git a/compensation/tests/ecoaccount/test_workflow.py b/compensation/tests/ecoaccount/test_workflow.py index 03b4996a..bd6894ae 100644 --- a/compensation/tests/ecoaccount/test_workflow.py +++ b/compensation/tests/ecoaccount/test_workflow.py @@ -302,3 +302,27 @@ class EcoAccountWorkflowTestCase(BaseWorkflowTestCase): self.assertEqual(pre_edit_account_log_count + 1, account.log.count()) self.assertEqual(intervention.log.first().action, UserAction.EDITED) self.assertEqual(account.log.first().action, UserAction.EDITED) + + def test_non_editable_after_recording(self): + """ Tests that the eco_account can not be edited after being recorded + + User must be redirected to another page + + Returns: + + """ + self.assertIsNotNone(self.eco_account) + self.assertFalse(self.eco_account.is_recorded) + edit_url = reverse("compensation:acc:edit", args=(self.eco_account.id,)) + response = self.client_user.get(edit_url) + has_redirect = response.status_code == 302 + self.assertFalse(has_redirect) + + self.eco_account.set_recorded(self.user) + self.assertTrue(self.eco_account.is_recorded) + + edit_url = reverse("compensation:acc:edit", args=(self.eco_account.id,)) + response = self.client_user.get(edit_url) + has_redirect = response.status_code == 302 + self.assertTrue(has_redirect) + self.eco_account.set_unrecorded(self.user) diff --git a/ema/tests/test_workflow.py b/ema/tests/test_workflow.py index 3306a21f..ecc3f195 100644 --- a/ema/tests/test_workflow.py +++ b/ema/tests/test_workflow.py @@ -117,6 +117,32 @@ class EmaWorkflowTestCase(BaseWorkflowTestCase): self.assertEqual(pre_edit_log_count + 1, self.ema.log.count()) self.assertEqual(self.ema.log.first().action, UserAction.EDITED) + def test_non_editable_after_recording(self): + """ Tests that the EMA can not be edited after being recorded + + User must be redirected to another page + + Returns: + + """ + self.superuser.groups.add(self.groups.get(name=ETS_GROUP)) + self.assertIsNotNone(self.ema) + self.ema.share_with_user(self.superuser) + self.assertFalse(self.ema.is_recorded) + edit_url = reverse("ema:edit", args=(self.ema.id,)) + response = self.client_user.get(edit_url) + has_redirect = response.status_code == 302 + self.assertFalse(has_redirect) + + self.ema.set_recorded(self.superuser) + self.assertTrue(self.ema.is_recorded) + + edit_url = reverse("ema:edit", args=(self.ema.id,)) + response = self.client_user.get(edit_url) + has_redirect = response.status_code == 302 + self.assertTrue(has_redirect) + self.ema.set_unrecorded(self.superuser) + def test_recordability(self): """ This tests if the recordability of the Ema is triggered by the quality of it's data (e.g. not all fields filled) diff --git a/intervention/tests/test_workflow.py b/intervention/tests/test_workflow.py index c5290503..66770977 100644 --- a/intervention/tests/test_workflow.py +++ b/intervention/tests/test_workflow.py @@ -89,6 +89,30 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase): self.assertIn(self.superuser, obj.users.all()) self.assertEqual(1, obj.users.count()) + def test_non_editable_after_recording(self): + """ Tests that the intervention can not be edited after being recorded + + User must be redirected to another page + + Returns: + + """ + self.assertIsNotNone(self.intervention) + self.assertFalse(self.intervention.is_recorded) + edit_url = reverse("intervention:edit", args=(self.intervention.id,)) + response = self.client_user.get(edit_url) + has_redirect = response.status_code == 302 + self.assertFalse(has_redirect) + + self.intervention.set_recorded(self.user) + self.assertTrue(self.intervention.is_recorded) + + edit_url = reverse("intervention:edit", args=(self.intervention.id,)) + response = self.client_user.get(edit_url) + has_redirect = response.status_code == 302 + self.assertTrue(has_redirect) + self.intervention.set_unrecorded(self.user) + def test_checkability(self): """ Tests that the intervention can only be checked if all required data has been added