diff -r d4e8cb5b1a72 django/contrib/auth/tests/views.py
a
|
b
|
|
5 | 5 | from django.conf import settings |
6 | 6 | from django.contrib.auth import SESSION_KEY, REDIRECT_FIELD_NAME |
7 | 7 | from django.contrib.auth.forms import AuthenticationForm |
8 | | from django.contrib.sites.models import Site |
| 8 | from django.contrib.sites.models import Site, RequestSite |
9 | 9 | from django.contrib.auth.models import User |
10 | 10 | from django.test import TestCase |
11 | 11 | from django.core import mail |
… |
… |
|
192 | 192 | def test_current_site_in_context_after_login(self): |
193 | 193 | response = self.client.get(reverse('django.contrib.auth.views.login')) |
194 | 194 | self.assertEquals(response.status_code, 200) |
195 | | site = Site.objects.get_current() |
196 | | self.assertEquals(response.context['site'], site) |
197 | | self.assertEquals(response.context['site_name'], site.name) |
| 195 | if Site._meta.installed: |
| 196 | site = Site.objects.get_current() |
| 197 | self.assertEquals(response.context['site'], site) |
| 198 | self.assertEquals(response.context['site_name'], site.name) |
| 199 | else: |
| 200 | self.assertIsInstance(response.context['site'], RequestSite) |
198 | 201 | self.assert_(isinstance(response.context['form'], AuthenticationForm), |
199 | 202 | 'Login form is not an AuthenticationForm') |
200 | 203 | |
diff -r d4e8cb5b1a72 django/contrib/contenttypes/tests.py
a
|
b
|
|
61 | 61 | from django.contrib.auth.models import User |
62 | 62 | user_ct = ContentType.objects.get_for_model(User) |
63 | 63 | obj = User.objects.create(username="john") |
64 | | Site._meta.installed = True |
65 | | response = shortcut(request, user_ct.id, obj.id) |
66 | | self.assertEqual("http://example.com/users/john/", response._headers.get("location")[1]) |
| 64 | |
| 65 | if Site._meta.installed: |
| 66 | response = shortcut(request, user_ct.id, obj.id) |
| 67 | self.assertEqual("http://example.com/users/john/", response._headers.get("location")[1]) |
| 68 | |
67 | 69 | Site._meta.installed = False |
68 | 70 | response = shortcut(request, user_ct.id, obj.id) |
69 | 71 | self.assertEqual("http://Example.com/users/john/", response._headers.get("location")[1]) |
diff -r d4e8cb5b1a72 django/contrib/sitemaps/tests/basic.py
a
|
b
|
|
15 | 15 | urls = 'django.contrib.sitemaps.tests.urls' |
16 | 16 | |
17 | 17 | def setUp(self): |
| 18 | if Site._meta.installed: |
| 19 | self.base_url = 'http://example.com' |
| 20 | else: |
| 21 | self.base_url = 'http://testserver' |
18 | 22 | self.old_USE_L10N = settings.USE_L10N |
19 | 23 | self.old_Site_meta_installed = Site._meta.installed |
20 | 24 | self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS |
… |
… |
|
36 | 40 | # Check for all the important bits: |
37 | 41 | self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?> |
38 | 42 | <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
39 | | <sitemap><loc>http://example.com/simple/sitemap-simple.xml</loc></sitemap> |
| 43 | <sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap> |
40 | 44 | </sitemapindex> |
41 | | """) |
| 45 | """ % self.base_url) |
42 | 46 | |
43 | 47 | def test_simple_sitemap_custom_index(self): |
44 | 48 | "A simple sitemap index can be rendered with a custom template" |
… |
… |
|
48 | 52 | self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?> |
49 | 53 | <!-- This is a customised template --> |
50 | 54 | <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
51 | | <sitemap><loc>http://example.com/simple/sitemap-simple.xml</loc></sitemap> |
| 55 | <sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap> |
52 | 56 | </sitemapindex> |
53 | | """) |
| 57 | """ % self.base_url) |
54 | 58 | |
55 | 59 | def test_simple_sitemap(self): |
56 | 60 | "A simple sitemap can be rendered" |
… |
… |
|
59 | 63 | # Check for all the important bits: |
60 | 64 | self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?> |
61 | 65 | <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
62 | | <url><loc>http://example.com/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url> |
| 66 | <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url> |
63 | 67 | </urlset> |
64 | | """ % date.today().strftime('%Y-%m-%d')) |
| 68 | """ % (self.base_url, date.today().strftime('%Y-%m-%d'))) |
65 | 69 | |
66 | 70 | def test_simple_custom_sitemap(self): |
67 | 71 | "A simple sitemap can be rendered with a custom template" |
… |
… |
|
71 | 75 | self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?> |
72 | 76 | <!-- This is a customised template --> |
73 | 77 | <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
74 | | <url><loc>http://example.com/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url> |
| 78 | <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url> |
75 | 79 | </urlset> |
76 | | """ % date.today().strftime('%Y-%m-%d')) |
| 80 | """ % (self.base_url, date.today().strftime('%Y-%m-%d'))) |
77 | 81 | |
78 | 82 | @skipUnless(settings.USE_I18N, "Internationalization is not enabled") |
79 | 83 | def test_localized_priority(self): |
… |
… |
|
97 | 101 | |
98 | 102 | expected = '' |
99 | 103 | for username in User.objects.values_list("username", flat=True): |
100 | | expected += "<url><loc>http://example.com/users/%s/</loc></url>" %username |
| 104 | expected += "<url><loc>%s/users/%s/</loc></url>" % (self.base_url, username) |
101 | 105 | # Check for all the important bits: |
102 | 106 | self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?> |
103 | 107 | <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
… |
… |
|
131 | 135 | private.sites.add(settings.SITE_ID) |
132 | 136 | response = self.client.get('/flatpages/sitemap.xml') |
133 | 137 | # Public flatpage should be in the sitemap |
134 | | self.assertContains(response, '<loc>http://example.com%s</loc>' % public.url) |
| 138 | self.assertContains(response, '<loc>%s%s</loc>' % (self.base_url, public.url)) |
135 | 139 | # Private flatpage should not be in the sitemap |
136 | | self.assertNotContains(response, '<loc>http://example.com%s</loc>' % private.url) |
| 140 | self.assertNotContains(response, '<loc>%s%s</loc>' % (self.base_url, private.url)) |
137 | 141 | |
138 | 142 | def test_requestsite_sitemap(self): |
139 | 143 | # Make sure hitting the flatpages sitemap without the sites framework |
… |
… |
|
163 | 167 | Sitemap.get_urls if Site objects exists, but the sites framework is not |
164 | 168 | actually installed. |
165 | 169 | """ |
166 | | Site.objects.get_current() |
167 | 170 | Site._meta.installed = False |
168 | 171 | self.assertRaises(ImproperlyConfigured, Sitemap().get_urls) |