diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/generic_relations/models.py | 30 | ||||
| -rw-r--r-- | tests/modeltests/model_forms/models.py | 56 | ||||
| -rw-r--r-- | tests/modeltests/serializers/models.py | 38 | ||||
| -rw-r--r-- | tests/regressiontests/cache/tests.py | 58 | ||||
| -rw-r--r-- | tests/regressiontests/defaultfilters/tests.py | 12 | ||||
| -rw-r--r-- | tests/regressiontests/forms/localflavor/cl.py | 8 | ||||
| -rw-r--r-- | tests/regressiontests/forms/localflavor/uk.py | 29 | ||||
| -rw-r--r-- | tests/regressiontests/httpwrappers/tests.py | 38 | ||||
| -rw-r--r-- | tests/regressiontests/maxlength/tests.py | 6 | ||||
| -rw-r--r-- | tests/regressiontests/model_regress/models.py | 10 | ||||
| -rw-r--r-- | tests/regressiontests/templates/filters.py | 4 | ||||
| -rw-r--r-- | tests/regressiontests/views/media/file.unknown | 1 | ||||
| -rw-r--r-- | tests/regressiontests/views/tests/static.py | 8 | ||||
| -rwxr-xr-x | tests/runtests.py | 3 |
14 files changed, 236 insertions, 65 deletions
diff --git a/tests/modeltests/generic_relations/models.py b/tests/modeltests/generic_relations/models.py index ce1d824ca8..ff86823d07 100644 --- a/tests/modeltests/generic_relations/models.py +++ b/tests/modeltests/generic_relations/models.py @@ -18,42 +18,42 @@ class TaggedItem(models.Model): tag = models.SlugField() content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() - + content_object = generic.GenericForeignKey() - + class Meta: ordering = ["tag"] - + def __unicode__(self): return self.tag class Animal(models.Model): common_name = models.CharField(max_length=150) latin_name = models.CharField(max_length=150) - + tags = generic.GenericRelation(TaggedItem) def __unicode__(self): return self.common_name - + class Vegetable(models.Model): name = models.CharField(max_length=150) is_yucky = models.BooleanField(default=True) - + tags = generic.GenericRelation(TaggedItem) - + def __unicode__(self): return self.name - + class Mineral(models.Model): name = models.CharField(max_length=150) hardness = models.PositiveSmallIntegerField() - + # note the lack of an explicit GenericRelation here... - + def __unicode__(self): return self.name - + __test__ = {'API_TESTS':""" # Create the world in 7 lines of code... >>> lion = Animal(common_name="Lion", latin_name="Panthera leo") @@ -117,13 +117,13 @@ __test__ = {'API_TESTS':""" >>> [(t.tag, t.content_type, t.object_id) for t in TaggedItem.objects.all()] [(u'clearish', <ContentType: mineral>, 1), (u'fatty', <ContentType: vegetable>, 2), (u'salty', <ContentType: vegetable>, 2), (u'shiny', <ContentType: animal>, 2)] -# If Generic Relation is not explicitly defined, any related objects +# If Generic Relation is not explicitly defined, any related objects # remain after deletion of the source object. >>> quartz.delete() >>> [(t.tag, t.content_type, t.object_id) for t in TaggedItem.objects.all()] [(u'clearish', <ContentType: mineral>, 1), (u'fatty', <ContentType: vegetable>, 2), (u'salty', <ContentType: vegetable>, 2), (u'shiny', <ContentType: animal>, 2)] -# If you delete a tag, the objects using the tag are unaffected +# If you delete a tag, the objects using the tag are unaffected # (other than losing a tag) >>> tag = TaggedItem.objects.get(id=1) >>> tag.delete() @@ -132,4 +132,8 @@ __test__ = {'API_TESTS':""" >>> [(t.tag, t.content_type, t.object_id) for t in TaggedItem.objects.all()] [(u'clearish', <ContentType: mineral>, 1), (u'salty', <ContentType: vegetable>, 2), (u'shiny', <ContentType: animal>, 2)] +>>> ctype = ContentType.objects.get_for_model(lion) +>>> Animal.objects.filter(tags__content_type=ctype) +[<Animal: Platypus>] + """} diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index cd92956270..17c3b3551c 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -143,7 +143,7 @@ familiar with the mechanics. ... model = Article Traceback (most recent call last): ... -ImproperlyConfigured: BadForm defines more than one model. +ImproperlyConfigured: BadForm defines a different model than its parent. >>> class ArticleForm(ModelForm): ... class Meta: @@ -155,6 +155,12 @@ Traceback (most recent call last): ... ImproperlyConfigured: BadForm's base classes define more than one model. +This one is OK since the subclass specifies the same model as the parent. + +>>> class SubCategoryForm(CategoryForm): +... class Meta: +... model = Category + # Old form_for_x tests ####################################################### @@ -167,7 +173,7 @@ ImproperlyConfigured: BadForm's base classes define more than one model. >>> class CategoryForm(ModelForm): ... class Meta: ... model = Category ->>> f = CategoryForm(Category()) +>>> f = CategoryForm() >>> print f <tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr> <tr><th><label for="id_slug">Slug:</label></th><td><input id="id_slug" type="text" name="slug" maxlength="20" /></td></tr> @@ -179,13 +185,13 @@ ImproperlyConfigured: BadForm's base classes define more than one model. >>> print f['name'] <input id="id_name" type="text" name="name" maxlength="20" /> ->>> f = CategoryForm(Category(), auto_id=False) +>>> f = CategoryForm(auto_id=False) >>> print f.as_ul() <li>Name: <input type="text" name="name" maxlength="20" /></li> <li>Slug: <input type="text" name="slug" maxlength="20" /></li> <li>The URL: <input type="text" name="url" maxlength="40" /></li> ->>> f = CategoryForm(Category(), {'name': 'Entertainment', 'slug': 'entertainment', 'url': 'entertainment'}) +>>> f = CategoryForm({'name': 'Entertainment', 'slug': 'entertainment', 'url': 'entertainment'}) >>> f.is_valid() True >>> f.cleaned_data @@ -196,7 +202,7 @@ True >>> Category.objects.all() [<Category: Entertainment>] ->>> f = CategoryForm(Category(), {'name': "It's a test", 'slug': 'its-test', 'url': 'test'}) +>>> f = CategoryForm({'name': "It's a test", 'slug': 'its-test', 'url': 'test'}) >>> f.is_valid() True >>> f.cleaned_data @@ -210,7 +216,7 @@ True If you call save() with commit=False, then it will return an object that hasn't yet been saved to the database. In this case, it's up to you to call save() on the resulting model instance. ->>> f = CategoryForm(Category(), {'name': 'Third test', 'slug': 'third-test', 'url': 'third'}) +>>> f = CategoryForm({'name': 'Third test', 'slug': 'third-test', 'url': 'third'}) >>> f.is_valid() True >>> f.cleaned_data @@ -225,7 +231,7 @@ True [<Category: Entertainment>, <Category: It's a test>, <Category: Third test>] If you call save() with invalid data, you'll get a ValueError. ->>> f = CategoryForm(Category(), {'name': '', 'slug': '', 'url': 'foo'}) +>>> f = CategoryForm({'name': '', 'slug': '', 'url': 'foo'}) >>> f.errors {'name': [u'This field is required.'], 'slug': [u'This field is required.']} >>> f.cleaned_data @@ -236,7 +242,7 @@ AttributeError: 'CategoryForm' object has no attribute 'cleaned_data' Traceback (most recent call last): ... ValueError: The Category could not be created because the data didn't validate. ->>> f = CategoryForm(Category(), {'name': '', 'slug': '', 'url': 'foo'}) +>>> f = CategoryForm({'name': '', 'slug': '', 'url': 'foo'}) >>> f.save() Traceback (most recent call last): ... @@ -253,7 +259,7 @@ fields with the 'choices' attribute are represented by a ChoiceField. >>> class ArticleForm(ModelForm): ... class Meta: ... model = Article ->>> f = ArticleForm(Article(), auto_id=False) +>>> f = ArticleForm(auto_id=False) >>> print f <tr><th>Headline:</th><td><input type="text" name="headline" maxlength="50" /></td></tr> <tr><th>Slug:</th><td><input type="text" name="slug" maxlength="50" /></td></tr> @@ -286,7 +292,7 @@ from the form can't provide a value for that field! ... class Meta: ... model = Article ... fields = ('headline','pub_date') ->>> f = PartialArticleForm(Article(), auto_id=False) +>>> f = PartialArticleForm(auto_id=False) >>> print f <tr><th>Headline:</th><td><input type="text" name="headline" maxlength="50" /></td></tr> <tr><th>Pub date:</th><td><input type="text" name="pub_date" /></td></tr> @@ -298,7 +304,7 @@ current values are inserted as 'initial' data in each Field. >>> class RoykoForm(ModelForm): ... class Meta: ... model = Writer ->>> f = RoykoForm(w, auto_id=False) +>>> f = RoykoForm(auto_id=False, instance=w) >>> print f <tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr> @@ -309,7 +315,7 @@ current values are inserted as 'initial' data in each Field. >>> class TestArticleForm(ModelForm): ... class Meta: ... model = Article ->>> f = TestArticleForm(art, auto_id=False) +>>> f = TestArticleForm(auto_id=False, instance=art) >>> print f.as_ul() <li>Headline: <input type="text" name="headline" value="Test article" maxlength="50" /></li> <li>Slug: <input type="text" name="slug" value="test-article" maxlength="50" /></li> @@ -331,7 +337,7 @@ current values are inserted as 'initial' data in each Field. <option value="2">It's a test</option> <option value="3">Third test</option> </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> ->>> f = TestArticleForm(art, {'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': u'1', 'article': 'Hello.'}) +>>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': u'1', 'article': 'Hello.'}, instance=art) >>> f.is_valid() True >>> test_art = f.save() @@ -347,7 +353,7 @@ by specifying a 'fields' argument to form_for_instance. ... class Meta: ... model = Article ... fields=('headline', 'slug', 'pub_date') ->>> f = PartialArticleForm(art, {'headline': u'New headline', 'slug': 'new-headline', 'pub_date': u'1988-01-04'}, auto_id=False) +>>> f = PartialArticleForm({'headline': u'New headline', 'slug': 'new-headline', 'pub_date': u'1988-01-04'}, auto_id=False, instance=art) >>> print f.as_ul() <li>Headline: <input type="text" name="headline" value="New headline" maxlength="50" /></li> <li>Slug: <input type="text" name="slug" value="new-headline" maxlength="50" /></li> @@ -370,7 +376,7 @@ Add some categories and test the many-to-many form output. >>> class TestArticleForm(ModelForm): ... class Meta: ... model = Article ->>> f = TestArticleForm(new_art, auto_id=False) +>>> f = TestArticleForm(auto_id=False, instance=new_art) >>> print f.as_ul() <li>Headline: <input type="text" name="headline" value="New headline" maxlength="50" /></li> <li>Slug: <input type="text" name="slug" value="new-headline" maxlength="50" /></li> @@ -393,8 +399,8 @@ Add some categories and test the many-to-many form output. <option value="3">Third test</option> </select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> ->>> f = TestArticleForm(new_art, {'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04', -... 'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']}) +>>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04', +... 'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art) >>> new_art = f.save() >>> new_art.id 1 @@ -403,8 +409,8 @@ Add some categories and test the many-to-many form output. [<Category: Entertainment>, <Category: It's a test>] Now, submit form data with no categories. This deletes the existing categories. ->>> f = TestArticleForm(new_art, {'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04', -... 'writer': u'1', 'article': u'Hello.'}) +>>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04', +... 'writer': u'1', 'article': u'Hello.'}, instance=new_art) >>> new_art = f.save() >>> new_art.id 1 @@ -416,7 +422,7 @@ Create a new article, with categories, via the form. >>> class ArticleForm(ModelForm): ... class Meta: ... model = Article ->>> f = ArticleForm(Article(), {'headline': u'The walrus was Paul', 'slug': u'walrus-was-paul', 'pub_date': u'1967-11-01', +>>> f = ArticleForm({'headline': u'The walrus was Paul', 'slug': u'walrus-was-paul', 'pub_date': u'1967-11-01', ... 'writer': u'1', 'article': u'Test.', 'categories': [u'1', u'2']}) >>> new_art = f.save() >>> new_art.id @@ -429,7 +435,7 @@ Create a new article, with no categories, via the form. >>> class ArticleForm(ModelForm): ... class Meta: ... model = Article ->>> f = ArticleForm(Article(), {'headline': u'The walrus was Paul', 'slug': u'walrus-was-paul', 'pub_date': u'1967-11-01', +>>> f = ArticleForm({'headline': u'The walrus was Paul', 'slug': u'walrus-was-paul', 'pub_date': u'1967-11-01', ... 'writer': u'1', 'article': u'Test.'}) >>> new_art = f.save() >>> new_art.id @@ -443,7 +449,7 @@ The m2m data won't be saved until save_m2m() is invoked on the form. >>> class ArticleForm(ModelForm): ... class Meta: ... model = Article ->>> f = ArticleForm(Article(), {'headline': u'The walrus was Paul', 'slug': 'walrus-was-paul', 'pub_date': u'1967-11-01', +>>> f = ArticleForm({'headline': u'The walrus was Paul', 'slug': 'walrus-was-paul', 'pub_date': u'1967-11-01', ... 'writer': u'1', 'article': u'Test.', 'categories': [u'1', u'2']}) >>> new_art = f.save(commit=False) @@ -474,7 +480,7 @@ existing Category instance. <Category: Third test> >>> cat.id 3 ->>> form = ShortCategory(cat, {'name': 'Third', 'slug': 'third', 'url': '3rd'}) +>>> form = ShortCategory({'name': 'Third', 'slug': 'third', 'url': '3rd'}, instance=cat) >>> form.save() <Category: Third> >>> Category.objects.get(id=3) @@ -486,7 +492,7 @@ the data in the database when the form is instantiated. >>> class ArticleForm(ModelForm): ... class Meta: ... model = Article ->>> f = ArticleForm(Article(), auto_id=False) +>>> f = ArticleForm(auto_id=False) >>> print f.as_ul() <li>Headline: <input type="text" name="headline" maxlength="50" /></li> <li>Slug: <input type="text" name="slug" maxlength="50" /></li> @@ -690,7 +696,7 @@ ValidationError: [u'Select a valid choice. 4 is not one of the available choices >>> class PhoneNumberForm(ModelForm): ... class Meta: ... model = PhoneNumber ->>> f = PhoneNumberForm(PhoneNumber(), {'phone': '(312) 555-1212', 'description': 'Assistance'}) +>>> f = PhoneNumberForm({'phone': '(312) 555-1212', 'description': 'Assistance'}) >>> f.is_valid() True >>> f.cleaned_data diff --git a/tests/modeltests/serializers/models.py b/tests/modeltests/serializers/models.py index 1c7dbabfd1..0ccc19f895 100644 --- a/tests/modeltests/serializers/models.py +++ b/tests/modeltests/serializers/models.py @@ -218,3 +218,41 @@ None 3.4 """} + +try: + import yaml + __test__['YAML'] = """ +# Create some data: + +>>> articles = Article.objects.all().order_by("id")[:2] +>>> from django.core import serializers + +# test if serial + +>>> serialized = serializers.serialize("yaml", articles) +>>> print serialized +- fields: + author: 2 + categories: [3, 1] + headline: Just kidding; I love TV poker + pub_date: 2006-06-16 11:00:00 + model: serializers.article + pk: 1 +- fields: + author: 1 + categories: [2, 3] + headline: Time to reform copyright + pub_date: 2006-06-16 13:00:11 + model: serializers.article + pk: 2 +<BLANKLINE> + +>>> obs = list(serializers.deserialize("yaml", serialized)) +>>> for i in obs: +... print i +<DeserializedObject: Just kidding; I love TV poker> +<DeserializedObject: Time to reform copyright> + +""" +except ImportError: pass + diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py index 9ac2722b0a..f050348c77 100644 --- a/tests/regressiontests/cache/tests.py +++ b/tests/regressiontests/cache/tests.py @@ -3,8 +3,8 @@ # Unit tests for cache framework # Uses whatever cache backend is set in the test settings file. -import time, unittest - +import time +import unittest from django.core.cache import cache from django.utils.cache import patch_vary_headers from django.http import HttpResponse @@ -27,7 +27,7 @@ class Cache(unittest.TestCase): cache.add("addkey1", "value") cache.add("addkey1", "newvalue") self.assertEqual(cache.get("addkey1"), "value") - + def test_non_existent(self): # get with non-existent keys self.assertEqual(cache.get("does_not_exist"), None) @@ -76,10 +76,16 @@ class Cache(unittest.TestCase): self.assertEqual(cache.get("stuff"), stuff) def test_expiration(self): - # expiration - cache.set('expire', 'very quickly', 1) - time.sleep(2) - self.assertEqual(cache.get("expire"), None) + cache.set('expire1', 'very quickly', 1) + cache.set('expire2', 'very quickly', 1) + cache.set('expire3', 'very quickly', 1) + + time.sleep(2) + self.assertEqual(cache.get("expire1"), None) + + cache.add("expire2", "newvalue") + self.assertEqual(cache.get("expire2"), "newvalue") + self.assertEqual(cache.has_key("expire3"), False) def test_unicode(self): stuff = { @@ -92,6 +98,44 @@ class Cache(unittest.TestCase): cache.set(key, value) self.assertEqual(cache.get(key), value) +import os +import md5 +import shutil +import tempfile +from django.core.cache.backends.filebased import CacheClass as FileCache + +class FileBasedCacheTests(unittest.TestCase): + """ + Specific test cases for the file-based cache. + """ + def setUp(self): + self.dirname = tempfile.mktemp() + os.mkdir(self.dirname) + self.cache = FileCache(self.dirname, {}) + + def tearDown(self): + shutil.rmtree(self.dirname) + + def test_hashing(self): + """Test that keys are hashed into subdirectories correctly""" + self.cache.set("foo", "bar") + keyhash = md5.new("foo").hexdigest() + keypath = os.path.join(self.dirname, keyhash[:2], keyhash[2:4], keyhash[4:]) + self.assert_(os.path.exists(keypath)) + + def test_subdirectory_removal(self): + """ + Make sure that the created subdirectories are correctly removed when empty. + """ + self.cache.set("foo", "bar") + keyhash = md5.new("foo").hexdigest() + keypath = os.path.join(self.dirname, keyhash[:2], keyhash[2:4], keyhash[4:]) + self.assert_(os.path.exists(keypath)) + + self.cache.delete("foo") + self.assert_(not os.path.exists(keypath)) + self.assert_(not os.path.exists(os.path.dirname(keypath))) + self.assert_(not os.path.exists(os.path.dirname(os.path.dirname(keypath)))) class CacheUtils(unittest.TestCase): """TestCase for django.utils.cache functions.""" diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py index bfa03cd6e1..668ecb9d5a 100644 --- a/tests/regressiontests/defaultfilters/tests.py +++ b/tests/regressiontests/defaultfilters/tests.py @@ -49,6 +49,18 @@ u'\\\\ : backslashes, too' >>> capfirst(u'hello world') u'Hello world' +>>> escapejs(u'"double quotes" and \'single quotes\'') +u'\\"double quotes\\" and \\\'single quotes\\\'' + +>>> escapejs(ur'\ : backslashes, too') +u'\\\\ : backslashes, too' + +>>> escapejs(u'and lots of whitespace: \r\n\t\v\f\b') +u'and lots of whitespace: \\r\\n\\t\\v\\f\\b' + +>>> escapejs(ur'<script>and this</script>') +u'<script>and this<\\/script>' + >>> fix_ampersands(u'Jack & Jill & Jeroboam') u'Jack & Jill & Jeroboam' diff --git a/tests/regressiontests/forms/localflavor/cl.py b/tests/regressiontests/forms/localflavor/cl.py index 407f6610e4..23e7a41902 100644 --- a/tests/regressiontests/forms/localflavor/cl.py +++ b/tests/regressiontests/forms/localflavor/cl.py @@ -41,7 +41,7 @@ Strict RUT usage (does not allow imposible values) >>> rut.clean('11-6') Traceback (most recent call last): ... -ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.'] +ValidationError: [u'Enter a valid Chilean RUT. The format is XX.XXX.XXX-X.'] # valid format, bad verifier. >>> rut.clean('11.111.111-0') @@ -53,17 +53,17 @@ ValidationError: [u'The Chilean RUT is not valid.'] >>> rut.clean('767484100') Traceback (most recent call last): ... -ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.'] +ValidationError: [u'Enter a valid Chilean RUT. The format is XX.XXX.XXX-X.'] >>> rut.clean('78.412.790-7') u'78.412.790-7' >>> rut.clean('8.334.6043') Traceback (most recent call last): ... -ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.'] +ValidationError: [u'Enter a valid Chilean RUT. The format is XX.XXX.XXX-X.'] >>> rut.clean('76793310-K') Traceback (most recent call last): ... -ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.'] +ValidationError: [u'Enter a valid Chilean RUT. The format is XX.XXX.XXX-X.'] ## CLRegionSelect ######################################################### >>> from django.contrib.localflavor.cl.forms import CLRegionSelect diff --git a/tests/regressiontests/forms/localflavor/uk.py b/tests/regressiontests/forms/localflavor/uk.py index d7848f70a8..258c22e5a9 100644 --- a/tests/regressiontests/forms/localflavor/uk.py +++ b/tests/regressiontests/forms/localflavor/uk.py @@ -12,13 +12,15 @@ u'BT32 4PX' >>> f.clean('GIR 0AA') u'GIR 0AA' >>> f.clean('BT324PX') +u'BT32 4PX' +>>> f.clean('1NV 4L1D') Traceback (most recent call last): ... -ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.'] ->>> f.clean('1NV 4L1D') +ValidationError: [u'Enter a valid postcode.'] +>>> f.clean('1NV4L1D') Traceback (most recent call last): ... -ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.'] +ValidationError: [u'Enter a valid postcode.'] >>> f.clean(None) Traceback (most recent call last): ... @@ -27,7 +29,20 @@ ValidationError: [u'This field is required.'] Traceback (most recent call last): ... ValidationError: [u'This field is required.'] - +>>> f.clean(' so11aa ') +u'SO1 1AA' +>>> f.clean(' so1 1aa ') +u'SO1 1AA' +>>> f.clean('G2 3wt') +u'G2 3WT' +>>> f.clean('EC1A 1BB') +u'EC1A 1BB' +>>> f.clean('Ec1a1BB') +u'EC1A 1BB' +>>> f.clean(' b0gUS') +Traceback (most recent call last): +... +ValidationError: [u'Enter a valid postcode.'] >>> f = UKPostcodeField(required=False) >>> f.clean('BT32 4PX') u'BT32 4PX' @@ -36,11 +51,9 @@ u'GIR 0AA' >>> f.clean('1NV 4L1D') Traceback (most recent call last): ... -ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.'] +ValidationError: [u'Enter a valid postcode.'] >>> f.clean('BT324PX') -Traceback (most recent call last): -... -ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.'] +u'BT32 4PX' >>> f.clean(None) u'' >>> f.clean('') diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py index 5cfae029bb..31b956a99d 100644 --- a/tests/regressiontests/httpwrappers/tests.py +++ b/tests/regressiontests/httpwrappers/tests.py @@ -391,9 +391,45 @@ u'\ufffd' >>> q.getlist('foo') [u'bar', u'\ufffd'] + +###################################### +# HttpResponse with Unicode headers # +###################################### + +>>> r = HttpResponse() + +If we insert a unicode value it will be converted to an ascii +string. This makes sure we comply with the HTTP specifications. + +>>> r['value'] = u'test value' +>>> isinstance(r['value'], str) +True + +An error is raised When a unicode object with non-ascii is assigned. + +>>> r['value'] = u't\xebst value' # doctest:+ELLIPSIS +Traceback (most recent call last): +... +UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format + +The response also converts unicode keys to strings. + +>>> r[u'test'] = 'testing key' +>>> l = list(r.items()) +>>> l.sort() +>>> l[1] +('test', 'testing key') + +It will also raise errors for keys with non-ascii data. + +>>> r[u't\xebst'] = 'testing key' # doctest:+ELLIPSIS +Traceback (most recent call last): +... +UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format + """ -from django.http import QueryDict +from django.http import QueryDict, HttpResponse if __name__ == "__main__": import doctest diff --git a/tests/regressiontests/maxlength/tests.py b/tests/regressiontests/maxlength/tests.py index 8a5f874c78..c7ed1f91c0 100644 --- a/tests/regressiontests/maxlength/tests.py +++ b/tests/regressiontests/maxlength/tests.py @@ -22,12 +22,12 @@ Don't print out the deprecation warnings during testing. >>> legacy_maxlength(10, 12) Traceback (most recent call last): ... -TypeError: field can not take both the max_length argument and the legacy maxlength argument. +TypeError: Field cannot take both the max_length argument and the legacy maxlength argument. >>> legacy_maxlength(0, 10) Traceback (most recent call last): ... -TypeError: field can not take both the max_length argument and the legacy maxlength argument. +TypeError: Field cannot take both the max_length argument and the legacy maxlength argument. >>> legacy_maxlength(0, None) 0 @@ -48,7 +48,7 @@ TypeError: field can not take both the max_length argument and the legacy maxlen >>> fields.Field(maxlength=10, max_length=15) Traceback (most recent call last): ... -TypeError: field can not take both the max_length argument and the legacy maxlength argument. +TypeError: Field cannot take both the max_length argument and the legacy maxlength argument. # Test max_length >>> new.max_length diff --git a/tests/regressiontests/model_regress/models.py b/tests/regressiontests/model_regress/models.py index 00c3bc96f0..02e73a5aa9 100644 --- a/tests/regressiontests/model_regress/models.py +++ b/tests/regressiontests/model_regress/models.py @@ -11,6 +11,7 @@ class Article(models.Model): pub_date = models.DateTimeField() status = models.IntegerField(blank=True, null=True, choices=CHOICES) misc_data = models.CharField(max_length=100, blank=True) + article_text = models.TextField() class Meta: ordering = ('pub_date','headline') @@ -41,5 +42,14 @@ Empty strings should be returned as Unicode >>> a2 = Article.objects.get(pk=a.id) >>> a2.misc_data u'' + +# TextFields can hold more than 4000 characters (this was broken in Oracle). +>>> a3 = Article(headline="Really, really big", pub_date=datetime.now()) +>>> a3.article_text = "ABCDE" * 1000 +>>> a3.save() +>>> a4 = Article.objects.get(pk=a3.id) +>>> len(a4.article_text) +5000 + """ } diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py index 4175bdbe5f..f38b2cdef1 100644 --- a/tests/regressiontests/templates/filters.py +++ b/tests/regressiontests/templates/filters.py @@ -108,8 +108,8 @@ def get_filter_tests(): 'filter-urlize05': ('{% autoescape off %}{{ a|urlize }}{% endautoescape %}', {"a": "<script>alert('foo')</script>"}, "<script>alert('foo')</script>"), 'filter-urlize06': ('{{ a|urlize }}', {"a": "<script>alert('foo')</script>"}, '<script>alert('foo')</script>'), - 'filter-urlizetrunc01': ('{% autoescape off %}{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}{% endautoescape %}', {"a": "http://example.com/x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'<a href="http://example.com/x=&y=" rel="nofollow">http:...</a> <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'), - 'filter-urlizetrunc02': ('{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}', {"a": "http://example.com/x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'<a href="http://example.com/x=&y=" rel="nofollow">http:...</a> <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'), + 'filter-urlizetrunc01': ('{% autoescape off %}{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}{% endautoescape %}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('"Safe" http://example.com?x=&y=')}, u'"Unsafe" <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> "Safe" <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'), + 'filter-urlizetrunc02': ('{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('"Safe" http://example.com?x=&y=')}, u'"Unsafe" <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> "Safe" <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'), 'filter-wordcount01': ('{% autoescape off %}{{ a|wordcount }} {{ b|wordcount }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a & b")}, "3 3"), 'filter-wordcount02': ('{{ a|wordcount }} {{ b|wordcount }}', {"a": "a & b", "b": mark_safe("a & b")}, "3 3"), diff --git a/tests/regressiontests/views/media/file.unknown b/tests/regressiontests/views/media/file.unknown new file mode 100644 index 0000000000..77dcda8970 --- /dev/null +++ b/tests/regressiontests/views/media/file.unknown @@ -0,0 +1 @@ +An unknown file extension. diff --git a/tests/regressiontests/views/tests/static.py b/tests/regressiontests/views/tests/static.py index c731b249e8..d7e87d19d2 100644 --- a/tests/regressiontests/views/tests/static.py +++ b/tests/regressiontests/views/tests/static.py @@ -13,11 +13,15 @@ class StaticTests(TestCase): response = self.client.get('/views/site_media/%s' % filename) file = open(path.join(media_dir, filename)) self.assertEquals(file.read(), response.content) + self.assertEquals(len(response.content), int(response['Content-Length'])) + + def test_unknown_mime_type(self): + response = self.client.get('/views/site_media/file.unknown') + self.assertEquals('application/octet-stream', response['Content-Type']) def test_copes_with_empty_path_component(self): file_name = 'file.txt' response = self.client.get('/views/site_media//%s' % file_name) file = open(path.join(media_dir, file_name)) self.assertEquals(file.read(), response.content) - - + diff --git a/tests/runtests.py b/tests/runtests.py index 2d3b737cec..599916ab23 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -93,6 +93,7 @@ def django_tests(verbosity, interactive, test_labels): old_root_urlconf = settings.ROOT_URLCONF old_template_dirs = settings.TEMPLATE_DIRS old_use_i18n = settings.USE_I18N + old_login_url = settings.LOGIN_URL old_language_code = settings.LANGUAGE_CODE old_middleware_classes = settings.MIDDLEWARE_CLASSES @@ -102,6 +103,7 @@ def django_tests(verbosity, interactive, test_labels): settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), TEST_TEMPLATE_DIR),) settings.USE_I18N = True settings.LANGUAGE_CODE = 'en' + settings.LOGIN_URL = '/accounts/login/' settings.MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -153,6 +155,7 @@ def django_tests(verbosity, interactive, test_labels): settings.TEMPLATE_DIRS = old_template_dirs settings.USE_I18N = old_use_i18n settings.LANGUAGE_CODE = old_language_code + settings.LOGIN_URL = old_login_url settings.MIDDLEWARE_CLASSES = old_middleware_classes if __name__ == "__main__": |
