コード例 #1
0
ファイル: test_middleware.py プロジェクト: LinuzLuzas/bedrock
class TestCrossOriginResourceSharingMiddleware(TestCase):
    def setUp(self):
        self.middleware = CrossOriginResourceSharingMiddleware()
        self.request = HttpRequest()
        self.response = HttpResponse()

    def test_match(self):
        self.request.path = '/foo/bar/baz/'

        cors_urls = {r'^/foo/bar': '*'}
        with self.settings(CORS_URLS=cors_urls):
            self.middleware.process_response(self.request, self.response)
            self.assertEqual(self.response['Access-Control-Allow-Origin'], '*')

    def test_middle_match(self):
        # Ensure that matches in the middle of the URL work.
        self.request.path = '/foo/bar/baz/'

        cors_urls = {r'/bar': '*'}
        with self.settings(CORS_URLS=cors_urls):
            self.middleware.process_response(self.request, self.response)
            self.assertEqual(self.response['Access-Control-Allow-Origin'], '*')

    def test_no_match(self):
        self.request.path = '/foo/bar/baz/'

        cors_urls = {r'^/biff/bak': '*'}
        with self.settings(CORS_URLS=cors_urls):
            self.middleware.process_response(self.request, self.response)
            self.assertFalse('Access-Control-Allow-Origin' in self.response)
コード例 #2
0
class TestCrossOriginResourceSharingMiddleware(TestCase):
    def setUp(self):
        self.middleware = CrossOriginResourceSharingMiddleware()
        self.request = HttpRequest()
        self.response = HttpResponse()

    def test_match(self):
        self.request.path = '/foo/bar/baz/'

        cors_urls = {r'^/foo/bar': '*'}
        with self.settings(CORS_URLS=cors_urls):
            self.middleware.process_response(self.request, self.response)
            self.assertEqual(self.response['Access-Control-Allow-Origin'], '*')

    def test_middle_match(self):
        # Ensure that matches in the middle of the URL work.
        self.request.path = '/foo/bar/baz/'

        cors_urls = {r'/bar': '*'}
        with self.settings(CORS_URLS=cors_urls):
            self.middleware.process_response(self.request, self.response)
            self.assertEqual(self.response['Access-Control-Allow-Origin'], '*')

    def test_no_match(self):
        self.request.path = '/foo/bar/baz/'

        cors_urls = {r'^/biff/bak': '*'}
        with self.settings(CORS_URLS=cors_urls):
            self.middleware.process_response(self.request, self.response)
            self.assertFalse('Access-Control-Allow-Origin' in self.response)
コード例 #3
0
ファイル: test_middleware.py プロジェクト: LinuzLuzas/bedrock
 def setUp(self):
     self.middleware = CrossOriginResourceSharingMiddleware()
     self.request = HttpRequest()
     self.response = HttpResponse()
コード例 #4
0
 def setUp(self):
     self.middleware = CrossOriginResourceSharingMiddleware()
     self.request = HttpRequest()
     self.response = HttpResponse()