Ticket #15111: site_not_installed.diff

File site_not_installed.diff, 6.7 KB (added by Waldemar Kornewald, 14 years ago)

patch against r15239

  • django/contrib/auth/tests/views.py

    diff -r d4e8cb5b1a72 django/contrib/auth/tests/views.py
    a b  
    55from django.conf import settings
    66from django.contrib.auth import SESSION_KEY, REDIRECT_FIELD_NAME
    77from django.contrib.auth.forms import AuthenticationForm
    8 from django.contrib.sites.models import Site
     8from django.contrib.sites.models import Site, RequestSite
    99from django.contrib.auth.models import User
    1010from django.test import TestCase
    1111from django.core import mail
     
    192192    def test_current_site_in_context_after_login(self):
    193193        response = self.client.get(reverse('django.contrib.auth.views.login'))
    194194        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)
    198201        self.assert_(isinstance(response.context['form'], AuthenticationForm),
    199202                     'Login form is not an AuthenticationForm')
    200203
  • django/contrib/contenttypes/tests.py

    diff -r d4e8cb5b1a72 django/contrib/contenttypes/tests.py
    a b  
    6161        from django.contrib.auth.models import User
    6262        user_ct = ContentType.objects.get_for_model(User)
    6363        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
    6769        Site._meta.installed = False
    6870        response = shortcut(request, user_ct.id, obj.id)
    6971        self.assertEqual("http://Example.com/users/john/", response._headers.get("location")[1])
  • django/contrib/sitemaps/tests/basic.py

    diff -r d4e8cb5b1a72 django/contrib/sitemaps/tests/basic.py
    a b  
    1515    urls = 'django.contrib.sitemaps.tests.urls'
    1616
    1717    def setUp(self):
     18        if Site._meta.installed:
     19            self.base_url = 'http://example.com'
     20        else:
     21            self.base_url = 'http://testserver'
    1822        self.old_USE_L10N = settings.USE_L10N
    1923        self.old_Site_meta_installed = Site._meta.installed
    2024        self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
     
    3640        # Check for all the important bits:
    3741        self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
    3842<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>
    4044</sitemapindex>
    41 """)
     45""" % self.base_url)
    4246
    4347    def test_simple_sitemap_custom_index(self):
    4448        "A simple sitemap index can be rendered with a custom template"
     
    4852        self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
    4953<!-- This is a customised template -->
    5054<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>
    5256</sitemapindex>
    53 """)
     57""" % self.base_url)
    5458
    5559    def test_simple_sitemap(self):
    5660        "A simple sitemap can be rendered"
     
    5963        # Check for all the important bits:
    6064        self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
    6165<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>
    6367</urlset>
    64 """ % date.today().strftime('%Y-%m-%d'))
     68""" % (self.base_url, date.today().strftime('%Y-%m-%d')))
    6569
    6670    def test_simple_custom_sitemap(self):
    6771        "A simple sitemap can be rendered with a custom template"
     
    7175        self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
    7276<!-- This is a customised template -->
    7377<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>
    7579</urlset>
    76 """ % date.today().strftime('%Y-%m-%d'))
     80""" % (self.base_url, date.today().strftime('%Y-%m-%d')))
    7781
    7882    @skipUnless(settings.USE_I18N, "Internationalization is not enabled")
    7983    def test_localized_priority(self):
     
    97101
    98102        expected = ''
    99103        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)
    101105        # Check for all the important bits:
    102106        self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
    103107<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
     
    131135        private.sites.add(settings.SITE_ID)
    132136        response = self.client.get('/flatpages/sitemap.xml')
    133137        # 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))
    135139        # 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))
    137141
    138142    def test_requestsite_sitemap(self):
    139143        # Make sure hitting the flatpages sitemap without the sites framework
     
    163167        Sitemap.get_urls if Site objects exists, but the sites framework is not
    164168        actually installed.
    165169        """
    166         Site.objects.get_current()
    167170        Site._meta.installed = False
    168171        self.assertRaises(ImproperlyConfigured, Sitemap().get_urls)
Back to Top