コード例 #1
0
def test_status_codes(doggo_proxy, default_http_client: DefaultHTTPClient,
                      http_doggo_url: str):
    patch_on_http_response(default_http_client, abort_on=[404])
    default_http_client.get(http_doggo_url)
    assert default_http_client.last_response.status_code == 200
    default_http_client.get(http_doggo_url[:-1])
    assert default_http_client.last_response.status_code == 404
コード例 #2
0
def test_default_http_client_close(doggo_proxy,
                                   default_http_client: DefaultHTTPClient,
                                   http_doggo_url: str):
    client = default_http_client.client
    check_response(default_http_client.get(http_doggo_url))
    default_http_client.close_active_channel(http_doggo_url)
    open_channels = client.get_open_channels()
    assert len(open_channels) == 0
コード例 #3
0
def test_default_http_client_existing_channel_topup(
        doggo_proxy, default_http_client: DefaultHTTPClient,
        receiver_address: str, http_doggo_url: str):
    client = default_http_client.client
    default_http_client.topup_deposit = lambda x: 13
    channel = client.open_channel(receiver_address, 1)
    check_response(default_http_client.get(http_doggo_url))
    assert channel.balance == 2
    assert channel.deposit == 13
コード例 #4
0
def test_custom_headers(default_http_client: DefaultHTTPClient,
                        api_endpoint_address: str, token_address: str,
                        channel_manager_address: str, receiver_address: str):
    default_http_client.initial_deposit = lambda x: x

    with requests_mock.mock() as server_mock:
        headers1 = Munch()
        headers1.token_address = token_address
        headers1.contract_address = channel_manager_address
        headers1.receiver_address = receiver_address
        headers1.price = '7'

        headers2 = Munch()
        headers2.cost = '7'

        headers1 = HTTPHeaders.serialize(headers1)
        headers2 = HTTPHeaders.serialize(headers2)

        url = 'http://{}/something'.format(api_endpoint_address)
        server_mock.get(url, [{
            'status_code': 402,
            'headers': headers1
        }, {
            'status_code': 200,
            'headers': headers2,
            'text': 'success'
        }])
        response = default_http_client.get(
            url,
            headers={
                'someheader': 'somevalue',
                # This should override the actual balance but doesn't actually make sense.
                'RDN-Balance': '5'
            })

    # First cycle, request price.
    request = server_mock.request_history[0]
    assert request.path == '/something'
    assert request.method == 'GET'
    assert request.headers['RDN-Contract-Address'] == channel_manager_address
    assert request.headers['RDN-Balance'] == '5'
    assert request.headers['someheader'] == 'somevalue'

    # Second cycle, pay price.
    request = server_mock.request_history[1]
    assert request.path == '/something'
    assert request.method == 'GET'
    assert request.headers['RDN-Contract-Address'] == channel_manager_address
    assert request.headers['RDN-Balance'] == '5'
    assert request.headers['someheader'] == 'somevalue'

    channel = default_http_client.get_channel(url)
    assert channel.balance == 7
    balance_sig_hex = encode_hex(channel.balance_sig)
    assert request.headers['RDN-Balance-Signature'] == balance_sig_hex
    assert channel.balance_sig
    assert response.text == 'success'
コード例 #5
0
def test_default_http_client(doggo_proxy,
                             default_http_client: DefaultHTTPClient,
                             sender_address: str, receiver_address: str,
                             http_doggo_url: str):
    check_response(default_http_client.get(http_doggo_url))

    client = default_http_client.client
    open_channels = client.get_open_channels()
    assert len(open_channels) == 1

    channel = open_channels[0]
    assert channel == default_http_client.get_channel(http_doggo_url)
    assert channel.balance_sig
    assert channel.balance < channel.deposit
    assert channel.sender == sender_address
    assert channel.receiver == receiver_address