[py3] Compared response.content with bytes.
This commit is contained in:
parent
d1452f6097
commit
faf570df18
|
@ -1,3 +1,5 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
|
||||||
|
@ -12,7 +14,7 @@ class GenericViewsSitemapTests(SitemapTestsBase):
|
||||||
expected = ''
|
expected = ''
|
||||||
for username in User.objects.values_list("username", flat=True):
|
for username in User.objects.values_list("username", flat=True):
|
||||||
expected += "<url><loc>%s/users/%s/</loc></url>" % (self.base_url, username)
|
expected += "<url><loc>%s/users/%s/</loc></url>" % (self.base_url, username)
|
||||||
self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
%s
|
%s
|
||||||
</urlset>
|
</urlset>
|
||||||
|
|
|
@ -21,7 +21,7 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
def test_simple_sitemap_index(self):
|
def test_simple_sitemap_index(self):
|
||||||
"A simple sitemap index can be rendered"
|
"A simple sitemap index can be rendered"
|
||||||
response = self.client.get('/simple/index.xml')
|
response = self.client.get('/simple/index.xml')
|
||||||
self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
|
@ -33,7 +33,7 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
def test_simple_sitemap_custom_index(self):
|
def test_simple_sitemap_custom_index(self):
|
||||||
"A simple sitemap index can be rendered with a custom template"
|
"A simple sitemap index can be rendered with a custom template"
|
||||||
response = self.client.get('/simple/custom-index.xml')
|
response = self.client.get('/simple/custom-index.xml')
|
||||||
self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- This is a customised template -->
|
<!-- This is a customised template -->
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
||||||
|
@ -43,7 +43,7 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
def test_simple_sitemap_section(self):
|
def test_simple_sitemap_section(self):
|
||||||
"A simple sitemap section can be rendered"
|
"A simple sitemap section can be rendered"
|
||||||
response = self.client.get('/simple/sitemap-simple.xml')
|
response = self.client.get('/simple/sitemap-simple.xml')
|
||||||
self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
||||||
</urlset>
|
</urlset>
|
||||||
|
@ -52,7 +52,7 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
def test_simple_sitemap(self):
|
def test_simple_sitemap(self):
|
||||||
"A simple sitemap can be rendered"
|
"A simple sitemap can be rendered"
|
||||||
response = self.client.get('/simple/sitemap.xml')
|
response = self.client.get('/simple/sitemap.xml')
|
||||||
self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
||||||
</urlset>
|
</urlset>
|
||||||
|
@ -64,7 +64,7 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
def test_simple_custom_sitemap(self):
|
def test_simple_custom_sitemap(self):
|
||||||
"A simple sitemap can be rendered with a custom template"
|
"A simple sitemap can be rendered with a custom template"
|
||||||
response = self.client.get('/simple/custom-sitemap.xml')
|
response = self.client.get('/simple/custom-sitemap.xml')
|
||||||
self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- This is a customised template -->
|
<!-- This is a customised template -->
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
||||||
|
@ -90,7 +90,7 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
# installed doesn't raise an exception
|
# installed doesn't raise an exception
|
||||||
Site._meta.installed = False
|
Site._meta.installed = False
|
||||||
response = self.client.get('/simple/sitemap.xml')
|
response = self.client.get('/simple/sitemap.xml')
|
||||||
self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<url><loc>http://testserver/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
<url><loc>http://testserver/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
||||||
</urlset>
|
</urlset>
|
||||||
|
@ -131,7 +131,7 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
Check that a cached sitemap index can be rendered (#2713).
|
Check that a cached sitemap index can be rendered (#2713).
|
||||||
"""
|
"""
|
||||||
response = self.client.get('/cached/index.xml')
|
response = self.client.get('/cached/index.xml')
|
||||||
self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<sitemap><loc>%s/cached/sitemap-simple.xml</loc></sitemap>
|
<sitemap><loc>%s/cached/sitemap-simple.xml</loc></sitemap>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
@ -11,7 +13,7 @@ class HTTPSSitemapTests(SitemapTestsBase):
|
||||||
def test_secure_sitemap_index(self):
|
def test_secure_sitemap_index(self):
|
||||||
"A secure sitemap index can be rendered"
|
"A secure sitemap index can be rendered"
|
||||||
response = self.client.get('/secure/index.xml')
|
response = self.client.get('/secure/index.xml')
|
||||||
self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<sitemap><loc>%s/secure/sitemap-simple.xml</loc></sitemap>
|
<sitemap><loc>%s/secure/sitemap-simple.xml</loc></sitemap>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
|
@ -20,7 +22,7 @@ class HTTPSSitemapTests(SitemapTestsBase):
|
||||||
def test_secure_sitemap_section(self):
|
def test_secure_sitemap_section(self):
|
||||||
"A secure sitemap section can be rendered"
|
"A secure sitemap section can be rendered"
|
||||||
response = self.client.get('/secure/sitemap-simple.xml')
|
response = self.client.get('/secure/sitemap-simple.xml')
|
||||||
self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
||||||
</urlset>
|
</urlset>
|
||||||
|
@ -34,7 +36,7 @@ class HTTPSDetectionSitemapTests(SitemapTestsBase):
|
||||||
def test_sitemap_index_with_https_request(self):
|
def test_sitemap_index_with_https_request(self):
|
||||||
"A sitemap index requested in HTTPS is rendered with HTTPS links"
|
"A sitemap index requested in HTTPS is rendered with HTTPS links"
|
||||||
response = self.client.get('/simple/index.xml', **self.extra)
|
response = self.client.get('/simple/index.xml', **self.extra)
|
||||||
self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
|
@ -43,7 +45,7 @@ class HTTPSDetectionSitemapTests(SitemapTestsBase):
|
||||||
def test_sitemap_section_with_https_request(self):
|
def test_sitemap_section_with_https_request(self):
|
||||||
"A sitemap section requested in HTTPS is rendered with HTTPS links"
|
"A sitemap section requested in HTTPS is rendered with HTTPS links"
|
||||||
response = self.client.get('/simple/sitemap-simple.xml', **self.extra)
|
response = self.client.get('/simple/sitemap-simple.xml', **self.extra)
|
||||||
self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEqual(response.content, b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
|
||||||
</urlset>
|
</urlset>
|
||||||
|
|
|
@ -91,7 +91,7 @@ class ClientTest(TestCase):
|
||||||
content_type="text/xml")
|
content_type="text/xml")
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.templates[0].name, "Book template")
|
self.assertEqual(response.templates[0].name, "Book template")
|
||||||
self.assertEqual(response.content, "Blink - Malcolm Gladwell")
|
self.assertEqual(response.content, b"Blink - Malcolm Gladwell")
|
||||||
|
|
||||||
def test_redirect(self):
|
def test_redirect(self):
|
||||||
"GET a URL that redirects elsewhere"
|
"GET a URL that redirects elsewhere"
|
||||||
|
|
|
@ -787,7 +787,7 @@ class CustomModelAdminTest(AdminViewBasicTest):
|
||||||
def testCustomAdminSiteView(self):
|
def testCustomAdminSiteView(self):
|
||||||
self.client.login(username='super', password='secret')
|
self.client.login(username='super', password='secret')
|
||||||
response = self.client.get('/test_admin/%s/my_view/' % self.urlbit)
|
response = self.client.get('/test_admin/%s/my_view/' % self.urlbit)
|
||||||
self.assertEqual(response.content, "Django is a magical pony!")
|
self.assertEqual(response.content, b"Django is a magical pony!")
|
||||||
|
|
||||||
def get_perm(Model, perm):
|
def get_perm(Model, perm):
|
||||||
"""Return the permission object, for the Model"""
|
"""Return the permission object, for the Model"""
|
||||||
|
|
|
@ -1592,43 +1592,43 @@ class CacheMiddlewareTest(TestCase):
|
||||||
|
|
||||||
# Request the view once
|
# Request the view once
|
||||||
response = default_view(request, '1')
|
response = default_view(request, '1')
|
||||||
self.assertEqual(response.content, 'Hello World 1')
|
self.assertEqual(response.content, b'Hello World 1')
|
||||||
|
|
||||||
# Request again -- hit the cache
|
# Request again -- hit the cache
|
||||||
response = default_view(request, '2')
|
response = default_view(request, '2')
|
||||||
self.assertEqual(response.content, 'Hello World 1')
|
self.assertEqual(response.content, b'Hello World 1')
|
||||||
|
|
||||||
# Requesting the same view with the explicit cache should yield the same result
|
# Requesting the same view with the explicit cache should yield the same result
|
||||||
response = explicit_default_view(request, '3')
|
response = explicit_default_view(request, '3')
|
||||||
self.assertEqual(response.content, 'Hello World 1')
|
self.assertEqual(response.content, b'Hello World 1')
|
||||||
|
|
||||||
# Requesting with a prefix will hit a different cache key
|
# Requesting with a prefix will hit a different cache key
|
||||||
response = explicit_default_with_prefix_view(request, '4')
|
response = explicit_default_with_prefix_view(request, '4')
|
||||||
self.assertEqual(response.content, 'Hello World 4')
|
self.assertEqual(response.content, b'Hello World 4')
|
||||||
|
|
||||||
# Hitting the same view again gives a cache hit
|
# Hitting the same view again gives a cache hit
|
||||||
response = explicit_default_with_prefix_view(request, '5')
|
response = explicit_default_with_prefix_view(request, '5')
|
||||||
self.assertEqual(response.content, 'Hello World 4')
|
self.assertEqual(response.content, b'Hello World 4')
|
||||||
|
|
||||||
# And going back to the implicit cache will hit the same cache
|
# And going back to the implicit cache will hit the same cache
|
||||||
response = default_with_prefix_view(request, '6')
|
response = default_with_prefix_view(request, '6')
|
||||||
self.assertEqual(response.content, 'Hello World 4')
|
self.assertEqual(response.content, b'Hello World 4')
|
||||||
|
|
||||||
# Requesting from an alternate cache won't hit cache
|
# Requesting from an alternate cache won't hit cache
|
||||||
response = other_view(request, '7')
|
response = other_view(request, '7')
|
||||||
self.assertEqual(response.content, 'Hello World 7')
|
self.assertEqual(response.content, b'Hello World 7')
|
||||||
|
|
||||||
# But a repeated hit will hit cache
|
# But a repeated hit will hit cache
|
||||||
response = other_view(request, '8')
|
response = other_view(request, '8')
|
||||||
self.assertEqual(response.content, 'Hello World 7')
|
self.assertEqual(response.content, b'Hello World 7')
|
||||||
|
|
||||||
# And prefixing the alternate cache yields yet another cache entry
|
# And prefixing the alternate cache yields yet another cache entry
|
||||||
response = other_with_prefix_view(request, '9')
|
response = other_with_prefix_view(request, '9')
|
||||||
self.assertEqual(response.content, 'Hello World 9')
|
self.assertEqual(response.content, b'Hello World 9')
|
||||||
|
|
||||||
# Request from the alternate cache with a new prefix and a custom timeout
|
# Request from the alternate cache with a new prefix and a custom timeout
|
||||||
response = other_with_timeout_view(request, '10')
|
response = other_with_timeout_view(request, '10')
|
||||||
self.assertEqual(response.content, 'Hello World 10')
|
self.assertEqual(response.content, b'Hello World 10')
|
||||||
|
|
||||||
# But if we wait a couple of seconds...
|
# But if we wait a couple of seconds...
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
@ -1636,38 +1636,38 @@ class CacheMiddlewareTest(TestCase):
|
||||||
# ... the default cache will still hit
|
# ... the default cache will still hit
|
||||||
cache = get_cache('default')
|
cache = get_cache('default')
|
||||||
response = default_view(request, '11')
|
response = default_view(request, '11')
|
||||||
self.assertEqual(response.content, 'Hello World 1')
|
self.assertEqual(response.content, b'Hello World 1')
|
||||||
|
|
||||||
# ... the default cache with a prefix will still hit
|
# ... the default cache with a prefix will still hit
|
||||||
response = default_with_prefix_view(request, '12')
|
response = default_with_prefix_view(request, '12')
|
||||||
self.assertEqual(response.content, 'Hello World 4')
|
self.assertEqual(response.content, b'Hello World 4')
|
||||||
|
|
||||||
# ... the explicit default cache will still hit
|
# ... the explicit default cache will still hit
|
||||||
response = explicit_default_view(request, '13')
|
response = explicit_default_view(request, '13')
|
||||||
self.assertEqual(response.content, 'Hello World 1')
|
self.assertEqual(response.content, b'Hello World 1')
|
||||||
|
|
||||||
# ... the explicit default cache with a prefix will still hit
|
# ... the explicit default cache with a prefix will still hit
|
||||||
response = explicit_default_with_prefix_view(request, '14')
|
response = explicit_default_with_prefix_view(request, '14')
|
||||||
self.assertEqual(response.content, 'Hello World 4')
|
self.assertEqual(response.content, b'Hello World 4')
|
||||||
|
|
||||||
# .. but a rapidly expiring cache won't hit
|
# .. but a rapidly expiring cache won't hit
|
||||||
response = other_view(request, '15')
|
response = other_view(request, '15')
|
||||||
self.assertEqual(response.content, 'Hello World 15')
|
self.assertEqual(response.content, b'Hello World 15')
|
||||||
|
|
||||||
# .. even if it has a prefix
|
# .. even if it has a prefix
|
||||||
response = other_with_prefix_view(request, '16')
|
response = other_with_prefix_view(request, '16')
|
||||||
self.assertEqual(response.content, 'Hello World 16')
|
self.assertEqual(response.content, b'Hello World 16')
|
||||||
|
|
||||||
# ... but a view with a custom timeout will still hit
|
# ... but a view with a custom timeout will still hit
|
||||||
response = other_with_timeout_view(request, '17')
|
response = other_with_timeout_view(request, '17')
|
||||||
self.assertEqual(response.content, 'Hello World 10')
|
self.assertEqual(response.content, b'Hello World 10')
|
||||||
|
|
||||||
# And if we wait a few more seconds
|
# And if we wait a few more seconds
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
# the custom timeouot cache will miss
|
# the custom timeouot cache will miss
|
||||||
response = other_with_timeout_view(request, '18')
|
response = other_with_timeout_view(request, '18')
|
||||||
self.assertEqual(response.content, 'Hello World 18')
|
self.assertEqual(response.content, b'Hello World 18')
|
||||||
|
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
@ -28,7 +30,7 @@ class ConditionalGet(TestCase):
|
||||||
|
|
||||||
def assertNotModified(self, response):
|
def assertNotModified(self, response):
|
||||||
self.assertEqual(response.status_code, 304)
|
self.assertEqual(response.status_code, 304)
|
||||||
self.assertEqual(response.content, '')
|
self.assertEqual(response.content, b'')
|
||||||
|
|
||||||
def testWithoutConditions(self):
|
def testWithoutConditions(self):
|
||||||
response = self.client.get('/condition/')
|
response = self.client.get('/condition/')
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
import time
|
import time
|
||||||
|
@ -29,16 +31,16 @@ class SimpleTemplateResponseTest(TestCase):
|
||||||
def test_template_resolving(self):
|
def test_template_resolving(self):
|
||||||
response = SimpleTemplateResponse('first/test.html')
|
response = SimpleTemplateResponse('first/test.html')
|
||||||
response.render()
|
response.render()
|
||||||
self.assertEqual('First template\n', response.content)
|
self.assertEqual(response.content, b'First template\n')
|
||||||
|
|
||||||
templates = ['foo.html', 'second/test.html', 'first/test.html']
|
templates = ['foo.html', 'second/test.html', 'first/test.html']
|
||||||
response = SimpleTemplateResponse(templates)
|
response = SimpleTemplateResponse(templates)
|
||||||
response.render()
|
response.render()
|
||||||
self.assertEqual('Second template\n', response.content)
|
self.assertEqual(response.content, b'Second template\n')
|
||||||
|
|
||||||
response = self._response()
|
response = self._response()
|
||||||
response.render()
|
response.render()
|
||||||
self.assertEqual(response.content, 'foo')
|
self.assertEqual(response.content, b'foo')
|
||||||
|
|
||||||
def test_explicit_baking(self):
|
def test_explicit_baking(self):
|
||||||
# explicit baking
|
# explicit baking
|
||||||
|
@ -50,17 +52,17 @@ class SimpleTemplateResponseTest(TestCase):
|
||||||
def test_render(self):
|
def test_render(self):
|
||||||
# response is not re-rendered without the render call
|
# response is not re-rendered without the render call
|
||||||
response = self._response().render()
|
response = self._response().render()
|
||||||
self.assertEqual(response.content, 'foo')
|
self.assertEqual(response.content, b'foo')
|
||||||
|
|
||||||
# rebaking doesn't change the rendered content
|
# rebaking doesn't change the rendered content
|
||||||
response.template_name = Template('bar{{ baz }}')
|
response.template_name = Template('bar{{ baz }}')
|
||||||
response.render()
|
response.render()
|
||||||
self.assertEqual(response.content, 'foo')
|
self.assertEqual(response.content, b'foo')
|
||||||
|
|
||||||
# but rendered content can be overridden by manually
|
# but rendered content can be overridden by manually
|
||||||
# setting content
|
# setting content
|
||||||
response.content = 'bar'
|
response.content = 'bar'
|
||||||
self.assertEqual(response.content, 'bar')
|
self.assertEqual(response.content, b'bar')
|
||||||
|
|
||||||
def test_iteration_unrendered(self):
|
def test_iteration_unrendered(self):
|
||||||
# unrendered response raises an exception on iteration
|
# unrendered response raises an exception on iteration
|
||||||
|
@ -77,7 +79,7 @@ class SimpleTemplateResponseTest(TestCase):
|
||||||
# iteration works for rendered responses
|
# iteration works for rendered responses
|
||||||
response = self._response().render()
|
response = self._response().render()
|
||||||
res = [x for x in response]
|
res = [x for x in response]
|
||||||
self.assertEqual(res, ['foo'])
|
self.assertEqual(res, [b'foo'])
|
||||||
|
|
||||||
def test_content_access_unrendered(self):
|
def test_content_access_unrendered(self):
|
||||||
# unrendered response raises an exception when content is accessed
|
# unrendered response raises an exception when content is accessed
|
||||||
|
@ -89,7 +91,7 @@ class SimpleTemplateResponseTest(TestCase):
|
||||||
def test_content_access_rendered(self):
|
def test_content_access_rendered(self):
|
||||||
# rendered response content can be accessed
|
# rendered response content can be accessed
|
||||||
response = self._response().render()
|
response = self._response().render()
|
||||||
self.assertEqual(response.content, 'foo')
|
self.assertEqual(response.content, b'foo')
|
||||||
|
|
||||||
def test_set_content(self):
|
def test_set_content(self):
|
||||||
# content can be overriden
|
# content can be overriden
|
||||||
|
@ -97,23 +99,23 @@ class SimpleTemplateResponseTest(TestCase):
|
||||||
self.assertFalse(response.is_rendered)
|
self.assertFalse(response.is_rendered)
|
||||||
response.content = 'spam'
|
response.content = 'spam'
|
||||||
self.assertTrue(response.is_rendered)
|
self.assertTrue(response.is_rendered)
|
||||||
self.assertEqual(response.content, 'spam')
|
self.assertEqual(response.content, b'spam')
|
||||||
response.content = 'baz'
|
response.content = 'baz'
|
||||||
self.assertEqual(response.content, 'baz')
|
self.assertEqual(response.content, b'baz')
|
||||||
|
|
||||||
def test_dict_context(self):
|
def test_dict_context(self):
|
||||||
response = self._response('{{ foo }}{{ processors }}',
|
response = self._response('{{ foo }}{{ processors }}',
|
||||||
{'foo': 'bar'})
|
{'foo': 'bar'})
|
||||||
self.assertEqual(response.context_data, {'foo': 'bar'})
|
self.assertEqual(response.context_data, {'foo': 'bar'})
|
||||||
response.render()
|
response.render()
|
||||||
self.assertEqual(response.content, 'bar')
|
self.assertEqual(response.content, b'bar')
|
||||||
|
|
||||||
def test_context_instance(self):
|
def test_context_instance(self):
|
||||||
response = self._response('{{ foo }}{{ processors }}',
|
response = self._response('{{ foo }}{{ processors }}',
|
||||||
Context({'foo': 'bar'}))
|
Context({'foo': 'bar'}))
|
||||||
self.assertEqual(response.context_data.__class__, Context)
|
self.assertEqual(response.context_data.__class__, Context)
|
||||||
response.render()
|
response.render()
|
||||||
self.assertEqual(response.content, 'bar')
|
self.assertEqual(response.content, b'bar')
|
||||||
|
|
||||||
def test_kwargs(self):
|
def test_kwargs(self):
|
||||||
response = self._response(content_type = 'application/json', status=504)
|
response = self._response(content_type = 'application/json', status=504)
|
||||||
|
@ -140,7 +142,7 @@ class SimpleTemplateResponseTest(TestCase):
|
||||||
|
|
||||||
# When the content is rendered, all the callbacks are invoked, too.
|
# When the content is rendered, all the callbacks are invoked, too.
|
||||||
response.render()
|
response.render()
|
||||||
self.assertEqual('First template\n', response.content)
|
self.assertEqual(response.content, b'First template\n')
|
||||||
self.assertEqual(post, ['post1','post2'])
|
self.assertEqual(post, ['post1','post2'])
|
||||||
|
|
||||||
|
|
||||||
|
@ -202,17 +204,17 @@ class TemplateResponseTest(TestCase):
|
||||||
|
|
||||||
def test_render(self):
|
def test_render(self):
|
||||||
response = self._response('{{ foo }}{{ processors }}').render()
|
response = self._response('{{ foo }}{{ processors }}').render()
|
||||||
self.assertEqual(response.content, 'yes')
|
self.assertEqual(response.content, b'yes')
|
||||||
|
|
||||||
def test_render_with_requestcontext(self):
|
def test_render_with_requestcontext(self):
|
||||||
response = self._response('{{ foo }}{{ processors }}',
|
response = self._response('{{ foo }}{{ processors }}',
|
||||||
{'foo': 'bar'}).render()
|
{'foo': 'bar'}).render()
|
||||||
self.assertEqual(response.content, 'baryes')
|
self.assertEqual(response.content, b'baryes')
|
||||||
|
|
||||||
def test_render_with_context(self):
|
def test_render_with_context(self):
|
||||||
response = self._response('{{ foo }}{{ processors }}',
|
response = self._response('{{ foo }}{{ processors }}',
|
||||||
Context({'foo': 'bar'})).render()
|
Context({'foo': 'bar'})).render()
|
||||||
self.assertEqual(response.content, 'bar')
|
self.assertEqual(response.content, b'bar')
|
||||||
|
|
||||||
def test_kwargs(self):
|
def test_kwargs(self):
|
||||||
response = self._response(content_type = 'application/json',
|
response = self._response(content_type = 'application/json',
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Unit tests for reverse URL lookups.
|
Unit tests for reverse URL lookups.
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
|
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
|
||||||
|
@ -405,8 +405,8 @@ class RequestURLconfTests(TestCase):
|
||||||
def test_urlconf(self):
|
def test_urlconf(self):
|
||||||
response = self.client.get('/test/me/')
|
response = self.client.get('/test/me/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.content, 'outer:/test/me/,'
|
self.assertEqual(response.content, b'outer:/test/me/,'
|
||||||
'inner:/inner_urlconf/second_test/')
|
b'inner:/inner_urlconf/second_test/')
|
||||||
response = self.client.get('/inner_urlconf/second_test/')
|
response = self.client.get('/inner_urlconf/second_test/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
response = self.client.get('/second_test/')
|
response = self.client.get('/second_test/')
|
||||||
|
@ -422,7 +422,7 @@ class RequestURLconfTests(TestCase):
|
||||||
self.assertEqual(response.status_code, 404)
|
self.assertEqual(response.status_code, 404)
|
||||||
response = self.client.get('/second_test/')
|
response = self.client.get('/second_test/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.content, 'outer:,inner:/second_test/')
|
self.assertEqual(response.content, b'outer:,inner:/second_test/')
|
||||||
|
|
||||||
def test_urlconf_overridden_with_null(self):
|
def test_urlconf_overridden_with_null(self):
|
||||||
settings.MIDDLEWARE_CLASSES += (
|
settings.MIDDLEWARE_CLASSES += (
|
||||||
|
|
Loading…
Reference in New Issue