#86 Edit view tests

* extends view tests
pull/111/head
mpeltriaux 3 years ago
parent 792b4a4632
commit c88bbdabbc

@ -34,7 +34,7 @@
{% trans 'Comment' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
<th class="w-10" scope="col">
<span class="float-right">
{% trans 'Action' %}
</span>

@ -34,7 +34,7 @@
{% trans 'Comment' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
<th class="w-10" scope="col">
<span class="float-right">
{% trans 'Action' %}
</span>

@ -34,7 +34,7 @@
{% trans 'Comment' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
<th class="w-10" scope="col">
<span class="float-right">
{% trans 'Action' %}
</span>
@ -60,9 +60,12 @@
{{ action.comment }}
</div>
</td>
<td class="">
<td class="align-middle float-right">
{% if is_default_member and has_access %}
<button data-form-url="{% url 'compensation:acc:action-remove' obj.id action.id %}" class="btn btn-default btn-modal float-right" title="{% trans 'Remove action' %}">
<button data-form-url="{% url 'compensation:acc:action-edit' obj.id action.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit action' %}">
{% fa5_icon 'edit' %}
</button>
<button data-form-url="{% url 'compensation:acc:action-remove' obj.id action.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove action' %}">
{% fa5_icon 'trash' %}
</button>
{% endif %}

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

@ -19,11 +19,15 @@ urlpatterns = [
path('<id>/report', report_view, name='report'),
path('<id>/edit', edit_view, name='edit'),
path('<id>/remove', remove_view, name='remove'),
path('<id>/state/new', state_new_view, name='new-state'),
path('<id>/action/new', action_new_view, name='new-action'),
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
path('<id>/state/<state_id>/edit', state_edit_view, name='state-edit'),
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
path('<id>/action/new', action_new_view, name='new-action'),
path('<id>/action/<action_id>/edit', action_edit_view, name='action-edit'),
path('<id>/action/<action_id>/remove', action_remove_view, name='action-remove'),
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'),
path('<id>/deadline/new', deadline_new_view, name="new-deadline"),
path('<id>/share/<token>', share_view, name='share'),

@ -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")

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

@ -33,7 +33,7 @@
{% trans 'Title' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
<th class="w-10" scope="col">
<span class="float-right">
{% trans 'Action' %}
</span>

@ -34,7 +34,7 @@
{% trans 'Created' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
<th class="w-10" scope="col">
<span class="float-right">
{% trans 'Action' %}
</span>

@ -34,7 +34,7 @@
{% trans 'Comment' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
<th class="w-10" scope="col">
<span class="float-right">
{% trans 'Action' %}
</span>

@ -34,7 +34,7 @@
{% trans 'Comment' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
<th class="w-10" scope="col">
<span class="float-right">
{% trans 'Action' %}
</span>

@ -37,7 +37,7 @@
{% trans 'Comment' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
<th class="w-10" scope="col">
<span class="float-right">
{% trans 'Action' %}
</span>

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

Loading…
Cancel
Save