Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions python/_restclient/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import pytest
from aiohttp import web
import asyncio

from hydrotools._restclient.async_client import ClientSession

Expand Down Expand Up @@ -81,12 +82,13 @@ async def test_get_check_cache(basic_test_server):
assert r.from_cache is False
assert r2.from_cache is True


def test_get_non_async(basic_test_server, event_loop):
@pytest.mark.asyncio
async def test_get_non_async(basic_test_server):
event_loop = asyncio.get_running_loop()
session = ClientSession(loop=event_loop)
resp_coro = session.get(basic_test_server["uri"])
resp = event_loop.run_until_complete(resp_coro)
assert event_loop.run_until_complete(resp.json()) == basic_test_server["data"]
resp_coro = await session.get(basic_test_server["uri"])
resp = await resp_coro.json()
assert resp == basic_test_server["data"]


@pytest.fixture
Expand Down
15 changes: 8 additions & 7 deletions python/_restclient/tests/test_restclient.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from aiohttp import web
import pytest
import asyncio
from hydrotools._restclient import RestClient


Expand Down Expand Up @@ -142,11 +143,10 @@ def test_get_headers_have_precedent_over_instance(basic_test_server):
# verify in key, "some", "other_header" value in headers not "headers"
assert all(k_v_pair in r.headers.items() for k_v_pair in method_headers.items())


def test_build_url(event_loop):
def test_build_url():
base_url = "http://www.test.gov/"
query_params = {"key": "value"}
with RestClient(enable_cache=False, loop=event_loop) as client:
with RestClient(enable_cache=False) as client:

assert client.build_url(base_url) == base_url
assert client.build_url(base_url, query_params) == f"{base_url}?key=value"
Expand All @@ -155,10 +155,11 @@ def test_build_url(event_loop):
class ModuleFoundError(Exception):
...


def test_restclient_nest_asyncio_ModuleNotFoundError(event_loop):
@pytest.mark.asyncio
async def test_restclient_nest_asyncio_ModuleNotFoundError():
"""Test for #99. Ensure ModuleNotFoundError raised if `nest_asyncio` not installed"""
import asyncio
event_loop = asyncio.get_running_loop()
# import asyncio
import warnings

# verify `nest_asyncio` is not installed
Expand All @@ -183,4 +184,4 @@ async def test():
# this test will need to change if `nest_asyncio` becomes a requirement
RestClient(enable_cache=False)

event_loop.run_until_complete(test())
await test()
2 changes: 1 addition & 1 deletion python/_restclient/tests/test_urllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def test_plus():
base_url = "http://www.fake.gov"
params = {"key": "+12"}
url = Url(base_url, quote_treatment=Quote.QUOTE) + params
print(url.quote_url)
# print(url.quote_url)


def test_quote_overide_map():
Expand Down