Skip to content

Commit

Permalink
✅ [#557] Start adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Dec 24, 2024
1 parent d7ff6cd commit 4102aa0
Show file tree
Hide file tree
Showing 6 changed files with 490 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from requests_mock import Mocker
from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from zgw_consumers.constants import APITypes
from zgw_consumers.test.factories import ServiceFactory

from openarchiefbeheer.accounts.tests.factories import UserFactory

Expand Down Expand Up @@ -55,3 +58,127 @@ def test_record_manager_can_delete_new_list(self):

self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
self.assertFalse(DestructionList.objects.filter(uuid=list_uuid).exists())

def test_cannot_download_report_if_not_record_manager(self):
user = UserFactory.create(post__can_start_destruction=False)
destruction_list = DestructionListFactory.create(
name="A deleted list",
status=ListStatus.deleted,
)

self.client.force_authenticate(user=user)
response = self.client.get(
reverse(
"api:destructionlist-download-report",
kwargs={"uuid": destruction_list.uuid},
),
)

self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

def test_cannot_download_report_if_not_deleted(self):
user = UserFactory.create(post__can_start_destruction=True)
destruction_list = DestructionListFactory.create(
name="A not-deleted list",
status=ListStatus.new,
)

self.client.force_authenticate(user=user)
response = self.client.get(
reverse(
"api:destructionlist-download-report",
kwargs={"uuid": destruction_list.uuid},
),
)

self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

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

destruction_list = DestructionListFactory.create(
name="A deleted list",
status=ListStatus.deleted,
)

self.client.force_authenticate(user=user)
response = self.client.get(
reverse(
"api:destructionlist-download-report",
kwargs={"uuid": destruction_list.uuid},
),
)

self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

@Mocker()
def test_destruction_report_url_in_internal_result(self, m):
user = UserFactory.create(post__can_start_destruction=True)
ServiceFactory.create(
api_type=APITypes.drc,
api_root="http://localhost:8003/documenten/api/v1",
)
destruction_list = DestructionListFactory.create(
name="A deleted list",
status=ListStatus.deleted,
internal_results={
"created_resources": {
"enkelvoudiginformatieobjecten": [
"http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/61a914a2-db24-4a53-acbc-5306e5c346a6"
]
}
},
)

m.get(
"http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/61a914a2-db24-4a53-acbc-5306e5c346a6/download"
)

self.client.force_authenticate(user=user)
response = self.client.get(
reverse(
"api:destructionlist-download-report",
kwargs={"uuid": destruction_list.uuid},
),
)

self.assertEqual(response.status_code, status.HTTP_200_OK)

@Mocker()
def test_destruction_report_url_retrieved_from_openzaak(self, m):
user = UserFactory.create(post__can_start_destruction=True)
ServiceFactory.create(
api_type=APITypes.drc,
api_root="http://localhost:8003/documenten/api/v1",
)
ServiceFactory.create(
api_type=APITypes.zrc,
api_root="http://localhost:8003/zaken/api/v1",
)
destruction_list = DestructionListFactory.create(
name="A deleted list",
status=ListStatus.deleted,
zaak_destruction_report_url="http://localhost:8003/zaken/api/v1/zaken/c1490adc-adf7-4e0a-97a7-fa3cd94b8ddf",
)

m.get(
"http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/61a914a2-db24-4a53-acbc-5306e5c346a6/download"
)
m.get(
"http://localhost:8003/zaken/api/v1/zaakinformatieobjecten?zaak=http://localhost:8003/zaken/api/v1/zaken/c1490adc-adf7-4e0a-97a7-fa3cd94b8ddf",
json=[
{
"informatieobject": "http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/61a914a2-db24-4a53-acbc-5306e5c346a6"
}
],
)

self.client.force_authenticate(user=user)
response = self.client.get(
reverse(
"api:destructionlist-download-report",
kwargs={"uuid": destruction_list.uuid},
),
)

self.assertEqual(response.status_code, status.HTTP_200_OK)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0LXZjciIsImlhdCI6MTczNTAzOTYxOCwiY2xpZW50X2lkIjoidGVzdC12Y3IiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.OdmIzepFs1PQyu-a2dx9jWGsOgifoG-pEtAENiABqQc
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/111-111-111/download
response:
body:
string: application/octet-stream
headers:
API-version:
- 1.4.2
Allow:
- GET, HEAD, OPTIONS
Connection:
- keep-alive
Content-Length:
- '24'
Content-Type:
- application/octet-stream
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Tue, 24 Dec 2024 11:26:58 GMT
Referrer-Policy:
- same-origin
Server:
- nginx/1.27.0
Vary:
- origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
status:
code: 404
message: Not Found
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0LXZjciIsImlhdCI6MTczNDk2OTA1NiwiY2xpZW50X2lkIjoidGVzdC12Y3IiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.MvNacVmG7cpDdCrNG4tkDI58JCeJkXHh-BNeGNLDGQg
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/ac7ab173-3b1c-4ea9-8ccb-023c3814e3b3/download
response:
body:
string: '"This is a destruction report"
'
headers:
Accept-Ranges:
- bytes
Connection:
- keep-alive
Content-Disposition:
- attachment; filename="01219b90-0d13-4e25-b463-ab1545b05f05.bin"
Content-Length:
- '31'
Content-Type:
- application/octet-stream
Date:
- Mon, 23 Dec 2024 15:50:56 GMT
ETag:
- '"6769861f-1f"'
Last-Modified:
- Mon, 23 Dec 2024 15:47:43 GMT
Server:
- nginx/1.27.0
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0LXZjciIsImlhdCI6MTczNTAzODM2NSwiY2xpZW50X2lkIjoidGVzdC12Y3IiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.B2nxlVAASxM-I-LuvHfX9XgvZIDS-8Tyjanlp1JiEHk
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://localhost:8003/zaken/api/v1/zaakinformatieobjecten?zaak=http%3A%2F%2Flocalhost%3A8003%2Fzaken%2Fapi%2Fv1%2Fzaken%2Fb316d968-c357-4fbf-a1ad-60b3f8b9c3a6
response:
body:
string: '[{"url":"http://localhost:8003/zaken/api/v1/zaakinformatieobjecten/be6d2a4f-30bd-4d02-8b2d-522bcc07f90f","uuid":"be6d2a4f-30bd-4d02-8b2d-522bcc07f90f","informatieobject":"http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/ac7ab173-3b1c-4ea9-8ccb-023c3814e3b3","zaak":"http://localhost:8003/zaken/api/v1/zaken/b316d968-c357-4fbf-a1ad-60b3f8b9c3a6","aardRelatieWeergave":"Hoort
bij, omgekeerd: kent","titel":"","beschrijving":"","registratiedatum":"2024-07-19T13:33:19.659000Z","vernietigingsdatum":null,"status":null}]'
headers:
API-version:
- 1.5.1
Allow:
- GET, POST, HEAD, OPTIONS
Connection:
- keep-alive
Content-Length:
- '536'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Tue, 24 Dec 2024 11:06:05 GMT
Referrer-Policy:
- same-origin
Server:
- nginx/1.27.0
Vary:
- Accept, origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0LXZjciIsImlhdCI6MTczNTAzODM2OSwiY2xpZW50X2lkIjoidGVzdC12Y3IiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.x9jYGvo-s9XCR4bPpiT8qTwCEEi1HfJufbZleEOta-0
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/ac7ab173-3b1c-4ea9-8ccb-023c3814e3b3/download
response:
body:
string: 'This is a destruction report
'
headers:
Accept-Ranges:
- bytes
Connection:
- keep-alive
Content-Disposition:
- attachment; filename="01219b90-0d13-4e25-b463-ab1545b05f05.bin"
Content-Length:
- '29'
Content-Type:
- application/octet-stream
Date:
- Tue, 24 Dec 2024 11:06:13 GMT
ETag:
- '"676a8b05-1d"'
Last-Modified:
- Tue, 24 Dec 2024 10:20:53 GMT
Server:
- nginx/1.27.0
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0LXZjciIsImlhdCI6MTczNTA0MDA4NywiY2xpZW50X2lkIjoidGVzdC12Y3IiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.MahihwdO_IZ4ZyVMN94oyTcL6B6gR3XC6cXrPncLu0c
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/ac7ab173-3b1c-4ea9-8ccb-023c3814e3b3/download
response:
body:
string: application/octet-stream
headers:
API-version:
- 1.4.2
Allow:
- GET, HEAD, OPTIONS
Connection:
- keep-alive
Content-Length:
- '24'
Content-Type:
- application/octet-stream
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Tue, 24 Dec 2024 11:34:47 GMT
Referrer-Policy:
- same-origin
Server:
- nginx/1.27.0
Vary:
- origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
status:
code: 500
message: Internal Server Error
version: 1
Loading

0 comments on commit 4102aa0

Please sign in to comment.