class AbstractBaseHttpResponse(object): """ Wrapper of Urllib3 HTTPResponse class needed to implement any HttpSdk response class. See `Urllib3 <http://urllib3.readthedocs.io/en/latest/user-guide.html#response-content>`_. """ urllib3_response = None _cookie = None def __init__(self, resp): self.urllib3_response = resp @property def cookie(self): if not self._cookie: self._cookie = Cookie(self.headers) else: self._cookie.load_from_headers(self.headers) return self._cookie @property def headers(self): """ Returns a dictionary of the response headers. """ return self.urllib3_response.getheaders()
def test_update_cookie(self): c = Cookie({"Set-Cookie": "new_param=marcos; another_new=ivan"}) c.update(self.cookie) res = c.as_cookie_header_value() self.assertIn("chips=ahoy", res) self.assertIn("vienna=finger", res) self.assertIn("new_param=marcos", res) self.assertIn("another_new=ivan", res)
def cookie(self, value): """ Set cookie. :param value: """ if value and not value.is_empty(): self._cookie = value else: self._cookie = Cookie()
def test_create_item_from_context_with_cookie(self): c = Cookie({"Set-Cookie": "new_param=marcos; another_new=ivan"}) context = HttpRequestContext( host="https://www.google.com", url_path="/items/", method="POST", body_params={"name": "mi nombre", "description": "algo"}, cookie=c ) response = request_from_context(context=context) self.assertEqual(response.status, 404)
def cookie(self, value): self._cookie = value or Cookie()
def setUpClass(cls): cls.cookie = Cookie({"Set-Cookie": "chips=ahoy; vienna=finger"})
def test_as_cookie_header_value_none(self): cookie = Cookie(None) res = cookie.as_cookie_header_value() self.assertEqual(res, "")
def test_as_cookie_header_value_tuples(self): cookie = Cookie([("Set-Cookie", "chips=ahoy; httpOnly"), ("Set-Cookie", "vienna=finger")]) res = cookie.as_cookie_header_value() self.assertIn("chips=ahoy", res) self.assertIn("vienna=finger", res)
def cookie(self): if not self._cookie: self._cookie = Cookie(self.headers) else: self._cookie.load_from_headers(self.headers) return self._cookie