Skip to content

Commit c23d3e0

Browse files
authored
Fix online tests using the countries.trevorblades.com backend (#459)
* 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
1 parent 039236c commit c23d3e0

6 files changed

+49
-69
lines changed

tests/test_aiohttp_online.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
@pytest.mark.aiohttp
1212
@pytest.mark.online
1313
@pytest.mark.asyncio
14-
@pytest.mark.parametrize("protocol", ["http", "https"])
15-
async def test_aiohttp_simple_query(event_loop, protocol):
14+
async def test_aiohttp_simple_query(event_loop):
1615

1716
from gql.transport.aiohttp import AIOHTTPTransport
1817

19-
# Create http or https url
20-
url = f"{protocol}://countries.trevorblades.com/graphql"
18+
# Create https url
19+
url = "https://countries.trevorblades.com/graphql"
2120

2221
# Get transport
2322
sample_transport = AIOHTTPTransport(url=url)

tests/test_client.py

+12-44
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def execute(self):
4646

4747

4848
@pytest.mark.aiohttp
49-
@pytest.mark.asyncio
5049
def test_request_async_execute_batch_not_implemented_yet():
5150
from gql.transport.aiohttp import AIOHTTPTransport
5251

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

147+
"""
148+
Batching is not supported anymore on countries backend
149+
148150
with pytest.raises(TransportQueryError) as exc_info:
149151
client.execute_batch([GraphQLRequest(document=failing_query)])
150152
assert 'Cannot query field "id" on type "Continent".' in str(exc_info.value)
151-
152-
153-
@pytest.mark.online
154-
@pytest.mark.requests
155-
def test_http_transport_raise_for_status_error(http_transport_query):
156-
from gql.transport.requests import RequestsHTTPTransport
157-
158-
with Client(
159-
transport=RequestsHTTPTransport(
160-
url="https://countries.trevorblades.com/",
161-
use_json=False,
162-
headers={"Content-type": "application/json"},
163-
)
164-
) as client:
165-
with pytest.raises(Exception) as exc_info:
166-
client.execute(http_transport_query)
167-
168-
assert "400 Client Error: Bad Request for url" in str(exc_info.value)
169-
170-
with pytest.raises(Exception) as exc_info:
171-
client.execute_batch([GraphQLRequest(document=http_transport_query)])
172-
173-
assert "400 Client Error: Bad Request for url" in str(exc_info.value)
153+
"""
174154

175155

176156
@pytest.mark.online
@@ -192,13 +172,17 @@ def test_http_transport_verify_error(http_transport_query):
192172
record[0].message
193173
)
194174

175+
"""
176+
Batching is not supported anymore on countries backend
177+
195178
with pytest.warns(Warning) as record:
196179
client.execute_batch([GraphQLRequest(document=http_transport_query)])
197180
198181
assert len(record) == 1
199182
assert "Unverified HTTPS request is being made to host" in str(
200183
record[0].message
201184
)
185+
"""
202186

203187

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

202+
"""
203+
Batching is not supported anymore on countries backend
204+
218205
result = client.execute_batch([GraphQLRequest(document=http_transport_query)])
219206
assert result is not None
220-
221-
222-
@pytest.mark.online
223-
@pytest.mark.requests
224-
def test_http_transport_specify_method_invalid(http_transport_query):
225-
from gql.transport.requests import RequestsHTTPTransport
226-
227-
with Client(
228-
transport=RequestsHTTPTransport(
229-
url="https://countries.trevorblades.com/",
230-
method="GET",
231-
)
232-
) as client:
233-
with pytest.raises(Exception) as exc_info:
234-
client.execute(http_transport_query)
235-
assert "400 Client Error: Bad Request for url" in str(exc_info.value)
236-
237-
with pytest.raises(Exception) as exc_info:
238-
client.execute_batch([GraphQLRequest(document=http_transport_query)])
239-
assert "400 Client Error: Bad Request for url" in str(exc_info.value)
207+
"""
240208

241209

242210
def test_gql():

tests/test_http_async_sync.py

+9-14
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
@pytest.mark.aiohttp
77
@pytest.mark.online
88
@pytest.mark.asyncio
9-
@pytest.mark.parametrize("protocol", ["http", "https"])
109
@pytest.mark.parametrize("fetch_schema_from_transport", [True, False])
11-
async def test_async_client_async_transport(
12-
event_loop, protocol, fetch_schema_from_transport
13-
):
10+
async def test_async_client_async_transport(event_loop, fetch_schema_from_transport):
1411

1512
from gql.transport.aiohttp import AIOHTTPTransport
1613

17-
# Create http or https url
18-
url = f"{protocol}://countries.trevorblades.com/graphql"
14+
# Create https url
15+
url = "https://countries.trevorblades.com/graphql"
1916

