Пример #1
0
 async def new_response(self, response):
     """Convert an aiohttp.Response object to a requests.Response object"""
     new = Response()
     new._content = await response.read()
     new.status_code = response.status
     new.headers = response.headers
     new.cookies = response.cookies
     new.encoding = response.charset
     return new
Пример #2
0
 async def new_response(self, response):
     """Convert an aiohttp.Response object to a requests.Response object"""
     new = Response()
     new._content = await response.read()
     new.status_code = response.status
     new.headers = response.headers
     new.cookies = response.cookies
     new.encoding = response.charset
     return new
Пример #3
0
 def test_login_failed_no_bbdata(self, post_mock):
     response = Response()
     response.url = "http://tapochek.net/not_login"
     response.cookies = {}
     post_mock.return_value = response
     with self.assertRaises(TapochekLoginFailedException) as e:
         self.tracker.login(self.helper.real_login, self.helper.real_password)
     self.assertEqual(2, e.exception.code)
     self.assertEqual("Failed to retrieve cookie", e.exception.message)
Пример #4
0
    def new_response(self, response):
        """Convert an aiohttp.Response object to a requests.Response object"""
        body = response.read()

        new = Response()
        new._content = body
        new.status_code = response.status_code
        new.headers = response.headers
        new.cookies = response.cookies
        new.encoding = response.encoding
        return new
Пример #5
0
def mock_send(prepped_request, **kwargs):
    if prepped_request.path_url == '/api/aaaLogin.xml':
        cookie_path = os.path.join(FIXTURES_DIR, 'login_cookie.txt')
        response_path = os.path.join(FIXTURES_DIR, 'login.txt')
        response = Response()
        with open(cookie_path, 'r') as f:
            response.cookies = {'APIC-cookie': f.read()}
        with open(response_path, 'r') as f:
            response.raw = f.read()

    return response
Пример #6
0
 def make_response(url='', content='ok', status_code=200, history=(),
                   encoding='utf8', reason='', cookies=None):
     r = Response()
     r.url = url
     r._content = content
     r.status_code = status_code
     r.history = history
     r.encoding = encoding
     r.reason = reason
     r.cookies = cookiejar_from_dict(cookies or {})
     return r