def test_method_error_request(): try: request = Request("https://httpbin.org/", method="PUT") response = asyncio.get_event_loop().run_until_complete(request.fetch()) assert await response.text() == "" except Exception as e: assert isinstance(e, InvalidRequestMethod)
def test_request_params(): params = { "name": "ruia" } request = Request('http://www.httpbin.org/get', method='GET', res_type='json', params=params) result = asyncio.get_event_loop().run_until_complete(request.fetch()) assert result.html['args']['name'] == "ruia"
def test_request_ua(): headers = { "User-Agent": "Python3.5" } request = Request('http://www.httpbin.org/get', method='GET', res_type='json', headers=headers) result = asyncio.get_event_loop().run_until_complete(request.fetch()) assert result.html['headers']['User-Agent'] == "Python3.5"
def test_method_error_request(): try: request = Request('https://httpbin.org/', method='PUT') response = asyncio.get_event_loop().run_until_complete(request.fetch()) assert response.html == '' except Exception as e: assert isinstance(e, InvalidRequestMethod)
def test_delay_false(): request_config = {"DELAY": 10} request = Request("https://httpbin.org/", request_config=request_config) # Start a timer to time request timer = time.time() response = asyncio.get_event_loop().run_until_complete(request.fetch(delay=False)) # Ensure delay option was ignored (time taken is less than 10s) assert time.time() - timer < 10
async def sec_request(): form_data, must_cookies, history = await request_example() headers = { 'User-Agent': ('Mozilla/5.0'), } request = Request(url='http://portal.neaea.gov.et/Student/StudentDetailsx', method='POST', headers=headers, metadata=form_data, cookies=must_cookies) print(request) return request.fetch()