From 43bc3517ff5ca0468b918de66a5d42f82f8867fb Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Tue, 8 Feb 2022 12:07:49 +0100 Subject: [PATCH] Further tests * adds tests for intervention workflow --- intervention/tests/test_workflow.py | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/intervention/tests/test_workflow.py b/intervention/tests/test_workflow.py index fbc2f81f..7644051b 100644 --- a/intervention/tests/test_workflow.py +++ b/intervention/tests/test_workflow.py @@ -74,6 +74,9 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase): self.assertEqual(obj.identifier, test_id) self.assertEqual(obj.title, test_title) self.assert_equal_geometries(obj.geometry.geom, test_geom) + self.assertEqual(1, obj.log.count()) + self.assertEqual(obj.log.first().action, UserAction.CREATED) + self.assertEqual(obj.log.first().user, self.superuser) except ObjectDoesNotExist: # Fail if there is no such object self.fail() @@ -215,6 +218,8 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase): # Make sure there are no payments on the intervention, yet self.assertEqual(0, self.intervention.payments.count()) + pre_payment_logs_count = self.intervention.log.count() + # Create form data to be sent to the url test_amount = 10.00 test_due = "2021-01-01" @@ -239,6 +244,10 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase): self.assertEqual(payment.amount, test_amount) self.assertEqual(payment.due_on, datetime.date.fromisoformat(test_due)) self.assertEqual(payment.comment, test_comment) + + # Make sure a log entry has been created + self.assertEqual(self.intervention.log.first().action, UserAction.EDITED) + self.assertEqual(pre_payment_logs_count + 1, self.intervention.log.count()) return payment def subtest_delete_payment(self, payment: Payment): @@ -250,6 +259,8 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase): Returns: """ + pre_payment_logs_count = self.intervention.log.count() + # Create removing url for the payment remove_url = reverse("compensation:pay:remove", args=(payment.id,)) post_data = { @@ -266,6 +277,11 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase): # Now make sure the intervention has no payments anymore self.assertEqual(0, self.intervention.payments.count()) + # Make sure a log entry has been created + self.assertEqual(self.intervention.log.first().action, UserAction.EDITED) + self.assertEqual(self.intervention.log.first().user, self.superuser) + self.assertEqual(pre_payment_logs_count + 1, self.intervention.log.count()) + def test_payments(self): """ Checks a 'normal' case of adding a payment. @@ -353,6 +369,8 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase): Returns: """ + pre_deduction_logs_count = self.intervention.log.count() + # Prepare the account for a working situation (enough deductable surface, recorded and shared) self.eco_account.deductable_surface = 10000.00 if self.eco_account.recorded is None: @@ -376,6 +394,11 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase): ) self.assertEqual(deduction.surface, test_surface) + # Make sure a log entry has been created + self.assertEqual(self.intervention.log.first().action, UserAction.EDITED) + self.assertEqual(self.intervention.log.first().user, self.superuser) + self.assertEqual(pre_deduction_logs_count + 1, self.intervention.log.count()) + # Return deduction for further usage in tests return deduction @@ -414,6 +437,8 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase): Returns: """ + pre_delete_logs_count = self.intervention.log.count() + # Prepare url for deleting of this deduction delete_url = reverse("compensation:acc:remove-deduction", args=(self.eco_account.id, deduction.id,)) post_data = { @@ -433,6 +458,11 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase): # Expect the deduction to be totally gone self.assert_object_is_deleted(deduction) + # Make sure a log entry has been created + self.assertEqual(self.intervention.log.first().action, UserAction.EDITED) + self.assertEqual(self.intervention.log.first().user, self.superuser) + self.assertEqual(pre_delete_logs_count + 1, self.intervention.log.count()) + def test_deduction(self): """ Checks a 'normal case of adding a deduction.