コード例 #1
0
ファイル: test_middleware.py プロジェクト: kepinq/MyJobs
    def test_wildcard_redirect(self):
        """
        Test the wildcard redirect. This makes a call to a url with an invalid
        subdomain, which should result in a 301 redirect to the root domain.

        """
        site = SeoSiteFactory.build(domain='www.my.jobs',name=u'www.my.jobs')
        site.save()

        settings.WILDCARD_REDIRECT = True
        # check that the redirect ignores domains without a subdomain
        resp = self.client.get('/', HTTP_HOST='domain.jobs')
        self.assertEqual(resp.status_code, 200)

        # check that IP addresses are NOT redirected
        resp = self.client.get('/', HTTP_HOST='127.0.0.1')
        self.assertEqual(resp.status_code, 200)

        # check that the redirect ignores domains in the exception list
        resp = self.client.get(
            '/',
            HTTP_HOST='ec2-50-16-227-119.compute-1.amazonaws.com'
            )
        self.assertEqual(resp.status_code, 200)

        # check that it redirects when it supposed to
        resp = self.client.get('/', HTTP_HOST='fake.usa.jobs', follow=True)
        self.assertEqual(resp.status_code, 301)
        WildcardMiddlewareTestCase._check_external_redirect(self,
            resp,"http://usa.jobs")

        # check that is respects the setting toggle
        settings.WILDCARD_REDIRECT = False
        resp = self.client.get('/', HTTP_HOST='wrong.www.my.jobs')
        self.assertEqual(resp.status_code, 200)
コード例 #2
0
    def test_wildcard_redirect(self):
        """
        Test the wildcard redirect. This makes a call to a url with an invalid
        subdomain, which should result in a 301 redirect to the root domain.

        """
        site = SeoSiteFactory.build(domain='www.my.jobs', name=u'www.my.jobs')
        site.save()

        settings.WILDCARD_REDIRECT = True
        # check that the redirect ignores domains without a subdomain
        resp = self.client.get('/', HTTP_HOST='domain.jobs')
        self.assertEqual(resp.status_code, 200)

        # check that IP addresses are NOT redirected
        resp = self.client.get('/', HTTP_HOST='127.0.0.1')
        self.assertEqual(resp.status_code, 200)

        # check that the redirect ignores domains in the exception list
        resp = self.client.get(
            '/',
            HTTP_HOST='ec2-50-16-227-119.compute-1.amazonaws.com'
            )
        self.assertEqual(resp.status_code, 200)

        # check that it redirects when it supposed to
        resp = self.client.get('/', HTTP_HOST='fake.usa.jobs', follow=True)
        self.assertEqual(resp.status_code, 301)
        self.assertRedirects(resp, 'http://usa.jobs', status_code=301,
                             target_status_code=301)

        # check that is respects the setting toggle
        settings.WILDCARD_REDIRECT = False
        resp = self.client.get('/', HTTP_HOST='wrong.www.my.jobs')
        self.assertEqual(resp.status_code, 200)
コード例 #3
0
 def setUp(self):
     super(SiteRedirectMiddlewareTestCase, self).setUp()
     self.test_site = SeoSiteFactory.build()
     self.test_site.save()
     self.ssr1 = SeoSiteRedirectFactory.build(seosite=self.test_site)
     self.ssr1.save()
     self.ssr2 = SeoSiteRedirectFactory.build(
                 redirect_url=u'test.%s' % self.test_site.domain,
                 seosite=self.test_site)
     self.ssr2.save()
コード例 #4
0
 def setUp(self):
     super(SiteRedirectMiddlewareTestCase, self).setUp()
     self.test_site = SeoSiteFactory.build()
     self.test_site.save()
     self.ssr1 = SeoSiteRedirectFactory.build(seosite=self.test_site)
     self.ssr1.save()
     self.ssr2 = SeoSiteRedirectFactory.build(redirect_url=u'test.%s' %
                                              self.test_site.domain,
                                              seosite=self.test_site)
     self.ssr2.save()