Exemplo n.º 1
0
class WrappedRequestTest(TestCase):
    def setUp(self):
        self.request = Request("http://www.example.com/page.html",
                               headers={"Content-Type": "text/html"})
        self.wrapped = WrappedRequest(self.request)

    def test_get_full_url(self):
        self.assertEqual(self.wrapped.get_full_url(), self.request.url)
        self.assertEqual(self.wrapped.full_url, self.request.url)

    def test_get_host(self):
        self.assertEqual(self.wrapped.get_host(),
                         urlparse(self.request.url).netloc)
        self.assertEqual(self.wrapped.host, urlparse(self.request.url).netloc)

    def test_get_type(self):
        self.assertEqual(self.wrapped.get_type(),
                         urlparse(self.request.url).scheme)
        self.assertEqual(self.wrapped.type, urlparse(self.request.url).scheme)

    def test_is_unverifiable(self):
        self.assertFalse(self.wrapped.is_unverifiable())
        self.assertFalse(self.wrapped.unverifiable)

    def test_is_unverifiable2(self):
        self.request.meta['is_unverifiable'] = True
        self.assertTrue(self.wrapped.is_unverifiable())
        self.assertTrue(self.wrapped.unverifiable)

    def test_get_origin_req_host(self):
        self.assertEqual(self.wrapped.get_origin_req_host(), 'www.example.com')
        self.assertEqual(self.wrapped.origin_req_host, 'www.example.com')

    def test_has_header(self):
        self.assertTrue(self.wrapped.has_header('content-type'))
        self.assertFalse(self.wrapped.has_header('xxxxx'))

    def test_get_header(self):
        self.assertEqual(self.wrapped.get_header('content-type'), 'text/html')
        self.assertEqual(self.wrapped.get_header('xxxxx', 'def'), 'def')

    def test_header_items(self):
        self.assertEqual(self.wrapped.header_items(),
                         [('Content-Type', ['text/html'])])

    def test_add_unredirected_header(self):
        self.wrapped.add_unredirected_header('hello', 'world')
        self.assertEqual(self.request.headers['hello'], b'world')
Exemplo n.º 2
0
 def setUp(self):
     self.request = Request("http://www.example.com/page.html",
                            headers={"Content-Type": "text/html"})
     self.wrapped = WrappedRequest(self.request)
Exemplo n.º 3
0
class WrappedRequestTest(TestCase):

    def setUp(self):
        self.request = Request("http://www.example.com/page.html",
                               headers={"Content-Type": "text/html"})
        self.wrapped = WrappedRequest(self.request)

    def test_get_full_url(self):
        self.assertEqual(self.wrapped.get_full_url(), self.request.url)

    def test_get_host(self):
        self.assertEqual(self.wrapped.get_host(), urlparse(self.request.url).netloc)

    def test_get_type(self):
        self.assertEqual(self.wrapped.get_type(), urlparse(self.request.url).scheme)

    def test_is_unverifiable(self):
        self.assertFalse(self.wrapped.is_unverifiable())
        self.assertFalse(self.wrapped.unverifiable)

    def test_is_unverifiable2(self):
        self.request.meta['is_unverifiable'] = True
        self.assertTrue(self.wrapped.is_unverifiable())
        self.assertTrue(self.wrapped.unverifiable)

    def test_get_origin_req_host(self):
        self.assertEqual(self.wrapped.get_origin_req_host(), 'www.example.com')

    def test_has_header(self):
        self.assertTrue(self.wrapped.has_header('content-type'))
        self.assertFalse(self.wrapped.has_header('xxxxx'))

    def test_get_header(self):
        self.assertEqual(self.wrapped.get_header('content-type'), 'text/html')
        self.assertEqual(self.wrapped.get_header('xxxxx', 'def'), 'def')

    def test_header_items(self):
        self.assertEqual(self.wrapped.header_items(),
                         [('Content-Type', ['text/html'])])

    def test_add_unredirected_header(self):
        self.wrapped.add_unredirected_header('hello', 'world')
        self.assertEqual(self.request.headers['hello'], b'world')
Exemplo n.º 4
0
 def setUp(self):
     self.request = Request("http://www.example.com/page.html",
                            headers={"Content-Type": "text/html"})
     self.wrapped = WrappedRequest(self.request)
Exemplo n.º 5
0
class WrappedRequestTest(TestCase):
    def setUp(self):
        self.request = Request("http://www.example.com/page.html", headers={"Content-Type": "text/html"})
        self.wrapped = WrappedRequest(self.request)

    def test_get_full_url(self):
        self.assertEqual(self.wrapped.get_full_url(), self.request.url)
        self.assertEqual(self.wrapped.full_url, self.request.url)

    def test_get_host(self):
        self.assertEqual(self.wrapped.get_host(), urlparse(self.request.url).netloc)
        self.assertEqual(self.wrapped.host, urlparse(self.request.url).netloc)

    def test_get_type(self):
        self.assertEqual(self.wrapped.get_type(), urlparse(self.request.url).scheme)
        self.assertEqual(self.wrapped.type, urlparse(self.request.url).scheme)

    def test_is_unverifiable(self):
        self.assertFalse(self.wrapped.is_unverifiable())
        self.assertFalse(self.wrapped.unverifiable)

    def test_is_unverifiable2(self):
        self.request.meta["is_unverifiable"] = True
        self.assertTrue(self.wrapped.is_unverifiable())
        self.assertTrue(self.wrapped.unverifiable)

    def test_get_origin_req_host(self):
        self.assertEqual(self.wrapped.get_origin_req_host(), "www.example.com")
        self.assertEqual(self.wrapped.origin_req_host, "www.example.com")

    def test_has_header(self):
        self.assertTrue(self.wrapped.has_header("content-type"))
        self.assertFalse(self.wrapped.has_header("xxxxx"))

    def test_get_header(self):
        self.assertEqual(self.wrapped.get_header("content-type"), "text/html")
        self.assertEqual(self.wrapped.get_header("xxxxx", "def"), "def")

    def test_header_items(self):
        self.assertEqual(self.wrapped.header_items(), [("Content-Type", ["text/html"])])

    def test_add_unredirected_header(self):
        self.wrapped.add_unredirected_header("hello", "world")
        self.assertEqual(self.request.headers["hello"], b"world")
 def add_cookie_header(self, request):
     super(CookieJar, self).add_cookie_header(WrappedRequest(request))
 def extract_cookies(self, response, request):
     wreq = WrappedRequest(request)
     wrsp = WrappedResponse(response)
     return super(CookieJar, self).extract_cookies(wrsp, wreq)
 def set_cookie_if_ok(self, cookie, request):
     super(CookieJar, self).set_cookie_if_ok(cookie,
                                             WrappedRequest(request))
 def make_cookies(self, response, request):
     if not isinstance(request, WrappedRequest):
         request = WrappedRequest(request)
     if not isinstance(response, WrappedResponse):
         response = WrappedResponse(response)
     return super(CookieJar, self).make_cookies(response, request)