コード例 #1
0
async def test_http_processing_error(session):
    loop = mock.Mock()
    request_info = mock.Mock()
    response = ClientResponse('get',
                              URL('http://del-cl-resp.org'),
                              request_info=request_info,
                              writer=mock.Mock(),
                              continue100=None,
                              timer=TimerNoop(),
                              auto_decompress=True,
                              traces=[],
                              loop=loop,
                              session=session)
    loop.get_debug = mock.Mock()
    loop.get_debug.return_value = True

    connection = mock.Mock()
    connection.protocol = aiohttp.DataQueue(loop=loop)
    connection.protocol.set_response_params = mock.Mock()
    connection.protocol.set_exception(http.HttpProcessingError())

    with pytest.raises(aiohttp.ClientResponseError) as info:
        await response.start(connection)

    assert info.value.request_info is request_info
コード例 #2
0
async def persist_order(order_data, session):
    async with session.post(ORDER_API_ENDPOINT, json=order_data) as response:
        if response.status == 201:
            order = await response.json()
            return order
        else:
            raise http.HttpProcessingError(code=response.status,
                                           message=response.reason,
                                           headers=response.headers)
コード例 #3
0
async def fetch_price(price_params, session):
    url_params = urlencode(price_params)
    url = '%s?%s' % (PRICE_API_ENDPOINT, url_params)
    async with session.get(url) as response:
        if response.status == 200:
            price_details = await response.json()
            return price_details
        else:
            raise http.HttpProcessingError(code=response.status,
                                           message=response.reason,
                                           headers=response.headers)
コード例 #4
0
def function1795():
    var3605 = mock.Mock()
    var1010 = mock.Mock()
    var286 = ClientResponse('get', URL('http://del-cl-resp.org'), request_info=var1010)
    var286._post_init(var3605)
    var3605.get_debug = mock.Mock()
    var3605.get_debug.return_value = True
    var4238 = mock.Mock()
    var4238.protocol = aiohttp.DataQueue(loop=var3605)
    var4238.protocol.set_response_params = mock.Mock()
    var4238.protocol.set_exception(http.HttpProcessingError())
    with pytest.raises(aiohttp.ClientResponseError) as var341:
        yield from var286.start(var4238)
    assert (var341.value.var1010 is var1010)
コード例 #5
0
async def fetch_customer(customer_id, session):
    url = '%s/%s' % (CUSTOMER_API_ENDPOINT, customer_id)
    async with session.get(url) as response:
        if response.status == 200:
            customer = await response.json()
            if customer['status'] == CUSTOMER_STATUS_DELETED:
                raise IntegrityError(
                    "Given customer is deleted! customer_id: {}".format(
                        customer_id))
            return customer
        elif response.status == 404:
            raise web.HTTPNotFound(
                reason="Customer with id: {} not found!".format(customer_id))
        else:
            raise http.HttpProcessingError(code=response.status,
                                           message=response.reason,
                                           headers=response.headers)
コード例 #6
0
async def test_http_processing_error(session):
    loop = mock.Mock()
    request_info = mock.Mock()
    response = ClientResponse(
        'get', URL('http://del-cl-resp.org'), request_info=request_info)
    response._post_init(loop, session)
    loop.get_debug = mock.Mock()
    loop.get_debug.return_value = True

    connection = mock.Mock()
    connection.protocol = aiohttp.DataQueue(loop=loop)
    connection.protocol.set_response_params = mock.Mock()
    connection.protocol.set_exception(http.HttpProcessingError())

    with pytest.raises(aiohttp.ClientResponseError) as info:
        await response.start(connection)

    assert info.value.request_info is request_info
コード例 #7
0
async def fetch_product(product_name, session):
    url_params = urlencode(OrderedDict(name=product_name))
    url = '%s?%s' % (PRODUCT_API_ENDPOINT, url_params)
    async with session.get(url) as response:
        if response.status == 200:
            results = await response.json()
            if results['results']:
                product = results['results'][0]
                if product['status'] == PRODUCT_STATUS_INACTIVE:
                    raise IntegrityError(
                        "Given product is inactive! name: {}".format(
                            product_name))
                return product
            raise web.HTTPNotFound(
                reason="Product with name: {} not found!".format(product_name))
        else:
            raise http.HttpProcessingError(code=response.status,
                                           message=response.reason,
                                           headers=response.headers)