From 43964bdcbab5264af3cd58f508ad887ee2aab3a8 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Tue, 10 Dec 2024 11:56:18 +0100 Subject: [PATCH] [#467] apply code formatting --- src/objects/core/models.py | 2 +- .../core/tests/test_objecttype_config.py | 60 +++++++------------ .../setup_configuration/models/objecttypes.py | 8 +-- .../setup_configuration/models/sites.py | 1 + .../setup_configuration/steps/objecttypes.py | 12 ++-- .../setup_configuration/steps/sites.py | 9 +-- .../tests/test_site_config.py | 3 +- 7 files changed, 35 insertions(+), 60 deletions(-) diff --git a/src/objects/core/models.py b/src/objects/core/models.py index 3df3af1f..1a68df91 100644 --- a/src/objects/core/models.py +++ b/src/objects/core/models.py @@ -1,6 +1,6 @@ import datetime -from typing import Iterable, Optional import uuid +from typing import Iterable, Optional from django.contrib.gis.db.models import GeometryField from django.core.exceptions import ValidationError diff --git a/src/objects/core/tests/test_objecttype_config.py b/src/objects/core/tests/test_objecttype_config.py index 2568ce74..5fb40bb5 100644 --- a/src/objects/core/tests/test_objecttype_config.py +++ b/src/objects/core/tests/test_objecttype_config.py @@ -30,17 +30,13 @@ def test_empty_database(self): objecttype_1: ObjectType = objecttypes.first() - self.assertEqual( - str(objecttype_1.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281" - ) + 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(str(objecttype_2.uuid), "b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2") self.assertEqual(objecttype_2._name, "Object Type 2") self.assertEqual(objecttype_2.service, service_2) @@ -53,12 +49,12 @@ def test_existing_objecttype(self): objecttype_1: ObjectType = ObjectTypeFactory( service=service_1, uuid="b427ef84-189d-43aa-9efd-7bb2c459e281", - _name="Object Type 001" + _name="Object Type 001", ) objecttype_2: ObjectType = ObjectTypeFactory( service=service_2, uuid="b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2", - _name="Object Type 002" + _name="Object Type 002", ) execute_single_step(ObjectTypesConfigurationStep, yaml_source=test_file_path) @@ -67,17 +63,13 @@ def test_existing_objecttype(self): objecttype_1.refresh_from_db() - self.assertEqual( - str(objecttype_1.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281" - ) + 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(str(objecttype_2.uuid), "b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2") self.assertEqual(objecttype_2._name, "Object Type 002") self.assertEqual(objecttype_2.service, service_2) @@ -85,9 +77,7 @@ def test_existing_objecttype(self): uuid="7229549b-7b41-47d1-8106-414b2a69751b" ) - self.assertEqual( - str(objecttype_3.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) @@ -97,21 +87,21 @@ def test_unknown_service(self): objecttype: ObjectType = ObjectTypeFactory( uuid="b427ef84-189d-43aa-9efd-7bb2c459e281", _name="Object Type 001", - service=service + 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) + 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(str(objecttype.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") self.assertEqual(objecttype._name, "Object Type 001") self.assertEqual(objecttype.service, service) @@ -123,19 +113,19 @@ def test_invalid_uuid(self): objecttype: ObjectType = ObjectTypeFactory( service=service, uuid="b427ef84-189d-43aa-9efd-7bb2c459e281", - _name="Object Type 001" + _name="Object Type 001", ) with self.assertRaises(ConfigurationRunFailed): - execute_single_step(ObjectTypesConfigurationStep, yaml_source=test_file_path) + 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(str(objecttype.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") self.assertEqual(objecttype._name, "Object Type 1") self.assertEqual(objecttype.service, service) @@ -153,17 +143,13 @@ def test_idempotent_step(self): objecttype_1: ObjectType = objecttypes.first() - self.assertEqual( - str(objecttype_1.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281" - ) + 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(str(objecttype_2.uuid), "b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2") self.assertEqual(objecttype_2._name, "Object Type 2") self.assertEqual(objecttype_2.service, service_2) @@ -176,15 +162,11 @@ def test_idempotent_step(self): self.assertEqual(ObjectType.objects.count(), 2) # objecttype 1 - self.assertEqual( - str(objecttype_1.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281" - ) + 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(str(objecttype_2.uuid), "b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2") self.assertEqual(objecttype_2._name, "Object Type 2") self.assertEqual(objecttype_2.service, service_2) diff --git a/src/objects/setup_configuration/models/objecttypes.py b/src/objects/setup_configuration/models/objecttypes.py index 20714a2a..0f440d33 100644 --- a/src/objects/setup_configuration/models/objecttypes.py +++ b/src/objects/setup_configuration/models/objecttypes.py @@ -1,7 +1,7 @@ from django_setup_configuration.fields import DjangoModelRef from django_setup_configuration.models import ConfigurationModel -from zgw_consumers.models import Service from pydantic import Field +from zgw_consumers.models import Service from objects.core.models import ObjectType @@ -11,11 +11,7 @@ class ObjectTypeConfigurationModel(ConfigurationModel): name: str = DjangoModelRef(ObjectType, "_name") class Meta: - django_model_refs = { - ObjectType: ( - "uuid", - ) - } + django_model_refs = {ObjectType: ("uuid",)} class ObjectTypesConfigurationModel(ConfigurationModel): diff --git a/src/objects/setup_configuration/models/sites.py b/src/objects/setup_configuration/models/sites.py index 3ecdeee6..347d8e0d 100644 --- a/src/objects/setup_configuration/models/sites.py +++ b/src/objects/setup_configuration/models/sites.py @@ -1,4 +1,5 @@ from django.contrib.sites.models import Site + from django_setup_configuration.models import ConfigurationModel from pydantic import Field diff --git a/src/objects/setup_configuration/steps/objecttypes.py b/src/objects/setup_configuration/steps/objecttypes.py index aad58993..91914ac4 100644 --- a/src/objects/setup_configuration/steps/objecttypes.py +++ b/src/objects/setup_configuration/steps/objecttypes.py @@ -1,11 +1,12 @@ from django.core.exceptions import ValidationError from django.db import IntegrityError + from django_setup_configuration.configuration import BaseConfigurationStep from django_setup_configuration.exceptions import ConfigurationRunFailed from zgw_consumers.models import Service -from objects.setup_configuration.models.objecttypes import ObjectTypesConfigurationModel from objects.core.models import ObjectType +from objects.setup_configuration.models.objecttypes import ObjectTypesConfigurationModel class ObjectTypesConfigurationStep(BaseConfigurationStep): @@ -46,12 +47,11 @@ def execute(self, model: ObjectTypesConfigurationModel) -> None: ObjectType.objects.update_or_create( uuid=item.uuid, defaults={ - key: value for key, value in objecttype_kwargs.items() + key: value + for key, value in objecttype_kwargs.items() if key != "uuid" - } + }, ) except IntegrityError as exception: - exception_message = ( - f"Failed configuring ObjectType {item.uuid}." - ) + exception_message = f"Failed configuring ObjectType {item.uuid}." raise ConfigurationRunFailed(exception_message) from exception diff --git a/src/objects/setup_configuration/steps/sites.py b/src/objects/setup_configuration/steps/sites.py index 5ed62f29..199e38f2 100644 --- a/src/objects/setup_configuration/steps/sites.py +++ b/src/objects/setup_configuration/steps/sites.py @@ -1,7 +1,7 @@ from django.contrib.sites.models import Site - from django.core.exceptions import ValidationError from django.db import IntegrityError + from django_setup_configuration.configuration import BaseConfigurationStep from django_setup_configuration.exceptions import ConfigurationRunFailed @@ -30,11 +30,8 @@ def execute(self, model: SitesConfigurationModel) -> None: try: Site.objects.update_or_create( - domain=item.domain, - defaults=dict(name=item.name) + domain=item.domain, defaults=dict(name=item.name) ) except IntegrityError as exception: - exception_message = ( - f"Failed configuring site {item.domain}." - ) + exception_message = f"Failed configuring site {item.domain}." raise ConfigurationRunFailed(exception_message) from exception diff --git a/src/objects/setup_configuration/tests/test_site_config.py b/src/objects/setup_configuration/tests/test_site_config.py index 0c07189b..3dd2f05b 100644 --- a/src/objects/setup_configuration/tests/test_site_config.py +++ b/src/objects/setup_configuration/tests/test_site_config.py @@ -32,8 +32,7 @@ def test_existing_sites(self): test_file_path = str(TEST_FILES / "sites_existing_sites.yaml") example_site, _ = Site.objects.get_or_create( - domain="example.com", - defaults=dict(name="Example site") + domain="example.com", defaults=dict(name="Example site") ) alternative_site = Site.objects.create(