Skip to content

Commit 1a7e248

Browse files
committed
Testing TagAdminForm and remove check of size by ensuring constraint at model level
1 parent 9358f44 commit 1a7e248

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

tagging/forms.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ def clean_name(self):
1919
tag_names = parse_tag_input(value)
2020
if len(tag_names) > 1:
2121
raise forms.ValidationError(_('Multiple tags were given.'))
22-
elif len(tag_names[0]) > settings.MAX_TAG_LENGTH:
23-
raise forms.ValidationError(
24-
_('A tag may be no more than %s characters long.') %
25-
settings.MAX_TAG_LENGTH)
2622
return value
2723

2824

tagging/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ class Tag(models.Model):
470470
A tag.
471471
"""
472472
name = models.CharField(
473-
_('name'), max_length=50,
473+
_('name'), max_length=settings.MAX_TAG_LENGTH,
474474
unique=True, db_index=True)
475475

476476
objects = TagManager()

tagging/tests/tests.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from tagging import settings
1414
from tagging.forms import TagField
15+
from tagging.forms import TagAdminForm
1516
from tagging.models import Tag
1617
from tagging.models import TaggedItem
1718
from tagging.tests.models import Article
@@ -1035,6 +1036,27 @@ def test_tag_d_validation(self):
10351036
forms.ValidationError, t.clean,
10361037
'foo qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbn bar')
10371038

1039+
#########
1040+
# Forms #
1041+
#########
1042+
1043+
1044+
class TestTagAdminForm(TestCase):
1045+
1046+
def test_clean_name(self):
1047+
datas = {'name': 'tag'}
1048+
form = TagAdminForm(datas)
1049+
self.assertTrue(form.is_valid())
1050+
1051+
def test_clean_name_multi(self):
1052+
datas = {'name': 'tag error'}
1053+
form = TagAdminForm(datas)
1054+
self.assertFalse(form.is_valid())
1055+
1056+
def test_clean_name_too_long(self):
1057+
datas = {'name': 't' * (settings.MAX_TAG_LENGTH + 1)}
1058+
form = TagAdminForm(datas)
1059+
self.assertFalse(form.is_valid())
10381060

10391061
#########
10401062
# Views #

0 commit comments

Comments
 (0)