#19 Tests
* adds EMA tests * extends compensation tests * fixes bugs detected by testing * restructured tests for performance boost
This commit is contained in:
@@ -20,6 +20,8 @@ urlpatterns = [
|
||||
path('<id>/remove', remove_view, name='acc-remove'),
|
||||
path('<id>/state/new', state_new_view, name='acc-new-state'),
|
||||
path('<id>/action/new', action_new_view, name='acc-new-action'),
|
||||
path('<id>/state/<state_id>/remove', state_remove_view, name='acc-state-remove'),
|
||||
path('<id>/action/<action_id>/remove', action_remove_view, name='acc-action-remove'),
|
||||
path('<id>/deadline/new', deadline_new_view, name="acc-new-deadline"),
|
||||
path('<id>/share/<token>', share_view, name='share'),
|
||||
path('<id>/share', create_share_view, name='share-create'),
|
||||
|
||||
@@ -20,6 +20,8 @@ urlpatterns = [
|
||||
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>/action/<action_id>/remove', action_remove_view, name='action-remove'),
|
||||
path('<id>/deadline/new', deadline_new_view, name="new-deadline"),
|
||||
path('<id>/report', report_view, name='report'),
|
||||
|
||||
@@ -28,10 +30,4 @@ urlpatterns = [
|
||||
path('document/<doc_id>', get_document_view, name='get-doc'),
|
||||
path('document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
||||
|
||||
# Generic state routes
|
||||
path('state/<id>/remove', state_remove_view, name='state-remove'),
|
||||
|
||||
# Generic action routes
|
||||
path('action/<id>/remove', action_remove_view, name='action-remove'),
|
||||
|
||||
]
|
||||
@@ -50,7 +50,7 @@
|
||||
<td class="align-middle">{{ action.comment|default_if_none:"" }}</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:action-remove' action.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove action' %}">
|
||||
<button data-form-url="{% url 'compensation:action-remove' obj.id action.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove action' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<td class="align-middle">{{ state.surface|floatformat:2 }} m²</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:state-remove' state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||
<button data-form-url="{% url 'compensation:state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<td class="align-middle">{{ state.surface|floatformat:2 }} m²</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:state-remove' state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||
<button data-form-url="{% url 'compensation:state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
<td class="align-middle">{{ action.comment|default_if_none:"" }}</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:action-remove' action.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove action' %}">
|
||||
<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 %}
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<td class="align-middle">{{ state.surface|floatformat:2 }} m²</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:state-remove' state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||
<button data-form-url="{% url 'compensation:acc-state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<td class="align-middle">{{ state.surface|floatformat:2 }} m²</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:state-remove' state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||
<button data-form-url="{% url 'compensation:acc-state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
@@ -8,60 +8,76 @@ Created on: 27.10.21
|
||||
from django.urls import reverse
|
||||
from django.test import Client
|
||||
|
||||
from compensation.models import CompensationState, CompensationAction
|
||||
from konova.settings import DEFAULT_GROUP
|
||||
from konova.tests.test_views import BaseViewTestCase
|
||||
|
||||
|
||||
class ViewTestCase(BaseViewTestCase):
|
||||
class CompensationViewTestCase(BaseViewTestCase):
|
||||
"""
|
||||
These tests focus on proper returned views depending on the user's groups privileges and login status
|
||||
|
||||
"""
|
||||
comp_state = None
|
||||
comp_action = None
|
||||
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.create_dummy_states()
|
||||
self.create_dummy_action()
|
||||
@classmethod
|
||||
def setUpTestData(cls) -> None:
|
||||
super().setUpTestData()
|
||||
state = cls.create_dummy_states()
|
||||
cls.compensation.before_states.set([state])
|
||||
cls.compensation.after_states.set([state])
|
||||
|
||||
action = cls.create_dummy_action()
|
||||
cls.compensation.actions.set([action])
|
||||
|
||||
# Prepare urls
|
||||
self.index_url = reverse("compensation:index", args=())
|
||||
self.new_url = reverse("compensation:new", args=(self.intervention.id,))
|
||||
self.new_id_url = reverse("compensation:new-id", args=())
|
||||
self.detail_url = reverse("compensation:detail", args=(self.compensation.id,))
|
||||
self.log_url = reverse("compensation:log", args=(self.compensation.id,))
|
||||
self.edit_url = reverse("compensation:edit", args=(self.compensation.id,))
|
||||
self.remove_url = reverse("compensation:remove", args=(self.compensation.id,))
|
||||
self.report_url = reverse("compensation:report", args=(self.compensation.id,))
|
||||
self.state_new_url = reverse("compensation:new-state", args=(self.compensation.id,))
|
||||
self.action_new_url = reverse("compensation:new-action", args=(self.compensation.id,))
|
||||
self.deadline_new_url = reverse("compensation:new-deadline", args=(self.compensation.id,))
|
||||
self.new_doc_url = reverse("compensation:new-doc", args=(self.compensation.id,))
|
||||
cls.index_url = reverse("compensation:index", args=())
|
||||
cls.new_url = reverse("compensation:new", args=(cls.intervention.id,))
|
||||
cls.new_id_url = reverse("compensation:new-id", args=())
|
||||
cls.detail_url = reverse("compensation:detail", args=(cls.compensation.id,))
|
||||
cls.log_url = reverse("compensation:log", args=(cls.compensation.id,))
|
||||
cls.edit_url = reverse("compensation:edit", args=(cls.compensation.id,))
|
||||
cls.remove_url = reverse("compensation:remove", args=(cls.compensation.id,))
|
||||
cls.report_url = reverse("compensation:report", args=(cls.compensation.id,))
|
||||
cls.state_new_url = reverse("compensation:new-state", args=(cls.compensation.id,))
|
||||
cls.action_new_url = reverse("compensation:new-action", args=(cls.compensation.id,))
|
||||
cls.deadline_new_url = reverse("compensation:new-deadline", args=(cls.compensation.id,))
|
||||
cls.new_doc_url = reverse("compensation:new-doc", args=(cls.compensation.id,))
|
||||
|
||||
self.state_remove_url = reverse("compensation:state-remove", args=(self.comp_state.id,))
|
||||
self.action_remove_url = reverse("compensation:action-remove", args=(self.comp_action.id,))
|
||||
cls.state_remove_url = reverse("compensation:state-remove", args=(cls.compensation.id, cls.comp_state.id,))
|
||||
cls.action_remove_url = reverse("compensation:action-remove", args=(cls.compensation.id, cls.comp_action.id,))
|
||||
|
||||
def create_dummy_states(self):
|
||||
""" Creates an intervention which can be used for tests
|
||||
def test_anonymous_user(self):
|
||||
""" Check correct status code for all requests
|
||||
|
||||
Assumption: User not logged in
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self.comp_state = CompensationState.objects.create(
|
||||
surface=10.00,
|
||||
biotope_type=None,
|
||||
)
|
||||
self.compensation.before_states.set([self.comp_state])
|
||||
self.compensation.after_states.set([self.comp_state])
|
||||
client = Client()
|
||||
|
||||
def create_dummy_action(self):
|
||||
""" Creates an intervention which can be used for tests
|
||||
success_urls = [
|
||||
self.report_url,
|
||||
]
|
||||
fail_urls = [
|
||||
self.index_url,
|
||||
self.detail_url,
|
||||
self.new_url,
|
||||
self.new_id_url,
|
||||
self.log_url,
|
||||
self.edit_url,
|
||||
self.remove_url,
|
||||
self.state_new_url,
|
||||
self.action_new_url,
|
||||
self.deadline_new_url,
|
||||
self.state_remove_url,
|
||||
self.action_remove_url,
|
||||
self.new_doc_url,
|
||||
]
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self.comp_action = CompensationAction.objects.create(
|
||||
amount=10
|
||||
)
|
||||
self.compensation.actions.set([self.comp_action])
|
||||
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
|
||||
@@ -111,6 +127,7 @@ class ViewTestCase(BaseViewTestCase):
|
||||
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.users.set([])
|
||||
|
||||
# Since the user has no groups, it does not matter that data is unshared. There SHOULD not be any difference
|
||||
@@ -140,7 +157,8 @@ class ViewTestCase(BaseViewTestCase):
|
||||
def test_logged_in_default_group_shared(self):
|
||||
""" Check correct status code for all requests
|
||||
|
||||
Assumption: User logged in and has no groups and data is shared
|
||||
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:
|
||||
|
||||
@@ -149,6 +167,7 @@ class ViewTestCase(BaseViewTestCase):
|
||||
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.users.set([self.superuser])
|
||||
|
||||
success_urls = [
|
||||
@@ -169,34 +188,39 @@ class ViewTestCase(BaseViewTestCase):
|
||||
]
|
||||
self.assert_url_success(client, success_urls)
|
||||
|
||||
def test_anonymous_user(self):
|
||||
def test_logged_in_default_group_unshared(self):
|
||||
""" Check correct status code for all requests
|
||||
|
||||
Assumption: User not logged in
|
||||
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.users.set([])
|
||||
|
||||
success_urls = [
|
||||
self.report_url,
|
||||
]
|
||||
fail_urls = [
|
||||
self.index_url,
|
||||
self.detail_url,
|
||||
self.new_url,
|
||||
self.report_url,
|
||||
self.new_id_url,
|
||||
self.log_url,
|
||||
]
|
||||
fail_urls = [
|
||||
self.new_url,
|
||||
self.edit_url,
|
||||
self.remove_url,
|
||||
self.state_new_url,
|
||||
self.action_new_url,
|
||||
self.deadline_new_url,
|
||||
self.state_remove_url,
|
||||
self.action_remove_url,
|
||||
self.new_doc_url,
|
||||
self.log_url,
|
||||
self.remove_url,
|
||||
]
|
||||
|
||||
self.assert_url_success(client, success_urls)
|
||||
self.assert_url_fail(client, fail_urls)
|
||||
self.assert_url_success(client, success_urls)
|
||||
|
||||
@@ -110,6 +110,7 @@ def new_id_view(request: HttpRequest):
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Compensation, "id")
|
||||
def edit_view(request: HttpRequest, id: str):
|
||||
"""
|
||||
Renders a view for editing compensations
|
||||
@@ -377,17 +378,19 @@ def deadline_new_view(request: HttpRequest, id: str):
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def state_remove_view(request: HttpRequest, id: str):
|
||||
@shared_access_required(Compensation, "id")
|
||||
def state_remove_view(request: HttpRequest, id: str, state_id: str):
|
||||
""" Renders a form for removing a compensation state
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The state's id
|
||||
id (str): The compensation's id
|
||||
state_id (str): The state's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
state = get_object_or_404(CompensationState, id=id)
|
||||
state = get_object_or_404(CompensationState, id=state_id)
|
||||
form = RemoveModalForm(request.POST or None, instance=state, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
@@ -397,17 +400,19 @@ def state_remove_view(request: HttpRequest, id: str):
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def action_remove_view(request: HttpRequest, id: str):
|
||||
@shared_access_required(Compensation, "id")
|
||||
def action_remove_view(request: HttpRequest, id: str, action_id: str):
|
||||
""" Renders a form for removing a compensation action
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
id (str): The action's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
action = get_object_or_404(CompensationAction, id=id)
|
||||
action = get_object_or_404(CompensationAction, id=action_id)
|
||||
form = RemoveModalForm(request.POST or None, instance=action, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
@@ -415,7 +420,7 @@ def action_remove_view(request: HttpRequest, id: str):
|
||||
)
|
||||
|
||||
|
||||
def report_view(request:HttpRequest, id: str):
|
||||
def report_view(request: HttpRequest, id: str):
|
||||
""" Renders the public report view
|
||||
|
||||
Args:
|
||||
|
||||
@@ -16,11 +16,12 @@ 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
|
||||
from compensation.models import EcoAccount, EcoAccountDocument
|
||||
from compensation.models import EcoAccount, EcoAccountDocument, CompensationState, CompensationAction
|
||||
from compensation.tables import EcoAccountTable
|
||||
from intervention.forms.modalForms import NewDeductionModalForm, ShareInterventionModalForm
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import any_group_check, default_group_required, conservation_office_group_required
|
||||
from konova.decorators import any_group_check, default_group_required, conservation_office_group_required, \
|
||||
shared_access_required
|
||||
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm, RecordModalForm
|
||||
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
|
||||
from konova.utils.documents import get_document, remove_document
|
||||
@@ -99,6 +100,7 @@ def new_view(request: HttpRequest):
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def new_id_view(request: HttpRequest):
|
||||
""" JSON endpoint
|
||||
|
||||
@@ -353,6 +355,50 @@ def action_new_view(request: HttpRequest, id: str):
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def state_remove_view(request: HttpRequest, id: str, state_id: str):
|
||||
""" Renders a form for removing a compensation state
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
state_id (str): The state's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
state = get_object_or_404(CompensationState, id=state_id)
|
||||
form = RemoveModalForm(request.POST or None, instance=state, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("State removed")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def action_remove_view(request: HttpRequest, id: str, action_id: str):
|
||||
""" Renders a form for removing a compensation action
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
id (str): The action's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
action = get_object_or_404(CompensationAction, id=action_id)
|
||||
form = RemoveModalForm(request.POST or None, instance=action, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Action removed")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def deadline_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new states for an eco account
|
||||
|
||||
Reference in New Issue
Block a user