Skip to content

Commit

Permalink
✅ [#390] Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Oct 1, 2024
1 parent 1a028f3 commit ad361a9
Show file tree
Hide file tree
Showing 26 changed files with 232 additions and 151 deletions.
35 changes: 35 additions & 0 deletions backend/src/openarchiefbeheer/accounts/fixtures/permissions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
{
"model": "auth.permission",
"fields": {
"name": "Can start destruction",
"content_type": [
"accounts",
"user"
],
"codename": "can_start_destruction"
}
},
{
"model": "auth.permission",
"fields": {
"name": "Can review destruction",
"content_type": [
"accounts",
"user"
],
"codename": "can_review_destruction"
}
},
{
"model": "auth.permission",
"fields": {
"name": "Can review final list",
"content_type": [
"accounts",
"user"
],
"codename": "can_review_final_list"
}
}
]
14 changes: 14 additions & 0 deletions backend/src/openarchiefbeheer/accounts/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission

import factory
from factory import post_generation
from factory.django import DjangoModelFactory

User = get_user_model()
Expand All @@ -21,3 +23,15 @@ class Params:
is_staff=True,
is_superuser=True,
)

@post_generation
def post(user, create, extracted, **kwargs):
if not create:
return

for item, value in kwargs.items():
if not value:
continue

permission = Permission.objects.filter(codename=item).first()
user.user_permissions.add(permission)
21 changes: 7 additions & 14 deletions backend/src/openarchiefbeheer/accounts/tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase

from openarchiefbeheer.accounts.tests.factories import RoleFactory, UserFactory
from openarchiefbeheer.accounts.tests.factories import UserFactory


class WhoAmIViewTest(APITestCase):
Expand All @@ -14,8 +14,7 @@ def test_not_authenticated(self):
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

def test_authenticated(self):
role = RoleFactory.create()
user = UserFactory.create(role=role)
user = UserFactory.create(post__can_start_destruction=True)

self.client.force_authenticate(user=user)
endpoint = reverse("api:whoami")
Expand All @@ -30,14 +29,8 @@ def test_authenticated(self):
self.assertEqual(data["firstName"], user.first_name)
self.assertEqual(data["lastName"], user.last_name)
self.assertEqual(data["email"], user.email)
self.assertEqual(data["role"]["name"], role.name)
self.assertEqual(
data["role"]["canStartDestruction"], role.can_start_destruction
)
self.assertEqual(
data["role"]["canReviewDestruction"], role.can_review_destruction
)
self.assertEqual(data["role"]["canViewCaseDetails"], role.can_view_case_details)
self.assertTrue(data["role"]["canStartDestruction"])
self.assertFalse(data["role"]["canReviewDestruction"])

def test_post(self):
user = UserFactory.create()
Expand All @@ -59,10 +52,10 @@ def test_not_authenticated_cant_access(self):
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

def test_get_archivists(self):
UserFactory.create_batch(2, role__can_review_final_list=True)
UserFactory.create_batch(3, role__can_review_final_list=False)
UserFactory.create_batch(2, post__can_review_final_list=True)
UserFactory.create_batch(3, post__can_review_final_list=False)

record_manager = UserFactory.create(role__can_start_destruction=True)
record_manager = UserFactory.create(post__can_start_destruction=True)

