Further tests

* adds tests for intervention workflow
This commit is contained in:
mpeltriaux 2022-02-08 12:07:49 +01:00
parent 00c1bb67ca
commit 13fd3e1fcb

View File

@ -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.