From 7f11929ed8482ba63e298ce2237dca80dfe7812f Mon Sep 17 00:00:00 2001 From: Daniel Mursa Date: Fri, 13 Dec 2024 10:58:33 +0100 Subject: [PATCH 1/6] [maykinmedia/objects-api#481] Fix INSTALL.rst --- INSTALL.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.rst b/INSTALL.rst index dcc927a..ccb6a29 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -276,7 +276,7 @@ There are no specific commands for the project. See .. _Django framework commands: https://docs.djangoproject.com/en/dev/ref/django-admin/#available-commands Configuration (CLI) -======== +=================== After deploying Objecttypes API, they need to be configured to be fully functional. The command line tool setup_configuration assist with this configuration: From ea8953925a8ce821410680144f69a130b23a6c8d Mon Sep 17 00:00:00 2001 From: Daniel Mursa Date: Fri, 13 Dec 2024 11:35:56 +0100 Subject: [PATCH 2/6] [maykinmedia/objects-api#481] Add link to repo in INSTALL.rst --- INSTALL.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/INSTALL.rst b/INSTALL.rst index ccb6a29..6b99d42 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -278,10 +278,12 @@ There are no specific commands for the project. See Configuration (CLI) =================== -After deploying Objecttypes API, they need to be configured to be fully functional. The command line tool setup_configuration assist with this configuration: +After deploying Objecttypes API, they need to be configured to be fully functional. +The command line tool ``setup_configuration`` assist with this configuration. You can get the full command documentation with: -.. code-block:: bash +See `Django Setup Configuration`_ for all documentation, or type +``python src/manage.py setup_configuration --help``. - python src/manage.py setup_configuration --help \ No newline at end of file +.. _Django Setup Configuration: https://github.com/maykinmedia/django-setup-configuration \ No newline at end of file From 3310deb7875aca0e516a95329d1a62ec14b52efe Mon Sep 17 00:00:00 2001 From: Daniel Mursa Date: Fri, 13 Dec 2024 12:01:03 +0100 Subject: [PATCH 3/6] [maykinmedia/objects-api#481] Fix token tests --- .../token/tests/test_authenticaton.py | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/objecttypes/token/tests/test_authenticaton.py b/src/objecttypes/token/tests/test_authenticaton.py index fb1748d..1873c43 100644 --- a/src/objecttypes/token/tests/test_authenticaton.py +++ b/src/objecttypes/token/tests/test_authenticaton.py @@ -19,16 +19,42 @@ def test_valid_token(self): ) self.assertEqual(response.status_code, status.HTTP_200_OK) - def test_invalid_token(self): + def test_valid_token_with_no_spaces(self): + token_auth = TokenAuth.objects.create( + contact_person="contact_person", + email="contact_person@gmail.nl", + identifier="token-1", + token="1234-Token-5678", + ) response = self.client.get( reverse("v2:objecttype-list"), - HTTP_AUTHORIZATION="Token 1234-Token-5678", + HTTP_AUTHORIZATION=f"Token {token_auth.token}", + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_invalid_token_with_spaces(self): + token_auth = TokenAuth.objects.create( + contact_person="contact_person", + email="contact_person@gmail.nl", + identifier="token-1", + token="1234 Token 5678", + ) + response = self.client.get( + reverse("v2:objecttype-list"), + HTTP_AUTHORIZATION=f"Token {token_auth.token}", ) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) + def test_invalid_token_existing(self): + response = self.client.get( + reverse("v2:objecttype-list"), + HTTP_AUTHORIZATION="Token 1234-Token-5678", + ) + self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) + def test_empty_token(self): response = self.client.get( - reverse("v2:objecttype-list"), HTTP_AUTHORIZATION="Token" + reverse("v2:objecttype-list"), HTTP_AUTHORIZATION="Token " ) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) From fd26732dd2a1c871696fd8ac0da0846b7874e602 Mon Sep 17 00:00:00 2001 From: Daniel Mursa Date: Fri, 13 Dec 2024 12:03:16 +0100 Subject: [PATCH 4/6] [maykinmedia/objects-api#481] Change name validate_no_whitespace --- ...enauth_identifier_alter_tokenauth_token.py | 2 +- src/objecttypes/token/models.py | 4 ++-- .../token/tests/test_validators.py | 22 +++++++++---------- src/objecttypes/token/validators.py | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/objecttypes/token/migrations/0009_tokenauth_identifier_alter_tokenauth_token.py b/src/objecttypes/token/migrations/0009_tokenauth_identifier_alter_tokenauth_token.py index caa6c34..5adbaf5 100644 --- a/src/objecttypes/token/migrations/0009_tokenauth_identifier_alter_tokenauth_token.py +++ b/src/objecttypes/token/migrations/0009_tokenauth_identifier_alter_tokenauth_token.py @@ -59,7 +59,7 @@ class Migration(migrations.Migration): field=models.CharField( max_length=40, unique=True, - validators=[objecttypes.token.validators.validate_whitespace], + validators=[objecttypes.token.validators.validate_no_whitespace], verbose_name="token", ), ), diff --git a/src/objecttypes/token/models.py b/src/objecttypes/token/models.py index cf011b8..6a3b659 100644 --- a/src/objecttypes/token/models.py +++ b/src/objecttypes/token/models.py @@ -3,7 +3,7 @@ from django.db import models from django.utils.translation import gettext_lazy as _ -from objecttypes.token.validators import validate_whitespace +from objecttypes.token.validators import validate_no_whitespace class TokenAuth(models.Model): @@ -16,7 +16,7 @@ class TokenAuth(models.Model): _("token"), max_length=40, unique=True, - validators=[validate_whitespace], + validators=[validate_no_whitespace], ) contact_person = models.CharField( diff --git a/src/objecttypes/token/tests/test_validators.py b/src/objecttypes/token/tests/test_validators.py index a1fe023..8877f97 100644 --- a/src/objecttypes/token/tests/test_validators.py +++ b/src/objecttypes/token/tests/test_validators.py @@ -1,45 +1,45 @@ from django.core.exceptions import ValidationError from django.test import SimpleTestCase -from objecttypes.token.validators import validate_whitespace +from objecttypes.token.validators import validate_no_whitespace class WhiteSpaceValidatorTestCase(SimpleTestCase): def test_characters_only(self): - self.assertIsNone(validate_whitespace("test123")) + self.assertIsNone(validate_no_whitespace("test123")) def test_trailing_whitespace(self): with self.assertRaises(ValidationError): - validate_whitespace("test123 ") + validate_no_whitespace("test123 ") def test_leading_whitespace(self): with self.assertRaises(ValidationError): - validate_whitespace(" test123") + validate_no_whitespace(" test123") def test_whitespace_in_between(self): with self.assertRaises(ValidationError): - validate_whitespace("test 123") + validate_no_whitespace("test 123") def test_whitespace_only(self): with self.assertRaises(ValidationError): - validate_whitespace(" ") + validate_no_whitespace(" ") def test_trailing_tab_character(self): with self.assertRaises(ValidationError): - validate_whitespace("test123\t") + validate_no_whitespace("test123\t") def test_leading_tab_character(self): with self.assertRaises(ValidationError): - validate_whitespace("\ttest123") + validate_no_whitespace("\ttest123") def test_tab_character_in_between(self): with self.assertRaises(ValidationError): - validate_whitespace("test\t123") + validate_no_whitespace("test\t123") def test_tab_characters_only(self): with self.assertRaises(ValidationError): - validate_whitespace("\t\t") + validate_no_whitespace("\t\t") def test_blank_value(self): with self.assertRaises(ValidationError): - validate_whitespace("") + validate_no_whitespace("") diff --git a/src/objecttypes/token/validators.py b/src/objecttypes/token/validators.py index a8fc228..9bab299 100644 --- a/src/objecttypes/token/validators.py +++ b/src/objecttypes/token/validators.py @@ -7,7 +7,7 @@ WHITESPACE_PATTERN = re.compile(r".*\s.*") -def validate_whitespace(value: str) -> None: +def validate_no_whitespace(value: str) -> None: if not value: raise ValidationError(code="invalid", message=_("Blank values are not allowed")) From dcecf538071f8a8f02795a739cfc13e4fe63036b Mon Sep 17 00:00:00 2001 From: Daniel Mursa Date: Fri, 13 Dec 2024 12:08:48 +0100 Subject: [PATCH 5/6] [maykinmedia/objects-api#481] Remove unused validation control --- src/objecttypes/token/tests/test_validators.py | 4 ---- src/objecttypes/token/validators.py | 3 --- 2 files changed, 7 deletions(-) diff --git a/src/objecttypes/token/tests/test_validators.py b/src/objecttypes/token/tests/test_validators.py index 8877f97..a042f29 100644 --- a/src/objecttypes/token/tests/test_validators.py +++ b/src/objecttypes/token/tests/test_validators.py @@ -39,7 +39,3 @@ def test_tab_character_in_between(self): def test_tab_characters_only(self): with self.assertRaises(ValidationError): validate_no_whitespace("\t\t") - - def test_blank_value(self): - with self.assertRaises(ValidationError): - validate_no_whitespace("") diff --git a/src/objecttypes/token/validators.py b/src/objecttypes/token/validators.py index 9bab299..4101ac2 100644 --- a/src/objecttypes/token/validators.py +++ b/src/objecttypes/token/validators.py @@ -8,9 +8,6 @@ def validate_no_whitespace(value: str) -> None: - if not value: - raise ValidationError(code="invalid", message=_("Blank values are not allowed")) - if WHITESPACE_PATTERN.match(value): raise ValidationError( code="all-whitespace", From f3f44d2ffd05a61148a2cfadc72eb1c9c3d845bc Mon Sep 17 00:00:00 2001 From: Daniel Mursa Date: Fri, 13 Dec 2024 12:09:50 +0100 Subject: [PATCH 6/6] [maykinmedia/objects-api#481] Black --- src/objecttypes/token/tests/test_authenticaton.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objecttypes/token/tests/test_authenticaton.py b/src/objecttypes/token/tests/test_authenticaton.py index 1873c43..b6c3930 100644 --- a/src/objecttypes/token/tests/test_authenticaton.py +++ b/src/objecttypes/token/tests/test_authenticaton.py @@ -51,7 +51,7 @@ def test_invalid_token_existing(self): HTTP_AUTHORIZATION="Token 1234-Token-5678", ) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) - + def test_empty_token(self): response = self.client.get( reverse("v2:objecttype-list"), HTTP_AUTHORIZATION="Token "