Skip to content

Commit

Permalink
Fix online tests using the countries.trevorblades.com backend (#459)
Browse files Browse the repository at this point in the history
* Remove http online tests - only https is supported on backend now
* Skip online websockets tests - backend does not support it anymore
* Skip/remove batching online tests as backend does not support it anymore
* Remove 2 flaky online tests
  • Loading branch information
leszekhanusz committed Jan 3, 2024
1 parent 039236c commit c23d3e0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 69 deletions.
7 changes: 3 additions & 4 deletions tests/test_aiohttp_online.py
Expand Up @@ -11,13 +11,12 @@
@pytest.mark.aiohttp
@pytest.mark.online
@pytest.mark.asyncio
@pytest.mark.parametrize("protocol", ["http", "https"])
async def test_aiohttp_simple_query(event_loop, protocol):
async def test_aiohttp_simple_query(event_loop):

from gql.transport.aiohttp import AIOHTTPTransport

# Create http or https url
url = f"{protocol}://countries.trevorblades.com/graphql"
# Create https url
url = "https://countries.trevorblades.com/graphql"

# Get transport
sample_transport = AIOHTTPTransport(url=url)
Expand Down
56 changes: 12 additions & 44 deletions tests/test_client.py
Expand Up @@ -46,7 +46,6 @@ def execute(self):


@pytest.mark.aiohttp
@pytest.mark.asyncio
def test_request_async_execute_batch_not_implemented_yet():
from gql.transport.aiohttp import AIOHTTPTransport

Expand Down Expand Up @@ -145,32 +144,13 @@ def test_execute_result_error():
client.execute(failing_query)
assert 'Cannot query field "id" on type "Continent".' in str(exc_info.value)

"""
Batching is not supported anymore on countries backend
with pytest.raises(TransportQueryError) as exc_info:
client.execute_batch([GraphQLRequest(document=failing_query)])
assert 'Cannot query field "id" on type "Continent".' in str(exc_info.value)


@pytest.mark.online
@pytest.mark.requests
def test_http_transport_raise_for_status_error(http_transport_query):
from gql.transport.requests import RequestsHTTPTransport

with Client(
transport=RequestsHTTPTransport(
url="https://countries.trevorblades.com/",
use_json=False,
headers={"Content-type": "application/json"},
)
) as client:
with pytest.raises(Exception) as exc_info:
client.execute(http_transport_query)

assert "400 Client Error: Bad Request for url" in str(exc_info.value)

with pytest.raises(Exception) as exc_info:
client.execute_batch([GraphQLRequest(document=http_transport_query)])

assert "400 Client Error: Bad Request for url" in str(exc_info.value)
"""


@pytest.mark.online
Expand All @@ -192,13 +172,17 @@ def test_http_transport_verify_error(http_transport_query):
record[0].message
)

"""
Batching is not supported anymore on countries backend
with pytest.warns(Warning) as record:
client.execute_batch([GraphQLRequest(document=http_transport_query)])
assert len(record) == 1
assert "Unverified HTTPS request is being made to host" in str(
record[0].message
)
"""


@pytest.mark.online
Expand All @@ -215,28 +199,12 @@ def test_http_transport_specify_method_valid(http_transport_query):
result = client.execute(http_transport_query)
assert result is not None

"""
Batching is not supported anymore on countries backend
result = client.execute_batch([GraphQLRequest(document=http_transport_query)])
assert result is not None


@pytest.mark.online
@pytest.mark.requests
def test_http_transport_specify_method_invalid(http_transport_query):
from gql.transport.requests import RequestsHTTPTransport

with Client(
transport=RequestsHTTPTransport(
url="https://countries.trevorblades.com/",
method="GET",
)
) as client:
with pytest.raises(Exception) as exc_info:
client.execute(http_transport_query)
assert "400 Client Error: Bad Request for url" in str(exc_info.value)

with pytest.raises(Exception) as exc_info:
client.execute_batch([GraphQLRequest(document=http_transport_query)])
assert "400 Client Error: Bad Request for url" in str(exc_info.value)
"""


def test_gql():
Expand Down
23 changes: 9 additions & 14 deletions tests/test_http_async_sync.py
Expand Up @@ -6,16 +6,13 @@
@pytest.mark.aiohttp
@pytest.mark.online
@pytest.mark.asyncio
@pytest.mark.parametrize("protocol", ["http", "https"])
@pytest.mark.parametrize("fetch_schema_from_transport", [True, False])
async def test_async_client_async_transport(
event_loop, protocol, fetch_schema_from_transport
):
async def test_async_client_async_transport(event_loop, fetch_schema_from_transport):

from gql.transport.aiohttp import AIOHTTPTransport

# Create http or https url
url = f"{protocol}://countries.trevorblades.com/graphql"
# Create https url
url = "https://countries.trevorblades.com/graphql"

