#86 Edit payment
* adds button for payment editing * adds new edit form payment editing * adds tests for views and workflowpull/111/head
parent
c5e3800c34
commit
ce9143e4b2
@ -0,0 +1,7 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 09.02.22
|
||||
|
||||
"""
|
@ -0,0 +1,154 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 09.02.22
|
||||
|
||||
"""
|
||||
from django.urls import reverse
|
||||
from django.test.client import Client
|
||||
|
||||
from compensation.models import Payment
|
||||
from konova.settings import DEFAULT_GROUP
|
||||
from konova.tests.test_views import BaseViewTestCase
|
||||
|
||||
|
||||
class PaymentViewTestCase(BaseViewTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls) -> None:
|
||||
super().setUpTestData()
|
||||
|
||||
cls.payment = Payment.objects.get_or_create(
|
||||
intervention=cls.intervention,
|
||||
amount=1,
|
||||
due_on="2020-01-01",
|
||||
comment="Testcomment"
|
||||
)[0]
|
||||
|
||||
cls.new_url = reverse("compensation:pay:new", args=(cls.intervention.id,))
|
||||
cls.edit_url = reverse("compensation:pay:edit", args=(cls.intervention.id, cls.payment.id))
|
||||
cls.remove_url = reverse("compensation:pay:remove", args=(cls.intervention.id, cls.payment.id))
|
||||
|
||||
def test_anonymous_user(self):
|
||||
""" Check correct status code for all requests
|
||||
|
||||
Assumption: User not logged in
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
client = Client()
|
||||
|
||||
success_urls = [
|
||||
]
|
||||
fail_urls = [
|
||||
self.new_url,
|
||||
self.edit_url,
|
||||
self.remove_url,
|
||||
]
|
||||
|
||||
self.assert_url_success(client, success_urls)
|
||||
self.assert_url_fail(client, fail_urls)
|
||||
|
||||
def test_logged_in_no_groups_shared(self):
|
||||
""" Check correct status code for all requests
|
||||
|
||||
Assumption: User logged in and has no groups and data is shared
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
client = Client()
|
||||
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||
self.superuser.groups.set([])
|
||||
self.intervention.share_with_list([self.superuser])
|
||||
|
||||
# Since the user has no groups, it does not matter that data has been shared. There SHOULD not be any difference
|
||||
# to a user without access, since the important permissions are missing
|
||||
success_urls = [
|
||||
]
|
||||
fail_urls = [
|
||||
self.new_url,
|
||||
self.edit_url,
|
||||
self.remove_url,
|
||||
]
|
||||
|
||||
self.assert_url_success(client, success_urls)
|
||||
self.assert_url_fail(client, fail_urls)
|
||||
|
||||
def test_logged_in_no_groups_unshared(self):
|
||||
""" Check correct status code for all requests
|
||||
|
||||
Assumption: User logged in and has no groups and data is not shared
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
client = Client()
|
||||
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||
self.superuser.groups.set([])
|
||||
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
||||
self.intervention.share_with_list([])
|
||||
|
||||
# Since the user has no groups, it does not matter that data is unshared. There SHOULD not be any difference
|
||||
# to a user having shared access, since all important permissions are missing
|
||||
success_urls = [
|
||||
]
|
||||
fail_urls = [
|
||||
self.new_url,
|
||||
self.edit_url,
|
||||
self.remove_url,
|
||||
]
|
||||
|
||||
self.assert_url_success(client, success_urls)
|
||||
self.assert_url_fail(client, fail_urls)
|
||||
|
||||
def test_logged_in_default_group_shared(self):
|
||||
""" Check correct status code for all requests
|
||||
|
||||
Assumption: User logged in, is default group member and data is shared
|
||||
--> Default group necessary since all base functionalities depend on this group membership
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
client = Client()
|
||||
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||
group = self.groups.get(name=DEFAULT_GROUP)
|
||||
self.superuser.groups.set([group])
|
||||
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
||||
self.intervention.share_with_list([self.superuser])
|
||||
|
||||
success_urls = [
|
||||
self.new_url,
|
||||
self.edit_url,
|
||||
self.remove_url,
|
||||
]
|
||||
self.assert_url_success(client, success_urls)
|
||||
|
||||
def test_logged_in_default_group_unshared(self):
|
||||
""" Check correct status code for all requests
|
||||
|
||||
Assumption: User logged in, is default group member and data is NOT shared
|
||||
--> Default group necessary since all base functionalities depend on this group membership
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
client = Client()
|
||||
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||
group = self.groups.get(name=DEFAULT_GROUP)
|
||||
self.superuser.groups.set([group])
|
||||
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
||||
self.intervention.share_with_list([])
|
||||
|
||||
success_urls = [
|
||||
]
|
||||
fail_urls = [
|
||||
self.new_url,
|
||||
self.edit_url,
|
||||
self.remove_url,
|
||||
]
|
||||
self.assert_url_fail(client, fail_urls)
|
||||
self.assert_url_success(client, success_urls)
|
@ -0,0 +1,125 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 09.02.22
|
||||
|
||||
"""
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.urls import reverse
|
||||
|
||||
from compensation.models import Payment
|
||||
from konova.tests.test_views import BaseWorkflowTestCase
|
||||
from user.models import UserAction
|
||||
|
||||
|
||||
class PaymentWorkflowTestCase(BaseWorkflowTestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
super().setUpTestData()
|
||||
|
||||
# Give the user shared access to the dummy intervention
|
||||
cls.intervention.share_with(cls.superuser)
|
||||
|
||||
cls.payment = Payment.objects.get_or_create(
|
||||
intervention=cls.intervention,
|
||||
amount=1,
|
||||
due_on="2020-01-01",
|
||||
comment="Testcomment"
|
||||
)[0]
|
||||
|
||||
def test_new(self):
|
||||
""" Test the creation of a payment
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
# Prepare url and form data to be posted
|
||||
new_url = reverse("compensation:pay:new", args=(self.intervention.id,))
|
||||
test_amount = 12345
|
||||
test_due_on = "1970-01-01"
|
||||
test_comment = self.create_dummy_string()
|
||||
post_data = {
|
||||
"amount": test_amount,
|
||||
"due": test_due_on,
|
||||
"comment": test_comment,
|
||||
}
|
||||
pre_creation_intervention_log_count = self.intervention.log.count()
|
||||
num_payments = self.intervention.payments.count()
|
||||
|
||||
self.client_user.post(new_url, post_data)
|
||||
|
||||
self.intervention.refresh_from_db()
|
||||
|
||||
self.assertEqual(num_payments + 1, self.intervention.payments.count())
|
||||
new_payment = self.intervention.payments.get(amount=test_amount)
|
||||
self.assertEqual(new_payment.amount, test_amount)
|
||||
self.assertEqual(str(new_payment.due_on), test_due_on)
|
||||
self.assertEqual(new_payment.comment, test_comment)
|
||||
|
||||
# Expect logs to be set
|
||||
self.assertEqual(pre_creation_intervention_log_count + 1, self.intervention.log.count())
|
||||
self.assertEqual(self.intervention.log.first().action, UserAction.EDITED)
|
||||
|
||||
def test_edit(self):
|
||||
""" Test edit of a payment
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
# Prepare url and form data to be posted
|
||||
new_url = reverse("compensation:pay:edit", args=(self.intervention.id, self.payment.id))
|
||||
test_amount = self.payment.amount * 2
|
||||
test_due_on = "1970-01-01"
|
||||
test_comment = self.create_dummy_string()
|
||||
post_data = {
|
||||
"amount": test_amount,
|
||||
"due": test_due_on,
|
||||
"comment": test_comment,
|
||||
}
|
||||
pre_edit_intervention_log_count = self.intervention.log.count()
|
||||
num_payments = self.intervention.payments.count()
|
||||
|
||||
self.client_user.post(new_url, post_data)
|
||||
|
||||
self.intervention.refresh_from_db()
|
||||
self.payment.refresh_from_db()
|
||||
|
||||
self.assertEqual(num_payments, self.intervention.payments.count())
|
||||
self.assertEqual(self.payment.amount, test_amount)
|
||||
self.assertEqual(str(self.payment.due_on), test_due_on)
|
||||
self.assertEqual(self.payment.comment, test_comment)
|
||||
|
||||
# Expect logs to be set
|
||||
self.assertEqual(pre_edit_intervention_log_count + 1, self.intervention.log.count())
|
||||
self.assertEqual(self.intervention.log.first().action, UserAction.EDITED)
|
||||
|
||||
def test_remove(self):
|
||||
""" Test remove of a payment
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
# Prepare url and form data to be posted
|
||||
new_url = reverse("compensation:pay:remove", args=(self.intervention.id, self.payment.id))
|
||||
post_data = {
|
||||
"confirm": True,
|
||||
}
|
||||
pre_remove_intervention_log_count = self.intervention.log.count()
|
||||
num_payments = self.intervention.payments.count()
|
||||
|
||||
self.client_user.post(new_url, post_data)
|
||||
|
||||
self.intervention.refresh_from_db()
|
||||
try:
|
||||
self.payment.refresh_from_db()
|
||||
self.fail(msg="Payment still exists after delete")
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
|
||||
self.assertEqual(num_payments - 1, self.intervention.payments.count())
|
||||
|
||||
# Expect logs to be set
|
||||
self.assertEqual(pre_remove_intervention_log_count + 1, self.intervention.log.count())
|
||||
self.assertEqual(self.intervention.log.first().action, UserAction.EDITED)
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue