Skip to content

Commit

Permalink
[#467] apply code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
SonnyBA committed Dec 10, 2024
1 parent f91b37d commit 43964bd
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/objects/core/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
60 changes: 21 additions & 39 deletions src/objects/core/tests/test_objecttype_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -67,27 +63,21 @@ 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)

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(str(objecttype_3.uuid), "7229549b-7b41-47d1-8106-414b2a69751b")
self.assertEqual(objecttype_3._name, "Object Type 3")
self.assertEqual(objecttype_3.service, service_2)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)
8 changes: 2 additions & 6 deletions src/objects/setup_configuration/models/objecttypes.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions src/objects/setup_configuration/models/sites.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.sites.models import Site

from django_setup_configuration.models import ConfigurationModel
from pydantic import Field

Expand Down
12 changes: 6 additions & 6 deletions src/objects/setup_configuration/steps/objecttypes.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
9 changes: 3 additions & 6 deletions src/objects/setup_configuration/steps/sites.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions src/objects/setup_configuration/tests/test_site_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 43964bd

Please sign in to comment.