mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Add test for invalid custom field names
This commit is contained in:
parent
050a3b789c
commit
970241e8c6
@ -25,7 +25,7 @@ class Migration(migrations.Migration):
|
|||||||
django.core.validators.RegexValidator(
|
django.core.validators.RegexValidator(
|
||||||
flags=re.RegexFlag['IGNORECASE'],
|
flags=re.RegexFlag['IGNORECASE'],
|
||||||
inverse_match=True,
|
inverse_match=True,
|
||||||
message='No double-underscores are allowed.',
|
message='Double underscores are not permitted in custom field names.',
|
||||||
regex=r'__',
|
regex=r'__',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -87,7 +87,7 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|||||||
),
|
),
|
||||||
RegexValidator(
|
RegexValidator(
|
||||||
regex=r'__',
|
regex=r'__',
|
||||||
message="No double-underscores are allowed.",
|
message="Double underscores are not permitted in custom field names.",
|
||||||
flags=re.IGNORECASE,
|
flags=re.IGNORECASE,
|
||||||
inverse_match=True
|
inverse_match=True
|
||||||
),
|
),
|
||||||
|
@ -29,6 +29,17 @@ class CustomFieldTest(TestCase):
|
|||||||
|
|
||||||
cls.object_type = ContentType.objects.get_for_model(Site)
|
cls.object_type = ContentType.objects.get_for_model(Site)
|
||||||
|
|
||||||
|
def test_invalid_name(self):
|
||||||
|
"""
|
||||||
|
Try creating a CustomField with an invalid name.
|
||||||
|
"""
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
# Invalid character
|
||||||
|
CustomField(name='?', type=CustomFieldTypeChoices.TYPE_TEXT).full_clean()
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
# Double underscores not permitted
|
||||||
|
CustomField(name='foo__bar', type=CustomFieldTypeChoices.TYPE_TEXT).full_clean()
|
||||||
|
|
||||||
def test_text_field(self):
|
def test_text_field(self):
|
||||||
value = 'Foobar!'
|
value = 'Foobar!'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user