diff options
author | Edward Henderson <kutenai@me.com> | 2015-04-15 16:28:49 -0600 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2015-07-17 13:48:58 -0400 |
commit | f8cc464452f495fce2a3d6f7494396c8f798a1e6 (patch) | |
tree | 61049a8351e327b59c98341f98dacda0e8186be2 /tests/model_fields | |
parent | adffff79a36f7de30f438915c492e475e17025f6 (diff) | |
download | django-f8cc464452f495fce2a3d6f7494396c8f798a1e6.tar.gz |
Fixed #16501 -- Added an allow_unicode parameter to SlugField.
Thanks Flavio Curella and Berker Peksag for the initial patch.
Diffstat (limited to 'tests/model_fields')
-rw-r--r-- | tests/model_fields/models.py | 4 | ||||
-rw-r--r-- | tests/model_fields/tests.py | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py index 350e98a80b..931468c9bf 100644 --- a/tests/model_fields/models.py +++ b/tests/model_fields/models.py @@ -86,6 +86,10 @@ class BigS(models.Model): s = models.SlugField(max_length=255) +class UnicodeSlugField(models.Model): + s = models.SlugField(max_length=255, allow_unicode=True) + + class SmallIntegerModel(models.Model): value = models.SmallIntegerField() diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index 353c15f491..8bbead1a36 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from __future__ import unicode_literals import datetime @@ -20,6 +21,7 @@ from django.db.models.fields import ( from django.db.models.fields.files import FileField, ImageField from django.test.utils import requires_tz_support from django.utils import six, timezone +from django.utils.encoding import force_str from django.utils.functional import lazy from .models import ( @@ -27,7 +29,8 @@ from .models import ( Document, FksToBooleans, FkToChar, FloatModel, Foo, GenericIPAddress, IntegerModel, NullBooleanModel, PositiveIntegerModel, PositiveSmallIntegerModel, Post, PrimaryKeyCharModel, RenamedField, - SmallIntegerModel, VerboseNameField, Whiz, WhizIter, WhizIterEmpty, + SmallIntegerModel, UnicodeSlugField, VerboseNameField, Whiz, WhizIter, + WhizIterEmpty, ) @@ -113,7 +116,6 @@ class BasicFieldTests(test.TestCase): self.assertIsInstance(field.formfield(choices_form_class=klass), klass) def test_field_str(self): - from django.utils.encoding import force_str f = Foo._meta.get_field('a') self.assertEqual(force_str(f), "model_fields.Foo.a") @@ -515,6 +517,14 @@ class SlugFieldTests(test.TestCase): bs = BigS.objects.get(pk=bs.pk) self.assertEqual(bs.s, 'slug' * 50) + def test_slugfield_unicode_max_length(self): + """ + SlugField with allow_unicode=True should honor max_length. + """ + bs = UnicodeSlugField.objects.create(s='你好你好' * 50) + bs = UnicodeSlugField.objects.get(pk=bs.pk) + self.assertEqual(bs.s, '你好你好' * 50) + class ValidationTest(test.SimpleTestCase): def test_charfield_raises_error_on_empty_string(self): |