示例#1
0
async def test_client_close():
    async with IpApiClient() as client:
        pass
    assert client.closed

    client = IpApiClient()
    await client.close()
    assert client.closed

    with pytest.raises(ValueError):
        await client.location()

    with pytest.raises(ValueError):
        async for _ in client.location_stream(['127.0.0.1']):
            pass
示例#2
0
async def test_location_a_lot_queries():
    ips = ['8.8.8.8', '1.1.1.1', '1.0.0.1'] * 700
    check_fields = ['org', 'lat', 'lon', 'country', 'as']

    async with IpApiClient() as client:
        async for ip, res in aioitertools.zip(ips,
                                              client.location_stream(ips)):
            assert 'status' in res and res['status'] == 'success'
            assert 'query' in res and res['query'] == ip

            for field in check_fields:
                assert field in res
示例#3
0
async def test_location(query):
    fields = ['org', 'lat', 'lon', 'country', 'as']

    async with IpApiClient(fields=fields) as client:
        if query is sentinel:
            result = await client.location()
        else:
            result = await client.location(query)

        if isinstance(result, dict):
            result = [result]

        for res in result:
            assert 'status' in res and res['status'] == 'success'
            assert 'query' in res

            for field in fields:
                assert field in res
示例#4
0
async def test_validate_batch_input_data(query):
    async with IpApiClient() as client:
        with pytest.raises(ValueError):
            await client.location([query])
示例#5
0
async def test_location_invalid_query():
    async with IpApiClient() as client:
        res = await client.location('1.2.3.4.5')
        assert 'status' in res and res['status'] == 'fail'
        assert 'message' in res and res['message'] == 'invalid query'
示例#6
0
async def test_location_reserved_range():
    async with IpApiClient() as client:
        res = await client.location('127.0.0.1')
        assert 'status' in res and res['status'] == 'fail'
        assert 'message' in res and res['message'] == 'reserved range'
示例#7
0
async def test_location_local_mock(query, fields, lang, expected,
                                   config_local):
    async with IpApiClient(fields=fields, lang=lang) as client:
        res = await client.location(query)
        assert res == expected