-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#467] Setup objecttypes through django-setup-configuration #492
Changes from all commits
e9656f4
c076d21
ada6794
0587ef6
6553c14
a90b822
90c27c0
54e048d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
objecttypes_config_enable: true | ||
objecttypes: | ||
items: | ||
- uuid: b427ef84-189d-43aa-9efd-7bb2c459e281 | ||
name: Object Type 1 | ||
service_identifier: service-1 | ||
|
||
- uuid: b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2 | ||
name: Object Type 2 | ||
service_identifier: service-2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
objecttypes_config_enable: true | ||
objecttypes: | ||
items: | ||
- uuid: b427ef84-189d-43aa-9efd-7bb2c459e281 | ||
name: Object Type 1 | ||
service_identifier: service-1 | ||
|
||
- uuid: 7229549b-7b41-47d1-8106-414b2a69751b | ||
name: Object Type 3 | ||
service_identifier: service-2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
objecttypes_config_enable: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need separate files for these tests? Most of them seem the same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the idempotent test file, the other files are quite different from each other |
||
objecttypes: | ||
items: | ||
- uuid: b427ef84-189d-43aa-9efd-7bb2c459e281 | ||
name: Object Type 1 | ||
service_identifier: service-1 | ||
|
||
- uuid: b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2 | ||
name: Object Type 2 | ||
service_identifier: service-2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
objecttypes_config_enable: true | ||
objecttypes: | ||
items: | ||
- uuid: b427ef84-189d-43aa-9efd-7bb2c459e281 | ||
name: Object Type 1 | ||
service_identifier: service-1 | ||
|
||
- uuid: foobar | ||
name: Object Type 2 | ||
service_identifier: service-1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
objecttypes_config_enable: true | ||
objecttypes: | ||
items: | ||
- uuid: b427ef84-189d-43aa-9efd-7bb2c459e281 | ||
name: Object Type 1 | ||
service_identifier: unknown | ||
|
||
- uuid: b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2 | ||
name: Object Type 2 | ||
service_identifier: service-1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
from pathlib import Path | ||
|
||
from django.db.models import QuerySet | ||
from django.test import TestCase | ||
|
||
from django_setup_configuration.exceptions import ConfigurationRunFailed | ||
from django_setup_configuration.test_utils import execute_single_step | ||
from zgw_consumers.models import Service | ||
from zgw_consumers.test.factories import ServiceFactory | ||
|
||
from objects.core.models import ObjectType | ||
from objects.core.tests.factories import ObjectTypeFactory | ||
from objects.setup_configuration.steps.objecttypes import ObjectTypesConfigurationStep | ||
|
||
TEST_FILES = (Path(__file__).parent / "files").resolve() | ||
|
||
|
||
class ObjectTypesConfigurationStepTests(TestCase): | ||
def test_empty_database(self): | ||
service_1 = ServiceFactory(slug="service-1") | ||
service_2 = ServiceFactory(slug="service-2") | ||
|
||
test_file_path = str(TEST_FILES / "objecttypes_empty_database.yaml") | ||
|
||
execute_single_step(ObjectTypesConfigurationStep, yaml_source=test_file_path) | ||
|
||
objecttypes: QuerySet[ObjectType] = ObjectType.objects.order_by("_name") | ||
|
||
self.assertEqual(objecttypes.count(), 2) | ||
|
||
objecttype_1: ObjectType = objecttypes.first() | ||
|
||
self.assertEqual(str(objecttype_1.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") | ||
self.assertEqual(objecttype_1._name, "Object Type 1") | ||
self.assertEqual(objecttype_1.service, service_1) | ||
|
||
objecttype_2: ObjectType = objecttypes.last() | ||
|
||
self.assertEqual(str(objecttype_2.uuid), "b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2") | ||
self.assertEqual(objecttype_2._name, "Object Type 2") | ||
self.assertEqual(objecttype_2.service, service_2) | ||
|
||
def test_existing_objecttype(self): | ||
test_file_path = str(TEST_FILES / "objecttypes_existing_objecttype.yaml") | ||
|
||
service_1: Service = ServiceFactory(slug="service-1") | ||
service_2: Service = ServiceFactory(slug="service-2") | ||
|
||
objecttype_1: ObjectType = ObjectTypeFactory( | ||
service=service_1, | ||
uuid="b427ef84-189d-43aa-9efd-7bb2c459e281", | ||
_name="Object Type 001", | ||
) | ||
objecttype_2: ObjectType = ObjectTypeFactory( | ||
service=service_2, | ||
uuid="b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2", | ||
_name="Object Type 002", | ||
) | ||
|
||
execute_single_step(ObjectTypesConfigurationStep, yaml_source=test_file_path) | ||
|
||
self.assertEqual(ObjectType.objects.count(), 3) | ||
|
||
objecttype_1.refresh_from_db() | ||
|
||
self.assertEqual(str(objecttype_1.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") | ||
self.assertEqual(objecttype_1._name, "Object Type 1") | ||
self.assertEqual(objecttype_1.service, service_1) | ||
|
||
objecttype_2.refresh_from_db() | ||
|
||
self.assertEqual(str(objecttype_2.uuid), "b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2") | ||
self.assertEqual(objecttype_2._name, "Object Type 002") | ||
self.assertEqual(objecttype_2.service, service_2) | ||
|
||
objecttype_3: ObjectType = ObjectType.objects.get( | ||
uuid="7229549b-7b41-47d1-8106-414b2a69751b" | ||
) | ||
|
||
self.assertEqual(str(objecttype_3.uuid), "7229549b-7b41-47d1-8106-414b2a69751b") | ||
self.assertEqual(objecttype_3._name, "Object Type 3") | ||
self.assertEqual(objecttype_3.service, service_2) | ||
|
||
def test_unknown_service(self): | ||
service = ServiceFactory(slug="service-1") | ||
|
||
objecttype: ObjectType = ObjectTypeFactory( | ||
uuid="b427ef84-189d-43aa-9efd-7bb2c459e281", | ||
_name="Object Type 001", | ||
service=service, | ||
) | ||
|
||
test_file_path = str(TEST_FILES / "objecttypes_unknown_service.yaml") | ||
|
||
with self.assertRaises(ConfigurationRunFailed): | ||
execute_single_step( | ||
ObjectTypesConfigurationStep, yaml_source=test_file_path | ||
) | ||
|
||
self.assertEqual(ObjectType.objects.count(), 1) | ||
|
||
objecttype.refresh_from_db() | ||
|
||
self.assertEqual(str(objecttype.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") | ||
self.assertEqual(objecttype._name, "Object Type 001") | ||
self.assertEqual(objecttype.service, service) | ||
|
||
def test_invalid_uuid(self): | ||
test_file_path = str(TEST_FILES / "objecttypes_invalid_uuid.yaml") | ||
|
||
service: Service = ServiceFactory(slug="service-1") | ||
|
||
objecttype: ObjectType = ObjectTypeFactory( | ||
service=service, | ||
uuid="b427ef84-189d-43aa-9efd-7bb2c459e281", | ||
_name="Object Type 001", | ||
) | ||
|
||
with self.assertRaises(ConfigurationRunFailed): | ||
execute_single_step( | ||
ObjectTypesConfigurationStep, yaml_source=test_file_path | ||
) | ||
|
||
self.assertEqual(ObjectType.objects.count(), 1) | ||
|
||
objecttype.refresh_from_db() | ||
|
||
self.assertEqual(str(objecttype.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") | ||
self.assertEqual(objecttype._name, "Object Type 1") | ||
self.assertEqual(objecttype.service, service) | ||
|
||
def test_idempotent_step(self): | ||
service_1 = ServiceFactory(slug="service-1") | ||
service_2 = ServiceFactory(slug="service-2") | ||
|
||
test_file_path = str(TEST_FILES / "objecttypes_idempotent.yaml") | ||
|
||
execute_single_step(ObjectTypesConfigurationStep, yaml_source=test_file_path) | ||
|
||
objecttypes: QuerySet[ObjectType] = ObjectType.objects.order_by("_name") | ||
|
||
self.assertEqual(objecttypes.count(), 2) | ||
|
||
objecttype_1: ObjectType = objecttypes.first() | ||
|
||
self.assertEqual(str(objecttype_1.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") | ||
self.assertEqual(objecttype_1._name, "Object Type 1") | ||
self.assertEqual(objecttype_1.service, service_1) | ||
|
||
objecttype_2: ObjectType = objecttypes.last() | ||
|
||
self.assertEqual(str(objecttype_2.uuid), "b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2") | ||
self.assertEqual(objecttype_2._name, "Object Type 2") | ||
self.assertEqual(objecttype_2.service, service_2) | ||
|
||
# Rerun | ||
execute_single_step(ObjectTypesConfigurationStep, yaml_source=test_file_path) | ||
|
||
objecttype_1.refresh_from_db() | ||
objecttype_2.refresh_from_db() | ||
|
||
self.assertEqual(ObjectType.objects.count(), 2) | ||
|
||
# objecttype 1 | ||
self.assertEqual(str(objecttype_1.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") | ||
self.assertEqual(objecttype_1._name, "Object Type 1") | ||
self.assertEqual(objecttype_1.service, service_1) | ||
|
||
# objecttype 2 | ||
self.assertEqual(str(objecttype_2.uuid), "b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2") | ||
self.assertEqual(objecttype_2._name, "Object Type 2") | ||
self.assertEqual(objecttype_2.service, service_2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's also set the headers to make it a bit more of a real example: