def test_canonical_page_diff(self):
        from pages.urls import slugify
        from pages.views import PageCompareView

        #####################################################
        # Page diff on custom domain
        #####################################################

        request = self.factory.get('/Parks/_history/2...1')
        request.user = self.user
        request.META['HTTP_HOST'] = self.sf.regionsettings.domain

        with self.mock_hosts_middleware(request):
            view = slugify(PageCompareView.as_view())
            response = view(request, slug='Parks', version1='2', version2='1')

            canonical_url = 'https://%s/sf/Parks/_history/2...1' % settings.MAIN_HOSTNAME
            response.render()
            self.assertTrue(self.has_canonical_url(canonical_url, request, response))

        #####################################################
        # Page diff on a normal region
        #####################################################

        request = self.factory.get('/sf/Parks/_history/2...1')
        request.user = self.user
        request.META['HTTP_HOST'] = settings.MAIN_HOSTNAME

        with self.mock_hosts_middleware(request):
            view = slugify(PageCompareView.as_view())
            response = view(request, slug='Parks', region='sf', version1='2', version2='1')

            canonical_url = ''
            response.render()
            # No canonical URL emitted
            self.assertFalse(self.has_canonical_url(canonical_url, request, response))
    '',
    url(r'^password/change/$',
        auth_views.password_change,
        name='auth_password_change'),
    url(r'^password/change/done/$',
        auth_views.password_change_done,
        name='auth_password_change_done'),
    url(r'^password/reset/$',
        auth_views.password_reset,
        name='auth_password_reset'),
    url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
        auth_views.password_reset_confirm,
        name='auth_password_reset_confirm'),
    url(r'^password/reset/complete/$',
        auth_views.password_reset_complete,
        name='auth_password_reset_complete'),
    url(r'^password/reset/done/$',
        auth_views.password_reset_done,
        name='auth_password_reset_done'),
)

user_page_urls = patterns(
    '',
    url(r'(?P<slug>[^/]+/[^/_]+)$',
        slugify(PageContentInUsersNamespaceView.as_view()),
        name="user-page-content-view"),
    url(r'(?P<username>[^/]*)/*$', UserPageView.as_view(), name="user-page"),
)

urlpatterns += django_registration_urls + user_page_urls
)

# We over-ride the login and logout views, so we just pull in the rest here:
django_registration_urls = patterns('',
    url(r'^password/change/$',
        auth_views.password_change,
        name='auth_password_change'),
    url(r'^password/change/done/$',
        auth_views.password_change_done,
        name='auth_password_change_done'),
    url(r'^password/reset/$',
        auth_views.password_reset,
        name='auth_password_reset'),
    url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
        auth_views.password_reset_confirm,
        name='auth_password_reset_confirm'),
    url(r'^password/reset/complete/$',
        auth_views.password_reset_complete,
        name='auth_password_reset_complete'),
    url(r'^password/reset/done/$',
        auth_views.password_reset_done,
        name='auth_password_reset_done'),
)

user_page_urls = patterns('',
    url(r'(?P<slug>[^/]+/[^/_]+)$', slugify(PageContentInUsersNamespaceView.as_view()), name="user-page-content-view"),
    url(r'(?P<username>[^/]*)/*$', UserPageView.as_view(), name="user-page"),
)

urlpatterns += django_registration_urls + user_page_urls
    def test_canonical_page_names(self):
        from pages.views import PageDetailView
        from pages.urls import slugify
        from django_hosts.middleware import HostsMiddlewareRequest

        #####################################################
        # A regular page on a custom domain
        #####################################################

        request = self.factory.get('/Parks')
        request.user = self.user
        request.META['HTTP_HOST'] = self.sf.regionsettings.domain

        with self.mock_hosts_middleware(request):
            view = slugify(PageDetailView.as_view())
            response = view(request, slug='Parks')

            canonical_url = 'https://%s/sf/Parks' % settings.MAIN_HOSTNAME
            response.render()
            self.assertTrue(self.has_canonical_url(canonical_url, request, response))

        #####################################################
        # Now let's try it with an alternative capitalization
        #####################################################

        request = self.factory.get('/PArkS')
        request.user = self.user
        request.META['HTTP_HOST'] = self.sf.regionsettings.domain

        with self.mock_hosts_middleware(request):
            view = slugify(PageDetailView.as_view())
            response = view(request, slug='PArkS')

            canonical_url = 'https://%s/sf/Parks' % settings.MAIN_HOSTNAME
            response.render()
            self.assertTrue(self.has_canonical_url(canonical_url, request, response))

        #####################################################
        # Regular page viewing directly on the main host
        #####################################################

        request = self.factory.get('/sf/Parks')
        request.user = self.user
        request.META['HTTP_HOST'] = self.sf.regionsettings.domain

        with self.mock_hosts_middleware(request):
            view = slugify(PageDetailView.as_view())
            response = view(request, slug='Parks', region='sf')

            response.render()
            # Directly on the canonical url, so it shouldn't be rendered
            self.assertFalse(self.has_canonical_url('', request, response))

        #####################################################
        # Capitalization variant viewed on the main host
        #####################################################

        request = self.factory.get('/sf/PArks')
        request.user = self.user
        request.META['HTTP_HOST'] = self.sf.regionsettings.domain

        with self.mock_hosts_middleware(request):
            view = slugify(PageDetailView.as_view())
            response = view(request, slug='PArks', region='sf')

            canonical_url = '/sf/Parks'
            response.render()
            self.assertFalse(self.has_canonical_url(canonical_url, request, response))