Ejemplo n.º 1
0
 def _execute(self, url, params=None, token=None, version=None):
     fy_request = Request()
     fy_request.set_host(self.host)
     fy_request.set_method('post')
     fy_request.set_protocol(constant.HTTPS)
     fy_request.set_content_type(constant.CONTENT_TYPE_JSON)
     fy_request.set_url(url)
     fy_request.set_cloud_token(token)
     fy_request.set_params(params)
     fy_request.format_params()
     if version:
         fy_request.set_api_ver(version)
     return super().execute(fy_request)
def test_methods_with_host():
    request = Request()
    request.set_host('vk.com')
    request.set_path('/feed/ru')
    request.set_scheme('http')
    request.set_body('Hello')
    request.set_headers({'Cookie': '1234', 'Reference': 'blablacar.com'})
    request.set_header(header='User-Agent', value='Yandex')
    request.set_method('delete')
    request.set_protocol('HTTP/1.0')
    expected_bytes_request: str = 'DELETE /feed/ru HTTP/1.0\r\n' \
                                  'Host: vk.com\r\n' \
                                  'Connection: close\r\n' \
                                  'Content-Length: 5\r\n' \
                                  'Cookie: 1234\r\n' \
                                  'Reference: blablacar.com\r\n' \
                                  'User-Agent: Yandex\r\n\r\n' \
                                  'Hello'
    assert bytes(request).decode() == expected_bytes_request
    assert request.scheme == 'http'
    assert request.host == 'vk.com'