Skip to content

Commit

Permalink
[#485] Add validate_no_empty for identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Dec 16, 2024
1 parent 80c5b0e commit 51da707
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/objects/setup_configuration/tests/test_token_auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,25 @@ def test_invalid_setup_identifier(self):
execute_single_step(TokenAuthConfigurationStep, object_source=object_source)
self.assertTrue("String should match pattern" in str(command_error.exception))
self.assertEqual(TokenAuth.objects.count(), 0)

def test_invalid_empty_identifier(self):
object_source = {
"tokenauth_config_enable": True,
"tokenauth": {
"items": [
{
"identifier": "",
"token": "ba9d233e95e04c4a8a661a27daffe7c9bd019067",
"contact_person": "Person 1",
"email": "[email protected]",
"organization": "Organization 1",
"application": "Application 1",
"administration": "Administration 1",
},
],
},
}
with self.assertRaises(PrerequisiteFailed) as command_error:
execute_single_step(TokenAuthConfigurationStep, object_source=object_source)
self.assertTrue("String should match pattern" in str(command_error.exception))
self.assertEqual(TokenAuth.objects.count(), 0)
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Migration(migrations.Migration):
field=models.SlugField(
help_text="A human-friendly label to refer to this token",
unique=True,
validators=[objects.token.validators.validate_no_empty],
),
),
migrations.AlterField(
Expand Down
1 change: 1 addition & 0 deletions src/objects/token/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TokenAuth(models.Model):
identifier = models.SlugField(
unique=True,
help_text=_("A human-friendly label to refer to this token"),
validators=[validate_no_empty],
)
token = models.CharField(
_("token"),
Expand Down

0 comments on commit 51da707

Please sign in to comment.