# Get async transport
sample_transport = AIOHTTPTransport(url=url)
Expand Down Expand Up @@ -76,14 +73,13 @@ async def test_async_client_sync_transport(event_loop, fetch_schema_from_transpo

@pytest.mark.aiohttp
@pytest.mark.online
@pytest.mark.parametrize("protocol", ["http", "https"])
@pytest.mark.parametrize("fetch_schema_from_transport", [True, False])
def test_sync_client_async_transport(protocol, fetch_schema_from_transport):
def test_sync_client_async_transport(fetch_schema_from_transport):

from gql.transport.aiohttp import AIOHTTPTransport

# Create http or https url
url = f"{protocol}://countries.trevorblades.com/graphql"
# Create https url
url = "https://countries.trevorblades.com/graphql"

# Get async transport
sample_transport = AIOHTTPTransport(url=url)
Expand Down Expand Up @@ -120,14 +116,13 @@ def test_sync_client_async_transport(protocol, fetch_schema_from_transport):

@pytest.mark.requests
@pytest.mark.online
@pytest.mark.parametrize("protocol", ["http", "https"])
@pytest.mark.parametrize("fetch_schema_from_transport", [True, False])
def test_sync_client_sync_transport(protocol, fetch_schema_from_transport):
def test_sync_client_sync_transport(fetch_schema_from_transport):

from gql.transport.requests import RequestsHTTPTransport

# Create http or https url
url = f"{protocol}://countries.trevorblades.com/graphql"
# Create https url
url = "https://countries.trevorblades.com/graphql"

# Get sync transport
sample_transport = RequestsHTTPTransport(url=url, use_json=True)
Expand Down
7 changes: 3 additions & 4 deletions tests/test_httpx_online.py
Expand Up @@ -11,13 +11,12 @@
@pytest.mark.httpx
@pytest.mark.online
@pytest.mark.asyncio
@pytest.mark.parametrize("protocol", ["http", "https"])
async def test_httpx_simple_query(event_loop, protocol):
async def test_httpx_simple_query(event_loop):

from gql.transport.httpx import HTTPXAsyncTransport

# Create http or https url
url = f"{protocol}://countries.trevorblades.com/graphql"
# Create https url
url = "https://countries.trevorblades.com/graphql"

# Get transport
sample_transport = HTTPXAsyncTransport(url=url)
Expand Down
14 changes: 11 additions & 3 deletions tests/test_requests_batch.py
Expand Up @@ -540,15 +540,21 @@ def test_code():
await run_sync_test(event_loop, server, test_code)


ONLINE_URL = "https://countries.trevorblades.com/"

skip_reason = "backend does not support batching anymore..."


@pytest.mark.online
@pytest.mark.requests
@pytest.mark.skip(reason=skip_reason)
def test_requests_sync_batch_auto():

from threading import Thread
from gql.transport.requests import RequestsHTTPTransport

client = Client(
transport=RequestsHTTPTransport(url="https://countries.trevorblades.com/"),
transport=RequestsHTTPTransport(url=ONLINE_URL),
batch_interval=0.01,
batch_max=3,
)
Expand Down Expand Up @@ -607,12 +613,13 @@ def get_continent_name(session, continent_code):

@pytest.mark.online
@pytest.mark.requests
@pytest.mark.skip(reason=skip_reason)
def test_requests_sync_batch_auto_execute_future():

from gql.transport.requests import RequestsHTTPTransport

client = Client(
transport=RequestsHTTPTransport(url="https://countries.trevorblades.com/"),
transport=RequestsHTTPTransport(url=ONLINE_URL),
batch_interval=0.01,
batch_max=3,
)
Expand Down Expand Up @@ -644,12 +651,13 @@ def test_requests_sync_batch_auto_execute_future():

@pytest.mark.online
@pytest.mark.requests
@pytest.mark.skip(reason=skip_reason)
def test_requests_sync_batch_manual():

from gql.transport.requests import RequestsHTTPTransport

client = Client(
transport=RequestsHTTPTransport(url="https://countries.trevorblades.com/"),
transport=RequestsHTTPTransport(url=ONLINE_URL),
)

query = gql(
Expand Down
11 changes: 11 additions & 0 deletions tests/test_websocket_online.py
Expand Up @@ -15,8 +15,14 @@

logging.basicConfig(level=logging.INFO)

skip_reason = (
"backend does not support websockets anymore: "
"https://github.com/trevorblades/countries/issues/42"
)


@pytest.mark.online
@pytest.mark.skip(reason=skip_reason)
@pytest.mark.asyncio
async def test_websocket_simple_query():
from gql.transport.websockets import WebsocketsTransport
Expand Down Expand Up @@ -57,6 +63,7 @@ async def test_websocket_simple_query():


@pytest.mark.online
@pytest.mark.skip(reason=skip_reason)
@pytest.mark.asyncio
async def test_websocket_invalid_query():
from gql.transport.websockets import WebsocketsTransport
Expand Down Expand Up @@ -86,6 +93,7 @@ async def test_websocket_invalid_query():


@pytest.mark.online
@pytest.mark.skip(reason=skip_reason)
@pytest.mark.asyncio
async def test_websocket_sending_invalid_data():
from gql.transport.websockets import WebsocketsTransport
Expand Down Expand Up @@ -121,6 +129,7 @@ async def test_websocket_sending_invalid_data():


@pytest.mark.online
@pytest.mark.skip(reason=skip_reason)
@pytest.mark.asyncio
async def test_websocket_sending_invalid_payload():
from gql.transport.websockets import WebsocketsTransport
Expand All @@ -143,6 +152,7 @@ async def test_websocket_sending_invalid_payload():

@pytest.mark.online
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
@pytest.mark.skip(reason=skip_reason)
@pytest.mark.asyncio
async def test_websocket_sending_invalid_data_while_other_query_is_running():
from gql.transport.websockets import WebsocketsTransport
Expand Down Expand Up @@ -194,6 +204,7 @@ async def query_task2():

@pytest.mark.online
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
@pytest.mark.skip(reason=skip_reason)
@pytest.mark.asyncio
async def test_websocket_two_queries_in_parallel_using_two_tasks():
from gql.transport.websockets import WebsocketsTransport
Expand Down

0 comments on commit c23d3e0

Please sign in to comment.