Skip to content

Commit

Permalink
[#293] apply formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
SonnyBA committed Dec 4, 2024
1 parent bf02194 commit 56ac44a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 4.2.15 on 2024-11-28 13:01

import logging
from typing import Set

from django.db import migrations, models
from django.db.migrations.state import StateApps
Expand Down
5 changes: 1 addition & 4 deletions src/openklant/components/token/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ class TokenAuth(models.Model):
)

token = models.CharField(
_("token"),
max_length=40,
unique=True,
validators=[validate_non_empty_chars]
_("token"), max_length=40, unique=True, validators=[validate_non_empty_chars]
)

contact_person = models.CharField(
Expand Down
1 change: 0 additions & 1 deletion src/openklant/components/token/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import secrets

from typing import Iterable


Expand Down
8 changes: 2 additions & 6 deletions src/openklant/components/token/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _


# includes tabs, carriage returns, newlines, form-feeds and vertical whitespace characters
ALL_WHITESPACE_PATTERN = re.compile(r"^\s*$")


def validate_non_empty_chars(value: str) -> None:
if not value:
raise ValidationError(
code="invalid",
message=_("Blank values are not allowed")
)
raise ValidationError(code="invalid", message=_("Blank values are not allowed"))

if ALL_WHITESPACE_PATTERN.match(value):
raise ValidationError(
code="all-whitespace",
message=_(
"Tokens cannot consistent exclusively out of whitespace-like characters"
)
),
)
10 changes: 4 additions & 6 deletions src/openklant/setup_configuration/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from openklant.components.token.models import TokenAuth
from openklant.setup_configuration.models import TokenAuthGroupConfigurationModel


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -43,9 +42,7 @@ def execute(self, model: TokenAuthGroupConfigurationModel) -> None:
token_instance = TokenAuth(**model_kwargs)

try:
token_instance.full_clean(
exclude=("id",), validate_unique=False
)
token_instance.full_clean(exclude=("id",), validate_unique=False)
except ValidationError as exception:
exception_message = (
f"Validation error(s) occured for {model.identifier}."
Expand All @@ -60,9 +57,10 @@ def execute(self, model: TokenAuthGroupConfigurationModel) -> None:
TokenAuth.objects.update_or_create(
identifier=model.identifier,
defaults={
key: value for key, value in model_kwargs.items()
key: value
for key, value in model_kwargs.items()
if key != "identifier"
}
},
)
except DatabaseError as exception:
exception_message = f"Failed configuring token {model.identifier}."
Expand Down
59 changes: 16 additions & 43 deletions src/openklant/setup_configuration/tests/test_token_auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def test_empty_database(self):
first_token: TokenAuth = tokens[0]