2017
# Get async transport
2118
sample_transport = AIOHTTPTransport(url=url)
@@ -76,14 +73,13 @@ async def test_async_client_sync_transport(event_loop, fetch_schema_from_transpo
7673

7774
@pytest.mark.aiohttp
7875
@pytest.mark.online
79-
@pytest.mark.parametrize("protocol", ["http", "https"])
8076
@pytest.mark.parametrize("fetch_schema_from_transport", [True, False])
81-
def test_sync_client_async_transport(protocol, fetch_schema_from_transport):
77+
def test_sync_client_async_transport(fetch_schema_from_transport):
8278

8379
from gql.transport.aiohttp import AIOHTTPTransport
8480

85-
# Create http or https url
86-
url = f"{protocol}://countries.trevorblades.com/graphql"
81+
# Create https url
82+
url = "https://countries.trevorblades.com/graphql"
8783

8884
# Get async transport
8985
sample_transport = AIOHTTPTransport(url=url)
@@ -120,14 +116,13 @@ def test_sync_client_async_transport(protocol, fetch_schema_from_transport):
120116

121117
@pytest.mark.requests
122118
@pytest.mark.online
123-
@pytest.mark.parametrize("protocol", ["http", "https"])
124119
@pytest.mark.parametrize("fetch_schema_from_transport", [True, False])
125-
def test_sync_client_sync_transport(protocol, fetch_schema_from_transport):
120+
def test_sync_client_sync_transport(fetch_schema_from_transport):
126121

127122
from gql.transport.requests import RequestsHTTPTransport
128123

129-
# Create http or https url
130-
url = f"{protocol}://countries.trevorblades.com/graphql"
124+
# Create https url
125+
url = "https://countries.trevorblades.com/graphql"
131126

132127
# Get sync transport
133128
sample_transport = RequestsHTTPTransport(url=url, use_json=True)

tests/test_httpx_online.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
@pytest.mark.httpx
1212
@pytest.mark.online
1313
@pytest.mark.asyncio
14-
@pytest.mark.parametrize("protocol", ["http", "https"])
15-
async def test_httpx_simple_query(event_loop, protocol):
14+
async def test_httpx_simple_query(event_loop):
1615

1716
from gql.transport.httpx import HTTPXAsyncTransport
1817

19-
# Create http or https url
20-
url = f"{protocol}://countries.trevorblades.com/graphql"
18+
# Create https url
19+
url = "https://countries.trevorblades.com/graphql"
2120

2221
# Get transport
2322
sample_transport = HTTPXAsyncTransport(url=url)

tests/test_requests_batch.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -540,15 +540,21 @@ def test_code():
540540
await run_sync_test(event_loop, server, test_code)
541541

542542

543+
ONLINE_URL = "https://countries.trevorblades.com/"
544+
545+
skip_reason = "backend does not support batching anymore..."
546+
547+
543548
@pytest.mark.online
544549
@pytest.mark.requests
550+
@pytest.mark.skip(reason=skip_reason)
545551
def test_requests_sync_batch_auto():
546552

547553
from threading import Thread
548554
from gql.transport.requests import RequestsHTTPTransport
549555

550556
client = Client(
551-
transport=RequestsHTTPTransport(url="https://countries.trevorblades.com/"),
557+
transport=RequestsHTTPTransport(url=ONLINE_URL),
552558
batch_interval=0.01,
553559
batch_max=3,
554560
)
@@ -607,12 +613,13 @@ def get_continent_name(session, continent_code):
607613

608614
@pytest.mark.online
609615
@pytest.mark.requests
616+
@pytest.mark.skip(reason=skip_reason)
610617
def test_requests_sync_batch_auto_execute_future():
611618

612619
from gql.transport.requests import RequestsHTTPTransport
613620

614621
client = Client(
615-
transport=RequestsHTTPTransport(url="https://countries.trevorblades.com/"),
622+
transport=RequestsHTTPTransport(url=ONLINE_URL),
616623
batch_interval=0.01,
617624
batch_max=3,
618625
)
@@ -644,12 +651,13 @@ def test_requests_sync_batch_auto_execute_future():
644651

645652
@pytest.mark.online
646653
@pytest.mark.requests
654+
@pytest.mark.skip(reason=skip_reason)
647655
def test_requests_sync_batch_manual():
648656

649657
from gql.transport.requests import RequestsHTTPTransport
650658

651659
client = Client(
652-
transport=RequestsHTTPTransport(url="https://countries.trevorblades.com/"),
660+
transport=RequestsHTTPTransport(url=ONLINE_URL),
653661
)
654662

655663
query = gql(

tests/test_websocket_online.py

+11
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@
1515

1616
logging.basicConfig(level=logging.INFO)
1717

18+
skip_reason = (
19+
"backend does not support websockets anymore: "
20+
"https://github.com/trevorblades/countries/issues/42"
21+
)
22+
1823

1924
@pytest.mark.online
25+
@pytest.mark.skip(reason=skip_reason)
2026
@pytest.mark.asyncio
2127
async def test_websocket_simple_query():
2228
from gql.transport.websockets import WebsocketsTransport
@@ -57,6 +63,7 @@ async def test_websocket_simple_query():
5763

5864

5965
@pytest.mark.online
66+
@pytest.mark.skip(reason=skip_reason)
6067
@pytest.mark.asyncio
6168
async def test_websocket_invalid_query():
6269
from gql.transport.websockets import WebsocketsTransport
@@ -86,6 +93,7 @@ async def test_websocket_invalid_query():
8693

8794

8895
@pytest.mark.online
96+
@pytest.mark.skip(reason=skip_reason)
8997
@pytest.mark.asyncio
9098
async def test_websocket_sending_invalid_data():
9199
from gql.transport.websockets import WebsocketsTransport
@@ -121,6 +129,7 @@ async def test_websocket_sending_invalid_data():
121129

122130

123131
@pytest.mark.online
132+
@pytest.mark.skip(reason=skip_reason)
124133
@pytest.mark.asyncio
125134
async def test_websocket_sending_invalid_payload():
126135
from gql.transport.websockets import WebsocketsTransport
@@ -143,6 +152,7 @@ async def test_websocket_sending_invalid_payload():
143152

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

195205
@pytest.mark.online
196206
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
207+
@pytest.mark.skip(reason=skip_reason)
197208
@pytest.mark.asyncio
198209
async def test_websocket_two_queries_in_parallel_using_two_tasks():
199210
from gql.transport.websockets import WebsocketsTransport

0 commit comments

Comments
 (0)