-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into healthcheck-fix
- Loading branch information
Showing
7 changed files
with
493 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import pytest | ||
from django.contrib.auth.models import User | ||
|
||
from api import models as api_models | ||
from gmn import models as gmn_models | ||
from gmw import models as gmw_models | ||
|
||
|
||
@pytest.fixture | ||
def organisation(): | ||
organisation = api_models.Organisation.objects.create( | ||
name="Nieuwegein", | ||
kvk_number="12345678", | ||
bro_user_token="secret", | ||
bro_user_password="secret", | ||
) | ||
return organisation | ||
|
||
|
||
@pytest.fixture | ||
def user(): | ||
user = User.objects.create_user( | ||
username="test_user", email="[email protected]", password="test_password" | ||
) | ||
return user | ||
|
||
|
||
@pytest.fixture | ||
def userprofile(user, organisation): | ||
userprofile = api_models.UserProfile.objects.create( | ||
user=user, | ||
organisation=organisation, | ||
) | ||
return userprofile | ||
|
||
|
||
@pytest.fixture | ||
def gmn(organisation): | ||
return gmn_models.GMN( | ||
data_owner=organisation, | ||
bro_id="GMN123456789", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def gmw(organisation): | ||
return gmw_models.GMW( | ||
data_owner=organisation, | ||
bro_id="GMW123456789", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def upload_task_valid_input_data(organisation): | ||
return { | ||
"data_owner": organisation, | ||
"bro_domain": "GMN", | ||
"project_number": "1", | ||
"registration_type": "GMN_StartRegistration", | ||
"request_type": "registration", | ||
"status": "PENDING", | ||
"metadata": {}, | ||
"sourcedocument_data": {}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import pytest | ||
from rest_framework.exceptions import ValidationError | ||
|
||
from api import models as api_models | ||
from api import serializers as api_serializers | ||
from api.tests import fixtures | ||
|
||
# this setup is chosen because ruff removes the fixture imports in other methods | ||
organisation = fixtures.organisation | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_valid_data_importtask_serialization(organisation): | ||
data = { | ||
"data_owner": organisation.uuid, | ||
"kvk_number": organisation.kvk_number, | ||
"bro_domain": "GMN", | ||
"status": "PENDING", | ||
} | ||
serializer = api_serializers.ImportTaskSerializer(data=data) | ||
assert serializer.is_valid(), serializer.errors | ||
serialized_data = serializer.data | ||
assert serialized_data["bro_domain"] == "GMN" | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_valid_data_importtask_deserialization(organisation): | ||
data = { | ||
"data_owner": organisation, | ||
"kvk_number": organisation.kvk_number, | ||
"bro_domain": "GMN", | ||
"status": "PENDING", | ||
} | ||
upload_task = api_models.ImportTask.objects.create(**data) | ||
serializer = api_serializers.ImportTaskSerializer(instance=upload_task) | ||
serialized_data = serializer.data | ||
assert serialized_data["bro_domain"] == "GMN" | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_invalid_data_importtask_validation(organisation): | ||
data = { | ||
"data_owner": organisation, | ||
"kvk_number": organisation.kvk_number, | ||
"bro_domain": "Non-existing-domain", | ||
"status": "PENDING", | ||
} | ||
serializer = api_serializers.ImportTaskSerializer(data=data) | ||
with pytest.raises(ValidationError): | ||
serializer.is_valid(raise_exception=True) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_valid_data_uploadtask_serialization(organisation): | ||
data = { | ||
"data_owner": organisation.uuid, | ||
"bro_domain": "GMN", | ||
"project_number": "1", | ||
"registration_type": "GMN_StartRegistration", | ||
"request_type": "registration", | ||
"status": "PENDING", | ||
"metadata": {}, | ||
"sourcedocument_data": {}, | ||
} | ||
serializer = api_serializers.UploadTaskSerializer(data=data) | ||
assert serializer.is_valid(), serializer.errors | ||
serialized_data = serializer.data | ||
assert serialized_data["bro_domain"] == "GMN" | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_valid_data_uploadtask_deserialization(organisation): | ||
data = { | ||
"data_owner": organisation, | ||
"bro_domain": "GMN", | ||
"project_number": "1", | ||
"registration_type": "GMN_StartRegistration", | ||
"request_type": "registration", | ||
"status": "PENDING", | ||
"metadata": {}, | ||
"sourcedocument_data": {}, | ||
} | ||
upload_task = api_models.UploadTask.objects.create(**data) | ||
serializer = api_serializers.UploadTaskSerializer(instance=upload_task) | ||
serialized_data = serializer.data | ||
assert serialized_data["bro_domain"] == "GMN" | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_invalid_data_uploadtask_validation(organisation): | ||
data = { | ||
"data_owner": organisation, | ||
"bro_domain": "Non-existing-domain", | ||
"project_number": "1", | ||
"registration_type": "GMN_StartRegistration", | ||
"request_type": "registration", | ||
"status": "PENDING", | ||
"metadata": {}, | ||
"sourcedocument_data": {}, | ||
} | ||
serializer = api_serializers.UploadTaskSerializer(data=data) | ||
with pytest.raises(ValidationError): | ||
serializer.is_valid(raise_exception=True) |
Oops, something went wrong.