self.assertEqual(first_token.identifier, "token-1")
self.assertEqual(
first_token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799"
)
self.assertEqual(first_token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799")
self.assertEqual(first_token.contact_person, "Person 1")
self.assertEqual(first_token.email, "[email protected]")
self.assertEqual(first_token.organization, "")
Expand All @@ -37,9 +35,7 @@ def test_empty_database(self):
second_token: TokenAuth = tokens[1]

self.assertEqual(second_token.identifier, "token-2")
self.assertEqual(
second_token.token, "ba9d233e95e04c4a8a661a27daffe7c9bd019067"
)
self.assertEqual(second_token.token, "ba9d233e95e04c4a8a661a27daffe7c9bd019067")
self.assertEqual(second_token.contact_person, "Person 2")
self.assertEqual(second_token.email, "[email protected]")
self.assertEqual(second_token.organization, "")
Expand Down Expand Up @@ -72,9 +68,7 @@ def test_existing_tokens(self):
first_token: TokenAuth = tokens[0]

self.assertEqual(first_token.identifier, "token-1")
self.assertEqual(
first_token.token, "18b2b74ef994314b84021d47b9422e82b685d82f"
)
self.assertEqual(first_token.token, "18b2b74ef994314b84021d47b9422e82b685d82f")
self.assertEqual(first_token.contact_person, "Person 1")
self.assertEqual(first_token.email, "[email protected]")
self.assertEqual(first_token.organization, "")
Expand All @@ -85,7 +79,8 @@ def test_existing_tokens(self):

self.assertEqual(second_token.identifier, "token-2")
self.assertEqual(
second_token.token, "795cb35c930d27b98297df761f0fa52182348875",
second_token.token,
"795cb35c930d27b98297df761f0fa52182348875",
)
self.assertEqual(second_token.contact_person, "Person 2")
self.assertEqual(second_token.email, "[email protected]")
Expand All @@ -96,9 +91,7 @@ def test_existing_tokens(self):
third_token: TokenAuth = tokens[2]

self.assertEqual(third_token.identifier, "token-3")
self.assertEqual(
third_token.token, "e882642bd0ec2482adcdc97258c2e6f98cb06d85"
)
self.assertEqual(third_token.token, "e882642bd0ec2482adcdc97258c2e6f98cb06d85")
self.assertEqual(third_token.contact_person, "Person 3")
self.assertEqual(third_token.email, "[email protected]")
self.assertEqual(third_token.organization, "")
Expand Down Expand Up @@ -134,9 +127,7 @@ def test_with_all_fields(self):
first_token: TokenAuth = tokens[0]

self.assertEqual(first_token.identifier, "token-1")
self.assertEqual(
first_token.token, "18b2b74ef994314b84021d47b9422e82b685d82f"
)
self.assertEqual(first_token.token, "18b2b74ef994314b84021d47b9422e82b685d82f")
self.assertEqual(first_token.contact_person, "Person 1")
self.assertEqual(first_token.email, "[email protected]")
self.assertEqual(first_token.organization, "Organization XYZ")
Expand All @@ -146,9 +137,7 @@ def test_with_all_fields(self):
second_token: TokenAuth = tokens[1]

self.assertEqual(second_token.identifier, "token-2")
self.assertEqual(
second_token.token, "ba9d233e95e04c4a8a661a27daffe7c9bd019067"
)
self.assertEqual(second_token.token, "ba9d233e95e04c4a8a661a27daffe7c9bd019067")
self.assertEqual(second_token.contact_person, "Person 2")
self.assertEqual(second_token.email, "[email protected]")
self.assertEqual(second_token.organization, "")
Expand All @@ -158,9 +147,7 @@ def test_with_all_fields(self):
third_token: TokenAuth = tokens[2]

self.assertEqual(third_token.identifier, "token-3")
self.assertEqual(
third_token.token, "e882642bd0ec2482adcdc97258c2e6f98cb06d85"
)
self.assertEqual(third_token.token, "e882642bd0ec2482adcdc97258c2e6f98cb06d85")
self.assertEqual(third_token.contact_person, "Person 3")
self.assertEqual(third_token.email, "[email protected]")
self.assertEqual(third_token.organization, "Organization ZYX")
Expand All @@ -187,9 +174,7 @@ def test_invalid_email(self):
token: TokenAuth = tokens[0]

self.assertEqual(token.identifier, "token-1")
self.assertEqual(
token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799"
)
self.assertEqual(token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799")
self.assertEqual(token.contact_person, "Person 4")
self.assertEqual(token.email, "[email protected]")
self.assertEqual(token.organization, "")
Expand All @@ -216,9 +201,7 @@ def test_invalid_token(self):
token: TokenAuth = tokens[0]

self.assertEqual(token.identifier, "token-1")
self.assertEqual(
token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799"
)
self.assertEqual(token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799")
self.assertEqual(token.contact_person, "Person 4")
self.assertEqual(token.email, "[email protected]")
self.assertEqual(token.organization, "")
Expand All @@ -245,9 +228,7 @@ def test_invalid_identifier(self):
token: TokenAuth = tokens[0]

self.assertEqual(token.identifier, "token-1")
self.assertEqual(
token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799"
)
self.assertEqual(token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799")
self.assertEqual(token.contact_person, "Person 4")
self.assertEqual(token.email, "[email protected]")
self.assertEqual(token.organization, "")
Expand All @@ -266,9 +247,7 @@ def test_idempotent_step(self):
first_token: TokenAuth = tokens[0]

self.assertEqual(first_token.identifier, "token-1")
self.assertEqual(
first_token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799"
)
self.assertEqual(first_token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799")
self.assertEqual(first_token.contact_person, "Person 1")
self.assertEqual(first_token.email, "[email protected]")
self.assertEqual(first_token.organization, "Organization XYZ")
Expand All @@ -278,9 +257,7 @@ def test_idempotent_step(self):
second_token: TokenAuth = tokens[1]

self.assertEqual(second_token.identifier, "token-2")
self.assertEqual(
second_token.token, "ba9d233e95e04c4a8a661a27daffe7c9bd019067"
)
self.assertEqual(second_token.token, "ba9d233e95e04c4a8a661a27daffe7c9bd019067")
self.assertEqual(second_token.contact_person, "Person 2")
self.assertEqual(second_token.email, "[email protected]")
self.assertEqual(second_token.organization, "Organization ZYX")
Expand All @@ -294,9 +271,7 @@ def test_idempotent_step(self):
first_token.refresh_from_db()

self.assertEqual(first_token.identifier, "token-1")
self.assertEqual(
first_token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799"
)
self.assertEqual(first_token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799")
self.assertEqual(first_token.contact_person, "Person 1")
self.assertEqual(first_token.email, "[email protected]")
self.assertEqual(first_token.organization, "Organization XYZ")
Expand All @@ -306,9 +281,7 @@ def test_idempotent_step(self):
second_token.refresh_from_db()

self.assertEqual(second_token.identifier, "token-2")
self.assertEqual(
second_token.token, "ba9d233e95e04c4a8a661a27daffe7c9bd019067"
)
self.assertEqual(second_token.token, "ba9d233e95e04c4a8a661a27daffe7c9bd019067")
self.assertEqual(second_token.contact_person, "Person 2")
self.assertEqual(second_token.email, "[email protected]")
self.assertEqual(second_token.organization, "Organization ZYX")
Expand Down

0 comments on commit 56ac44a

Please sign in to comment.