self.client.force_login(record_manager)
response = self.client.get(reverse("api:archivists"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def test_user_not_logged_in(self):
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

def test_retrieve_reviewers(self):
admin = UserFactory.create(is_superuser=True, role=None)
UserFactory.create_batch(2, role__can_review_destruction=True)
UserFactory.create_batch(2, role__can_review_destruction=False)
admin = UserFactory.create(is_superuser=True)
UserFactory.create_batch(2, post__can_review_destruction=True)
UserFactory.create_batch(2, post__can_review_destruction=False)

self.client.force_authenticate(user=admin)
response = self.client.get(reverse("api:reviewers"))
Expand Down
8 changes: 4 additions & 4 deletions backend/src/openarchiefbeheer/config/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_authenticated_can_retrieve(self):
self.assertIn("zaaktypesShortProcess", response.json())

def test_not_record_manager_update(self):
user = UserFactory.create(role__can_start_destruction=False)
user = UserFactory.create(post__can_start_destruction=False)

self.client.force_login(user)
response = self.client.put(
Expand All @@ -36,7 +36,7 @@ def test_not_record_manager_update(self):
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

def test_record_manager_update(self):
user = UserFactory.create(role__can_start_destruction=True)
user = UserFactory.create(post__can_start_destruction=True)

self.client.force_login(user)
response = self.client.put(
Expand All @@ -51,7 +51,7 @@ def test_record_manager_update(self):
self.assertEqual(config.zaaktypes_short_process, ["http://tralala.nl"])

def test_record_manager_partial_update(self):
user = UserFactory.create(role__can_start_destruction=True)
user = UserFactory.create(post__can_start_destruction=True)

self.client.force_login(user)
response = self.client.patch(
Expand All @@ -68,7 +68,7 @@ def test_record_manager_partial_update(self):
@tag("gh-227")
@override_settings(SOLO_CACHE=None)
def test_can_send_empty_list(self):
user = UserFactory.create(role__can_start_destruction=True)
user = UserFactory.create(post__can_start_destruction=True)

config = ArchiveConfig.get_solo()
config.zaaktypes_short_process = ["http://tralala.nl"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def test_zaaktype_filters_on_process_review_page(self):
@sync_to_async
def create_data():
record_manager = UserFactory.create(
password="ANic3Password", role__can_start_destruction=True
password="ANic3Password", post__can_start_destruction=True
)
destruction_list = DestructionListFactory.create(
assignee=record_manager,
Expand Down Expand Up @@ -166,7 +166,7 @@ def create_data():
async def test_zaak_removed_outside_process(self):
@sync_to_async
def create_data():
record_manager = UserFactory.create(username="Record Manager", password="ANic3Password", role__can_start_destruction=True)
record_manager = UserFactory.create(username="Record Manager", password="ANic3Password", post__can_start_destruction=True)

zaken = ZaakFactory.create_batch(2)
list = DestructionListFactory.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ async def test_scenario_reviewer_rejects_list(self):
async def test_scenario_reviewer_reviews_second_time(self):
@sync_to_async
def create_data():
record_manager = UserFactory.create(role__can_start_destruction=True)
reviewer = UserFactory.create(username="Beoordelaar", password="ANic3Password", role__can_review_destruction=True)
record_manager = UserFactory.create(post__can_start_destruction=True)
reviewer = UserFactory.create(username="Beoordelaar", password="ANic3Password", post__can_review_destruction=True)

zaken = ZaakFactory.create_batch(2)

Expand Down Expand Up @@ -195,7 +195,7 @@ async def test_zaaktype_filters(self):
@sync_to_async
def create_data():
reviewer = UserFactory.create(
password="ANic3Password", role__can_review_destruction=True
password="ANic3Password", post__can_review_destruction=True
)
destruction_list = DestructionListFactory.create(
assignee=reviewer,
Expand Down Expand Up @@ -275,8 +275,8 @@ def create_data():
async def test_zaak_removed_outside_process(self):
@sync_to_async
def create_data():
record_manager = UserFactory.create(role__can_start_destruction=True)
reviewer = UserFactory.create(username="Beoordelaar", password="ANic3Password", role__can_review_destruction=True)
record_manager = UserFactory.create(post__can_start_destruction=True)
reviewer = UserFactory.create(username="Beoordelaar", password="ANic3Password", post__can_review_destruction=True)

zaken = ZaakFactory.create_batch(2)
list = DestructionListFactory.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def test_login_redirects_to_destruction_list(self):
@sync_to_async
def _create_record_manager():
record_manager = UserFactory.create(
role__can_start_destruction=True,
post__can_start_destruction=True,
password="ANic3Password",
)
return record_manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class DestructionListAbortDestructionEndpointTest(APITestCase):
def test_only_author_can_abort(self):
record_manager = UserFactory.create(
username="record_manager", role__can_start_destruction=True
username="record_manager", post__can_start_destruction=True
)
destruction_list = DestructionListFactory.create(
name="A test list",
Expand All @@ -39,7 +39,7 @@ def test_only_author_can_abort(self):

def test_only_ready_to_delete_with_planned_date_can_be_aborted(self):
record_manager = UserFactory.create(
username="record_manager", role__can_start_destruction=True
username="record_manager", post__can_start_destruction=True
)
destruction_list = DestructionListFactory.create(
name="A test list",
Expand All @@ -63,7 +63,7 @@ def test_only_ready_to_delete_with_planned_date_can_be_aborted(self):

def test_cannot_abort_without_comment(self):
record_manager = UserFactory.create(
username="record_manager", role__can_start_destruction=True
username="record_manager", post__can_start_destruction=True
)
destruction_list = DestructionListFactory.create(
name="A test list",
Expand All @@ -88,7 +88,7 @@ def test_cannot_abort_without_comment(self):

def test_abort_list_destruction(self):
record_manager = UserFactory.create(
username="record_manager", role__can_start_destruction=True
username="record_manager", post__can_start_destruction=True
)
destruction_list = DestructionListFactory.create(
name="A test list",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class DestructionListStartDestructionEndpointTest(APITestCase):
def test_plan_destruction(self):
record_manager = UserFactory.create(
username="record_manager", role__can_start_destruction=True
username="record_manager", post__can_start_destruction=True
)
destruction_list = DestructionListFactory.create(
name="A test list",
Expand Down Expand Up @@ -47,7 +47,7 @@ def test_retry_destruction_after_failure_queues_immediately(
self,
):
record_manager = UserFactory.create(
username="record_manager", role__can_start_destruction=True
username="record_manager", post__can_start_destruction=True
)
destruction_list = DestructionListFactory.create(
name="A test list",
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_retry_destruction_after_failure_with_planned_date_in_future_raises_erro
):
"""This scenario should never happen unless someone manually changes the planned destruction date."""
record_manager = UserFactory.create(
username="record_manager", role__can_start_destruction=True
username="record_manager", post__can_start_destruction=True
)
destruction_list = DestructionListFactory.create(
name="A test list",
Expand All @@ -110,7 +110,7 @@ def test_retry_destruction_after_failure_with_planned_date_in_future_raises_erro
)

def test_cannot_start_destruction_if_not_author(self):
record_manager = UserFactory.create(role__can_start_destruction=True)
record_manager = UserFactory.create(post__can_start_destruction=True)
destruction_list = DestructionListFactory.create(
name="A test list",
contains_sensitive_info=True,
Expand All @@ -131,7 +131,7 @@ def test_cannot_start_destruction_if_not_author(self):
m_task.assert_not_called()

def test_cannot_start_destruction_if_not_ready_to_delete(self):
record_manager = UserFactory.create(role__can_start_destruction=True)
record_manager = UserFactory.create(post__can_start_destruction=True)
destruction_list = DestructionListFactory.create(
name="A test list",
contains_sensitive_info=True,
Expand All @@ -154,7 +154,7 @@ def test_cannot_start_destruction_if_not_ready_to_delete(self):

def test_cannot_start_destruction_if_archiefactiedatum_in_the_future(self):
record_manager = UserFactory.create(
username="record_manager", role__can_start_destruction=True
username="record_manager", post__can_start_destruction=True
)
destruction_list = DestructionListFactory.create(
name="A test list",
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_cannot_start_destruction_if_archiefactiedatum_in_the_future(self):

def test_can_start_destruction_if_archiefactiedatum_in_the_future_but_removed(self):
record_manager = UserFactory.create(
username="record_manager", role__can_start_destruction=True
username="record_manager", post__can_start_destruction=True
)
destruction_list = DestructionListFactory.create(
name="A test list",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_filter_on_review(self):
self.assertEqual(len(data[0]["itemsResponses"]), 2)

def test_create_review_response(self):
record_manager = UserFactory.create(role__can_start_destruction=True)
record_manager = UserFactory.create(post__can_start_destruction=True)
review = DestructionListReviewFactory.create(
destruction_list__author=record_manager,
destruction_list__status=ListStatus.changes_requested,
Expand Down Expand Up @@ -125,8 +125,8 @@ def test_create_review_response(self):
self.assertEqual(item_response3.action_zaak["archiefactiedatum"], "2030-01-01")

def test_cannot_create_response_if_not_author(self):
record_manager1 = UserFactory.create(role__can_start_destruction=True)
record_manager2 = UserFactory.create(role__can_start_destruction=True)
record_manager1 = UserFactory.create(post__can_start_destruction=True)
record_manager2 = UserFactory.create(post__can_start_destruction=True)

review = DestructionListReviewFactory.create(
destruction_list__author=record_manager1,
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_cannot_create_response_if_not_author(self):
)

def test_cannot_create_response_if_not_changes_requested(self):
record_manager = UserFactory.create(role__can_start_destruction=True)
record_manager = UserFactory.create(post__can_start_destruction=True)

review = DestructionListReviewFactory.create(
destruction_list__author=record_manager,
Expand Down Expand Up @@ -190,14 +190,14 @@ def test_cannot_create_response_if_not_changes_requested(self):
@freezegun.freeze_time("2023-09-15T21:36:00+02:00")
def test_audit_log(self):
# Reassign
record_manager = UserFactory.create(role__can_start_destruction=True)
record_manager = UserFactory.create(post__can_start_destruction=True)
destruction_list = DestructionListFactory.create(
name="Test audittrail",
status=ListStatus.ready_to_review,
author=record_manager,
)
DestructionListAssigneeFactory.create(destruction_list=destruction_list)
other_reviewer = UserFactory.create(role__can_review_destruction=True)
other_reviewer = UserFactory.create(post__can_review_destruction=True)

self.client.force_authenticate(user=record_manager)
endpoint_reassign = reverse(
Expand Down
Loading

0 comments on commit ad361a9

Please sign in to comment.