From cba174b762e1cac22ca6b003c8d98cc270d343cd Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Thu, 10 Feb 2022 11:45:55 +0100 Subject: [PATCH] #86 Edit view tests * extends view tests --- .../compensation/includes/deadlines.html | 2 +- .../compensation/includes/documents.html | 2 +- .../detail/eco_account/includes/actions.html | 9 +++-- compensation/tests/ecoaccount/test_views.py | 33 +++++++++++++------ compensation/urls/eco_account.py | 8 +++-- compensation/views/eco_account.py | 28 ++++++++++++++-- ema/tests/test_views.py | 33 +++++++++++++------ .../detail/includes/compensations.html | 2 +- .../detail/includes/deductions.html | 2 +- .../detail/includes/documents.html | 2 +- .../detail/includes/payments.html | 2 +- .../detail/includes/revocation.html | 2 +- intervention/tests/test_views.py | 18 ++++++++++ 13 files changed, 109 insertions(+), 34 deletions(-) diff --git a/compensation/templates/compensation/detail/compensation/includes/deadlines.html b/compensation/templates/compensation/detail/compensation/includes/deadlines.html index da4e21d6..0af1498a 100644 --- a/compensation/templates/compensation/detail/compensation/includes/deadlines.html +++ b/compensation/templates/compensation/detail/compensation/includes/deadlines.html @@ -34,7 +34,7 @@ {% trans 'Comment' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} diff --git a/compensation/templates/compensation/detail/compensation/includes/documents.html b/compensation/templates/compensation/detail/compensation/includes/documents.html index e12de4e9..573fd865 100644 --- a/compensation/templates/compensation/detail/compensation/includes/documents.html +++ b/compensation/templates/compensation/detail/compensation/includes/documents.html @@ -34,7 +34,7 @@ {% trans 'Comment' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} diff --git a/compensation/templates/compensation/detail/eco_account/includes/actions.html b/compensation/templates/compensation/detail/eco_account/includes/actions.html index d1275c78..add698e0 100644 --- a/compensation/templates/compensation/detail/eco_account/includes/actions.html +++ b/compensation/templates/compensation/detail/eco_account/includes/actions.html @@ -34,7 +34,7 @@ {% trans 'Comment' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} @@ -60,9 +60,12 @@ {{ action.comment }} - + {% if is_default_member and has_access %} - + {% endif %} diff --git a/compensation/tests/ecoaccount/test_views.py b/compensation/tests/ecoaccount/test_views.py index 670f4f0d..091e86db 100644 --- a/compensation/tests/ecoaccount/test_views.py +++ b/compensation/tests/ecoaccount/test_views.py @@ -44,12 +44,17 @@ class EcoAccountViewTestCase(CompensationViewTestCase): self.edit_url = reverse("compensation:acc:edit", args=(self.eco_account.id,)) self.remove_url = reverse("compensation:acc:remove", args=(self.eco_account.id,)) self.report_url = reverse("compensation:acc:report", args=(self.eco_account.id,)) + self.state_new_url = reverse("compensation:acc:new-state", args=(self.eco_account.id,)) + self.state_edit_url = reverse("compensation:acc:state-edit", args=(self.eco_account.id, self.comp_state.id)) + self.state_remove_url = reverse("compensation:acc:state-remove", args=(self.eco_account.id, self.comp_state.id,)) + self.action_new_url = reverse("compensation:acc:new-action", args=(self.eco_account.id,)) + self.action_edit_url = reverse("compensation:acc:action-edit", args=(self.eco_account.id, self.comp_action.id)) + self.action_remove_url = reverse("compensation:acc:action-remove", args=(self.eco_account.id, self.comp_action.id,)) + self.deadline_new_url = reverse("compensation:acc:new-deadline", args=(self.eco_account.id,)) self.new_doc_url = reverse("compensation:acc:new-doc", args=(self.eco_account.id,)) - self.state_remove_url = reverse("compensation:acc:state-remove", args=(self.eco_account.id, self.comp_state.id,)) - self.action_remove_url = reverse("compensation:acc:action-remove", args=(self.eco_account.id, self.comp_action.id,)) def test_logged_in_no_groups_shared(self): """ Check correct status code for all requests @@ -78,10 +83,12 @@ class EcoAccountViewTestCase(CompensationViewTestCase): self.edit_url, self.remove_url, self.state_new_url, - self.action_new_url, - self.deadline_new_url, + self.state_edit_url, self.state_remove_url, + self.action_new_url, + self.action_edit_url, self.action_remove_url, + self.deadline_new_url, self.new_doc_url, ] @@ -115,10 +122,12 @@ class EcoAccountViewTestCase(CompensationViewTestCase): self.edit_url, self.remove_url, self.state_new_url, - self.action_new_url, - self.deadline_new_url, + self.state_edit_url, self.state_remove_url, + self.action_new_url, + self.action_edit_url, self.action_remove_url, + self.deadline_new_url, self.new_doc_url, ] @@ -149,11 +158,13 @@ class EcoAccountViewTestCase(CompensationViewTestCase): self.new_id_url, self.edit_url, self.state_new_url, - self.action_new_url, - self.deadline_new_url, + self.state_edit_url, self.state_remove_url, + self.action_new_url, + self.action_edit_url, self.action_remove_url, self.new_doc_url, + self.deadline_new_url, self.log_url, self.remove_url, ] @@ -184,13 +195,15 @@ class EcoAccountViewTestCase(CompensationViewTestCase): fail_urls = [ self.edit_url, self.state_new_url, - self.action_new_url, - self.deadline_new_url, + self.state_edit_url, self.state_remove_url, + self.action_new_url, + self.action_edit_url, self.action_remove_url, self.new_doc_url, self.log_url, self.remove_url, + self.deadline_new_url, ] self.assert_url_fail(client, fail_urls) self.assert_url_success(client, success_urls) diff --git a/compensation/urls/eco_account.py b/compensation/urls/eco_account.py index f23f2a11..ccd549dd 100644 --- a/compensation/urls/eco_account.py +++ b/compensation/urls/eco_account.py @@ -19,11 +19,15 @@ urlpatterns = [ path('/report', report_view, name='report'), path('/edit', edit_view, name='edit'), path('/remove', remove_view, name='remove'), + path('/state/new', state_new_view, name='new-state'), - path('/action/new', action_new_view, name='new-action'), - path('/state//remove', state_remove_view, name='state-remove'), path('/state//edit', state_edit_view, name='state-edit'), + path('/state//remove', state_remove_view, name='state-remove'), + + path('/action/new', action_new_view, name='new-action'), + path('/action//edit', action_edit_view, name='action-edit'), path('/action//remove', action_remove_view, name='action-remove'), + path('/deadline//remove', deadline_remove_view, name='deadline-remove'), path('/deadline/new', deadline_new_view, name="new-deadline"), path('/share/', share_view, name='share'), diff --git a/compensation/views/eco_account.py b/compensation/views/eco_account.py index a0365068..37223786 100644 --- a/compensation/views/eco_account.py +++ b/compensation/views/eco_account.py @@ -17,7 +17,7 @@ from django.shortcuts import render, get_object_or_404, redirect from compensation.forms.forms import NewEcoAccountForm, EditEcoAccountForm from compensation.forms.modalForms import NewStateModalForm, NewActionModalForm, NewDeadlineModalForm, \ NewEcoAccountDocumentModalForm, RemoveCompensationActionModalForm, RemoveCompensationStateModalForm, \ - EditCompensationStateModalForm + EditCompensationStateModalForm, EditCompensationActionModalForm from compensation.models import EcoAccount, EcoAccountDocument, CompensationState, CompensationAction from compensation.tables import EcoAccountTable from intervention.forms.modalForms import NewDeductionModalForm, ShareModalForm, RemoveEcoAccountDeductionModalForm, \ @@ -35,7 +35,7 @@ from konova.utils.generators import generate_qr_code from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \ CANCEL_ACC_RECORDED_OR_DEDUCTED, DEDUCTION_REMOVED, DEDUCTION_ADDED, DOCUMENT_ADDED, COMPENSATION_STATE_REMOVED, \ COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED, DEADLINE_ADDED, DEADLINE_REMOVED, \ - DEDUCTION_EDITED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED + DEDUCTION_EDITED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED from konova.utils.user_checks import in_group @@ -491,6 +491,30 @@ def action_remove_view(request: HttpRequest, id: str, action_id: str): ) +@login_required +@default_group_required +@shared_access_required(EcoAccount, "id") +def action_edit_view(request: HttpRequest, id: str, action_id: str): + """ Renders a form for editing a compensation action + + Args: + request (HttpRequest): The incoming request + id (str): The compensation's id + id (str): The action's id + + Returns: + + """ + acc = get_object_or_404(EcoAccount, id=id) + action = get_object_or_404(CompensationAction, id=action_id) + form = EditCompensationActionModalForm(request.POST or None, instance=acc, action=action, request=request) + return form.process_request( + request, + msg_success=COMPENSATION_ACTION_EDITED, + redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data" + ) + + @login_required @default_group_required @shared_access_required(EcoAccount, "id") diff --git a/ema/tests/test_views.py b/ema/tests/test_views.py index 65f4d351..70090c7d 100644 --- a/ema/tests/test_views.py +++ b/ema/tests/test_views.py @@ -54,12 +54,17 @@ class EmaViewTestCase(CompensationViewTestCase): self.record_url = reverse("ema:record", args=(self.ema.id,)) self.report_url = reverse("ema:report", args=(self.ema.id,)) self.new_doc_url = reverse("ema:new-doc", args=(self.ema.id,)) + self.state_new_url = reverse("ema:new-state", args=(self.ema.id,)) - self.action_new_url = reverse("ema:new-action", args=(self.ema.id,)) - self.deadline_new_url = reverse("ema:new-deadline", args=(self.ema.id,)) + self.state_edit_url = reverse("ema:state-edit", args=(self.ema.id, state.id)) self.state_remove_url = reverse("ema:state-remove", args=(self.ema.id, state.id,)) + + self.action_new_url = reverse("ema:new-action", args=(self.ema.id,)) + self.action_edit_url = reverse("ema:action-edit", args=(self.ema.id, action.id)) self.action_remove_url = reverse("ema:action-remove", args=(self.ema.id, action.id,)) + self.deadline_new_url = reverse("ema:new-deadline", args=(self.ema.id,)) + def create_dummy_data(self): # Create dummy data # Create log entry @@ -108,10 +113,12 @@ class EmaViewTestCase(CompensationViewTestCase): self.new_id_url, self.edit_url, self.state_new_url, - self.action_new_url, - self.deadline_new_url, self.state_remove_url, + self.state_edit_url, + self.deadline_new_url, + self.action_edit_url, self.action_remove_url, + self.action_new_url, self.new_doc_url, self.log_url, self.remove_url, @@ -154,10 +161,12 @@ class EmaViewTestCase(CompensationViewTestCase): self.new_id_url, self.edit_url, self.state_new_url, - self.action_new_url, - self.deadline_new_url, + self.state_edit_url, self.state_remove_url, + self.action_new_url, + self.action_edit_url, self.action_remove_url, + self.deadline_new_url, self.new_doc_url, self.log_url, self.remove_url, @@ -191,9 +200,11 @@ class EmaViewTestCase(CompensationViewTestCase): self.new_id_url, self.edit_url, self.state_new_url, - self.action_new_url, - self.deadline_new_url, + self.state_edit_url, self.state_remove_url, + self.deadline_new_url, + self.action_new_url, + self.action_edit_url, self.action_remove_url, self.new_doc_url, self.log_url, @@ -229,9 +240,11 @@ class EmaViewTestCase(CompensationViewTestCase): fail_urls = [ self.edit_url, self.state_new_url, - self.action_new_url, - self.deadline_new_url, + self.state_edit_url, self.state_remove_url, + self.deadline_new_url, + self.action_new_url, + self.action_edit_url, self.action_remove_url, self.new_doc_url, self.log_url, diff --git a/intervention/templates/intervention/detail/includes/compensations.html b/intervention/templates/intervention/detail/includes/compensations.html index b7a546dd..c572a344 100644 --- a/intervention/templates/intervention/detail/includes/compensations.html +++ b/intervention/templates/intervention/detail/includes/compensations.html @@ -33,7 +33,7 @@ {% trans 'Title' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} diff --git a/intervention/templates/intervention/detail/includes/deductions.html b/intervention/templates/intervention/detail/includes/deductions.html index b11817d1..04110b8b 100644 --- a/intervention/templates/intervention/detail/includes/deductions.html +++ b/intervention/templates/intervention/detail/includes/deductions.html @@ -34,7 +34,7 @@ {% trans 'Created' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} diff --git a/intervention/templates/intervention/detail/includes/documents.html b/intervention/templates/intervention/detail/includes/documents.html index 93309f5c..9fccc4b7 100644 --- a/intervention/templates/intervention/detail/includes/documents.html +++ b/intervention/templates/intervention/detail/includes/documents.html @@ -34,7 +34,7 @@ {% trans 'Comment' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} diff --git a/intervention/templates/intervention/detail/includes/payments.html b/intervention/templates/intervention/detail/includes/payments.html index 4bf00cd8..65408e47 100644 --- a/intervention/templates/intervention/detail/includes/payments.html +++ b/intervention/templates/intervention/detail/includes/payments.html @@ -34,7 +34,7 @@ {% trans 'Comment' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} diff --git a/intervention/templates/intervention/detail/includes/revocation.html b/intervention/templates/intervention/detail/includes/revocation.html index 6eb68f99..39738d24 100644 --- a/intervention/templates/intervention/detail/includes/revocation.html +++ b/intervention/templates/intervention/detail/includes/revocation.html @@ -37,7 +37,7 @@ {% trans 'Comment' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} diff --git a/intervention/tests/test_views.py b/intervention/tests/test_views.py index 68e4b562..f12ee7a3 100644 --- a/intervention/tests/test_views.py +++ b/intervention/tests/test_views.py @@ -40,12 +40,14 @@ class InterventionViewTestCase(BaseViewTestCase): self.deduction.intervention = self.intervention self.deduction.save() self.deduction_new_url = reverse("intervention:new-deduction", args=(self.intervention.id,)) + self.deduction_edit_url = reverse("intervention:edit-deduction", args=(self.intervention.id, self.deduction.id,)) self.deduction_remove_url = reverse("intervention:remove-deduction", args=(self.intervention.id, self.deduction.id)) self.revocation = Revocation.objects.create( legal=self.intervention.legal ) self.revocation_new_url = reverse("intervention:new-revocation", args=(self.intervention.id,)) + self.revocation_edit_url = reverse("intervention:edit-revocation", args=(self.intervention.id, self.revocation.id)) self.revocation_remove_url = reverse("intervention:remove-revocation", args=(self.intervention.id, self.revocation.id)) def test_views_anonymous_user(self): @@ -76,8 +78,10 @@ class InterventionViewTestCase(BaseViewTestCase): self.run_check_url: f"{login_redirect_base}{self.run_check_url}", self.record_url: f"{login_redirect_base}{self.record_url}", self.deduction_new_url: f"{login_redirect_base}{self.deduction_new_url}", + self.deduction_edit_url: f"{login_redirect_base}{self.deduction_edit_url}", self.deduction_remove_url: f"{login_redirect_base}{self.deduction_remove_url}", self.revocation_new_url: f"{login_redirect_base}{self.revocation_new_url}", + self.revocation_edit_url: f"{login_redirect_base}{self.revocation_edit_url}", self.revocation_remove_url: f"{login_redirect_base}{self.revocation_remove_url}", } @@ -115,8 +119,10 @@ class InterventionViewTestCase(BaseViewTestCase): self.run_check_url, self.record_url, self.revocation_new_url, + self.revocation_edit_url, self.revocation_remove_url, self.deduction_new_url, + self.deduction_edit_url, self.deduction_remove_url, ] @@ -151,8 +157,10 @@ class InterventionViewTestCase(BaseViewTestCase): self.remove_url, self.share_create_url, self.revocation_new_url, + self.revocation_edit_url, self.revocation_remove_url, self.deduction_new_url, + self.deduction_edit_url, self.deduction_remove_url, ] fail_urls = [ @@ -199,8 +207,10 @@ class InterventionViewTestCase(BaseViewTestCase): self.share_create_url, self.log_url, self.revocation_new_url, + self.revocation_edit_url, self.revocation_remove_url, self.deduction_new_url, + self.deduction_edit_url, self.deduction_remove_url, ] success_urls_redirect = { @@ -243,8 +253,10 @@ class InterventionViewTestCase(BaseViewTestCase): self.share_create_url, self.record_url, self.revocation_new_url, + self.revocation_edit_url, self.revocation_remove_url, self.deduction_new_url, + self.deduction_edit_url, self.deduction_remove_url, ] success_urls_redirect = { @@ -287,8 +299,10 @@ class InterventionViewTestCase(BaseViewTestCase): self.record_url, self.run_check_url, self.revocation_new_url, + self.revocation_edit_url, self.revocation_remove_url, self.deduction_new_url, + self.deduction_edit_url, self.deduction_remove_url, ] success_urls_redirect = { @@ -331,8 +345,10 @@ class InterventionViewTestCase(BaseViewTestCase): self.share_create_url, self.run_check_url, self.revocation_new_url, + self.revocation_edit_url, self.revocation_remove_url, self.deduction_new_url, + self.deduction_edit_url, self.deduction_remove_url, ] success_urls_redirect = { @@ -375,8 +391,10 @@ class InterventionViewTestCase(BaseViewTestCase): self.share_create_url, self.run_check_url, self.revocation_new_url, + self.revocation_edit_url, self.revocation_remove_url, self.deduction_new_url, + self.deduction_edit_url, self.deduction_remove_url, ] # Define urls where a redirect to a specific location is the proper response