2021-10-27 14:44:49 +02:00
|
|
|
"""
|
|
|
|
Author: Michel Peltriaux
|
|
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
|
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
|
|
Created on: 27.10.21
|
|
|
|
|
|
|
|
"""
|
|
|
|
from django.urls import reverse
|
|
|
|
from django.test import Client
|
|
|
|
|
|
|
|
from konova.settings import DEFAULT_GROUP
|
|
|
|
from konova.tests.test_views import BaseViewTestCase
|
|
|
|
|
|
|
|
|
2021-11-09 13:06:22 +01:00
|
|
|
class CompensationViewTestCase(BaseViewTestCase):
|
|
|
|
"""
|
|
|
|
These tests focus on proper returned views depending on the user's groups privileges and login status
|
|
|
|
|
|
|
|
"""
|
2021-10-27 14:44:49 +02:00
|
|
|
|
2021-11-09 13:06:22 +01:00
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls) -> None:
|
|
|
|
super().setUpTestData()
|
|
|
|
state = cls.create_dummy_states()
|
|
|
|
cls.compensation.before_states.set([state])
|
|
|
|
cls.compensation.after_states.set([state])
|
2021-10-27 14:44:49 +02:00
|
|
|
|
2021-11-09 13:06:22 +01:00
|
|
|
action = cls.create_dummy_action()
|
|
|
|
cls.compensation.actions.set([action])
|
2021-10-27 14:44:49 +02:00
|
|
|
|
2021-11-09 13:06:22 +01:00
|
|
|
# Prepare urls
|
|
|
|
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,))
|
|
|
|
|
|
|
|
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,))
|
2021-10-27 14:44:49 +02:00
|
|
|
|
2021-11-09 13:06:22 +01:00
|
|
|
def test_anonymous_user(self):
|
|
|
|
""" Check correct status code for all requests
|
2021-10-27 14:44:49 +02:00
|
|
|
|
2021-11-09 13:06:22 +01:00
|
|
|
Assumption: User not logged in
|
2021-10-27 14:44:49 +02:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2021-11-09 13:06:22 +01:00
|
|
|
client = Client()
|
|
|
|
|
|
|
|
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,
|
|
|
|
]
|
|
|
|
|
|
|
|
self.assert_url_success(client, success_urls)
|
|
|
|
self.assert_url_fail(client, fail_urls)
|
2021-10-27 14:44:49 +02:00
|
|
|
|
|
|
|
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([])
|
2021-11-11 15:09:03 +01:00
|
|
|
self.intervention.share_with_list([self.superuser])
|
2021-10-27 14:44:49 +02:00
|
|
|
|
|
|
|
# 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 = [
|
|
|
|
self.index_url,
|
|
|
|
self.detail_url,
|
|
|
|
self.report_url,
|
|
|
|
]
|
|
|
|
fail_urls = [
|
|
|
|
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,
|
|
|
|
]
|
|
|
|
|
|
|
|
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 shared
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
client = Client()
|
|
|
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
|
|
|
self.superuser.groups.set([])
|
2021-11-09 13:06:22 +01:00
|
|
|
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
2021-11-11 15:09:03 +01:00
|
|
|
self.intervention.share_with_list([])
|
2021-10-27 14:44:49 +02:00
|
|
|
|
|
|
|
# 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 = [
|
|
|
|
self.index_url,
|
|
|
|
self.detail_url,
|
|
|
|
self.report_url,
|
|
|
|
]
|
|
|
|
fail_urls = [
|
|
|
|
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,
|
|
|
|
]
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-11-09 13:06:22 +01:00
|
|
|
Assumption: User logged in, is default group member and data is shared
|
|
|
|
--> Default group necessary since all base functionalities depend on this group membership
|
2021-10-27 14:44:49 +02:00
|
|
|
|
|
|
|
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])
|
2021-11-09 13:06:22 +01:00
|
|
|
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
2021-11-11 15:09:03 +01:00
|
|
|
self.intervention.share_with_list([self.superuser])
|
2021-10-27 14:44:49 +02:00
|
|
|
|
|
|
|
success_urls = [
|
|
|
|
self.index_url,
|
|
|
|
self.detail_url,
|
|
|
|
self.report_url,
|
|
|
|
self.new_url,
|
|
|
|
self.new_id_url,
|
|
|
|
self.edit_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)
|
|
|
|
|
2021-11-09 13:06:22 +01:00
|
|
|
def test_logged_in_default_group_unshared(self):
|
2021-10-27 14:44:49 +02:00
|
|
|
""" Check correct status code for all requests
|
|
|
|
|
2021-11-09 13:06:22 +01:00
|
|
|
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
|
2021-10-27 14:44:49 +02:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
client = Client()
|
2021-11-09 13:06:22 +01:00
|
|
|
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
|
2021-11-11 15:09:03 +01:00
|
|
|
self.intervention.share_with_list([])
|
2021-10-27 14:44:49 +02:00
|
|
|
|
|
|
|
success_urls = [
|
2021-11-09 13:06:22 +01:00
|
|
|
self.index_url,
|
|
|
|
self.detail_url,
|
2021-10-27 14:44:49 +02:00
|
|
|
self.report_url,
|
2021-11-09 13:06:22 +01:00
|
|
|
self.new_id_url,
|
2021-10-27 14:44:49 +02:00
|
|
|
]
|
|
|
|
fail_urls = [
|
|
|
|
self.new_url,
|
|
|
|
self.edit_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,
|
2021-11-09 13:06:22 +01:00
|
|
|
self.log_url,
|
|
|
|
self.remove_url,
|
2021-10-27 14:44:49 +02:00
|
|
|
]
|
|
|
|
self.assert_url_fail(client, fail_urls)
|
2021-11-09 13:06:22 +01:00
|
|
|
self.assert_url_success(client, success_urls)
|
2021-11-10 09:11:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
class EcoAccountViewTestCase(CompensationViewTestCase):
|
|
|
|
"""
|
|
|
|
These tests focus on proper returned views depending on the user's groups privileges and login status
|
|
|
|
|
|
|
|
EcoAccounts can inherit the same tests used for compensations.
|
|
|
|
|
|
|
|
"""
|
|
|
|
comp_state = None
|
|
|
|
comp_action = None
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls) -> None:
|
|
|
|
super().setUpTestData()
|
|
|
|
state = cls.create_dummy_states()
|
|
|
|
cls.eco_account.before_states.set([state])
|
|
|
|
cls.eco_account.after_states.set([state])
|
|
|
|
|
|
|
|
action = cls.create_dummy_action()
|
|
|
|
cls.eco_account.actions.set([action])
|
|
|
|
|
|
|
|
# Prepare urls
|
2022-02-02 11:26:02 +01:00
|
|
|
cls.index_url = reverse("compensation:acc:index", args=())
|
|
|
|
cls.new_url = reverse("compensation:acc:new", args=())
|
|
|
|
cls.new_id_url = reverse("compensation:acc:new-id", args=())
|
|
|
|
cls.detail_url = reverse("compensation:acc:detail", args=(cls.eco_account.id,))
|
|
|
|
cls.log_url = reverse("compensation:acc:log", args=(cls.eco_account.id,))
|
|
|
|
cls.edit_url = reverse("compensation:acc:edit", args=(cls.eco_account.id,))
|
|
|
|
cls.remove_url = reverse("compensation:acc:remove", args=(cls.eco_account.id,))
|
|
|
|
cls.report_url = reverse("compensation:acc:report", args=(cls.eco_account.id,))
|
|
|
|
cls.state_new_url = reverse("compensation:acc:new-state", args=(cls.eco_account.id,))
|
|
|
|
cls.action_new_url = reverse("compensation:acc:new-action", args=(cls.eco_account.id,))
|
|
|
|
cls.deadline_new_url = reverse("compensation:acc:new-deadline", args=(cls.eco_account.id,))
|
|
|
|
cls.new_doc_url = reverse("compensation:acc:new-doc", args=(cls.eco_account.id,))
|
|
|
|
cls.state_remove_url = reverse("compensation:acc:state-remove", args=(cls.eco_account.id, cls.comp_state.id,))
|
|
|
|
cls.action_remove_url = reverse("compensation:acc:action-remove", args=(cls.eco_account.id, cls.comp_action.id,))
|
2021-11-10 09:11:24 +01:00
|
|
|
|
|
|
|
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([])
|
2021-11-11 15:09:03 +01:00
|
|
|
self.eco_account.share_with_list([self.superuser])
|
2021-11-10 09:11:24 +01:00
|
|
|
|
|
|
|
# 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 = [
|
|
|
|
self.index_url,
|
|
|
|
self.detail_url,
|
|
|
|
self.report_url,
|
|
|
|
]
|
|
|
|
fail_urls = [
|
|
|
|
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,
|
|
|
|
]
|
|
|
|
|
|
|
|
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 shared
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
client = Client()
|
|
|
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
|
|
|
self.superuser.groups.set([])
|
2021-11-11 15:09:03 +01:00
|
|
|
self.eco_account.share_with_list([])
|
2021-11-10 09:11:24 +01:00
|
|
|
|
|
|
|
# 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 = [
|
|
|
|
self.index_url,
|
|
|
|
self.detail_url,
|
|
|
|
self.report_url,
|
|
|
|
]
|
|
|
|
fail_urls = [
|
|
|
|
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,
|
|
|
|
]
|
|
|
|
|
|
|
|
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
|
2021-11-11 15:09:03 +01:00
|
|
|
self.eco_account.share_with_list([self.superuser])
|
2021-11-10 09:11:24 +01:00
|
|
|
|
|
|
|
success_urls = [
|
|
|
|
self.index_url,
|
|
|
|
self.detail_url,
|
|
|
|
self.report_url,
|
|
|
|
self.new_url,
|
|
|
|
self.new_id_url,
|
|
|
|
self.edit_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)
|
|
|
|
|
|
|
|
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])
|
2021-11-11 15:09:03 +01:00
|
|
|
self.eco_account.share_with_list([])
|
2021-11-10 09:11:24 +01:00
|
|
|
|
|
|
|
success_urls = [
|
|
|
|
self.index_url,
|
|
|
|
self.detail_url,
|
|
|
|
self.report_url,
|
|
|
|
self.new_id_url,
|
|
|
|
self.new_url,
|
|
|
|
]
|
|
|
|
fail_urls = [
|
|
|
|
self.edit_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_fail(client, fail_urls)
|
|
|
|
self.assert_url_success(client, success_urls)
|
|
|
|
|