Skip to content

Commit e4ffc8f

Browse files
aurelienlombardAurélien Lombard
andauthored
test(LAB-3399): remove graphql client tests that needs to connect to … (#1843)
Co-authored-by: Aurélien Lombard <aurelien.lombard@kili-technology.com>
1 parent fb90304 commit e4ffc8f

2 files changed

Lines changed: 10 additions & 140 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ jobs:
99
- uses: actions/setup-python@v5
1010
with:
1111
python-version: 3.8
12-
cache: 'pip'
12+
cache: "pip"
1313
- uses: pre-commit/action@v3.0.1
1414

1515
pylint:
1616
runs-on: ubuntu-latest
1717
name: Pylint test
1818
strategy:
1919
matrix:
20-
python-version: ['3.8', '3.12']
20+
python-version: ["3.8", "3.12"]
2121
steps:
2222
- uses: actions/checkout@v4
2323
- name: Set up Python ${{ matrix.python-version }}
2424
uses: actions/setup-python@v5
2525
with:
2626
python-version: ${{ matrix.python-version }}
27-
cache: 'pip'
27+
cache: "pip"
2828
- name: Install dependencies
2929
run: |
3030
python -m pip install --upgrade pip
@@ -37,13 +37,13 @@ jobs:
3737
runs-on: ubuntu-latest
3838
strategy:
3939
matrix:
40-
version: ['3.8', '3.12']
40+
version: ["3.8", "3.12"]
4141
steps:
4242
- uses: actions/checkout@v4
4343
- uses: actions/setup-python@v5
4444
with:
4545
python-version: ${{ matrix.version }}
46-
cache: 'pip'
46+
cache: "pip"
4747
- name: Install dependencies
4848
run: |
4949
python -m pip install --upgrade pip
@@ -72,15 +72,15 @@ jobs:
7272
uses: actions/setup-python@v5
7373
with:
7474
python-version: ${{ matrix.python-version }}
75-
cache: 'pip'
75+
cache: "pip"
7676

7777
- name: Install dependencies
7878
run: |
7979
python -m pip install --upgrade pip
8080
pip install -e ".[dev]"
8181
8282
- name: Unit and integration tests
83-
run: pytest -n auto -ra -sv --color yes --code-highlight yes --durations=15 -vv --ignore tests/e2e/ --cov=src/kili --cov-report=term-missing --cov-config=.coveragerc --cov-fail-under=82.99
83+
run: pytest -n auto -ra -sv --color yes --code-highlight yes --durations=15 -vv --ignore tests/e2e/ --cov=src/kili --cov-report=term-missing --cov-config=.coveragerc --cov-fail-under=82
8484

8585
markdown-link-check:
8686
timeout-minutes: 10
@@ -102,7 +102,7 @@ jobs:
102102
uses: actions/setup-python@v5
103103
with:
104104
python-version: 3.8
105-
cache: 'pip'
105+
cache: "pip"
106106

107107
- name: Install dependencies
108108
run: |
@@ -132,7 +132,7 @@ jobs:
132132
uses: actions/setup-python@v5
133133
with:
134134
python-version: 3.8
135-
cache: 'pip'
135+
cache: "pip"
136136

137137
- name: Install dependencies
138138
run: |
@@ -163,7 +163,7 @@ jobs:
163163
uses: actions/setup-python@v5
164164
with:
165165
python-version: 3.8
166-
cache: 'pip'
166+
cache: "pip"
167167

168168
- name: Install dependencies
169169
run: |

tests/unit/test_graphql_client.py

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import os
2-
from pathlib import Path
3-
from tempfile import TemporaryDirectory
42
from time import time
53
from typing import Dict
6-
from unittest import mock
74

8-
import graphql
95
import pytest
106
import pytest_mock
117
from gql import Client
@@ -35,88 +31,6 @@ def test_graphql_client_cache_cant_get_kili_version(mocker):
3531
)
3632

3733

38-
@pytest.mark.parametrize(
39-
"query",
40-
[
41-
"query MyQuery { my_query_is_clearly_not_valid_according_to_the_kili_schema { id } }",
42-
"query { projects { this_field_does_not_exist } }",
43-
],
44-
)
45-
def test_gql_bad_query_local_validation(query, mocker):
46-
"""Test gql validation against local schema."""
47-
api_endpoint = os.getenv(
48-
"KILI_API_ENDPOINT", "https://cloud.kili-technology.com/api/label/v2/graphql"
49-
)
50-
51-
# we need to remove "Authorization" api key from the header
52-
# if not, the backend will refuse the introspection query
53-
mocker.patch.object(GraphQLClient, "_get_headers", return_value={})
54-
55-
client = GraphQLClient(
56-
endpoint=api_endpoint,
57-
api_key="",
58-
client_name=GraphQLClientName.SDK,
59-
verify=True,
60-
http_client=HttpClient(
61-
kili_endpoint="https://fake_endpoint.kili-technology.com", api_key="", verify=True
62-
),
63-
)
64-
65-
with pytest.raises(GraphQLError) as exc_info:
66-
client.execute(query)
67-
68-
assert isinstance(exc_info.value.__cause__, graphql.GraphQLError)
69-
70-
71-
def test_graphql_client_cache(mocker):
72-
with TemporaryDirectory() as temp_dir:
73-
schema_path = Path(temp_dir) / "schema.graphql"
74-
mocker.patch.object(GraphQLClient, "_get_graphql_schema_path", return_value=schema_path)
75-
76-
api_endpoint = os.getenv(
77-
"KILI_API_ENDPOINT", "https://cloud.kili-technology.com/api/label/v2/graphql"
78-
)
79-
80-
# we need to remove "Authorization" api key from the header
81-
# if not, the backend will refuse the introspection query
82-
mocker.patch.object(GraphQLClient, "_get_headers", return_value={})
83-
84-
# initialize a client with schema caching enabled
85-
_ = GraphQLClient(
86-
endpoint=api_endpoint,
87-
api_key="",
88-
client_name=GraphQLClientName.SDK,
89-
verify=True,
90-
http_client=HttpClient(
91-
kili_endpoint="https://fake_endpoint.kili-technology.com", api_key="", verify=True
92-
),
93-
enable_schema_caching=True,
94-
graphql_schema_cache_dir=temp_dir,
95-
)
96-
97-
# schema should be cached
98-
files_in_cache_dir = list(schema_path.parent.glob("*"))
99-
assert schema_path.is_file(), f"{files_in_cache_dir}, {schema_path}"
100-
assert schema_path.stat().st_size > 0
101-
102-
# check that the schema is not fetched again when we initialize a new client
103-
with mock.patch("kili.core.graphql.graphql_client.print_schema") as mocked_print_schema:
104-
_ = GraphQLClient(
105-
endpoint=api_endpoint,
106-
api_key="",
107-
client_name=GraphQLClientName.SDK,
108-
verify=True,
109-
http_client=HttpClient(
110-
kili_endpoint="https://fake_endpoint.kili-technology.com",
111-
api_key="",
112-
verify=True,
113-
),
114-
enable_schema_caching=True,
115-
graphql_schema_cache_dir=temp_dir,
116-
)
117-
mocked_print_schema.assert_not_called()
118-
119-
12034
def test_schema_caching_requires_cache_dir():
12135
with pytest.raises(
12236
Exception, match="must specify a cache directory if you want to enable schema caching"
@@ -190,50 +104,6 @@ def mock_execute(*args, **kwargs):
190104
assert last_call_timestamp - before_last_call_timestamp > 1
191105

192106

193-
def test_given_gql_client_when_i_send_wrong_query_then_it_refreshes_the_schema_and_retry_once_only(
194-
mocker: pytest_mock.MockerFixture,
195-
):
196-
api_endpoint = os.getenv(
197-
"KILI_API_ENDPOINT", "https://cloud.kili-technology.com/api/label/v2/graphql"
198-
)
199-
200-
# we need to remove "Authorization" api key from the header
201-
# if not, the backend will refuse the introspection query
202-
mocker.patch.object(GraphQLClient, "_get_headers", return_value={})
203-
204-
gql_execute_spy = mocker.spy(Client, "execute")
205-
206-
# Given
207-
client = GraphQLClient(
208-
endpoint=api_endpoint,
209-
api_key="",
210-
client_name=GraphQLClientName.SDK,
211-
http_client=HttpClient(
212-
kili_endpoint="https://fake_endpoint.kili-technology.com", api_key="", verify=True
213-
),
214-
enable_schema_caching=True,
215-
)
216-
217-
# When I send wrong query, the local validation fails
218-
# the client fetches a fresh schema from the backend
219-
# and we retry the query once only
220-
with pytest.raises(
221-
GraphQLError,
222-
match=(
223-
'GraphQL error: "Cannot query field'
224-
" 'my_query_is_clearly_not_valid_according_to_the_kili_schema'"
225-
),
226-
):
227-
client.execute(
228-
query=(
229-
"query MyQuery { my_query_is_clearly_not_valid_according_to_the_kili_schema {"
230-
" id } }"
231-
)
232-
)
233-
234-
assert gql_execute_spy.call_count == 2 # first call + one retry
235-
236-
237107
def test_given_gql_client_when_the_server_refuses_wrong_query_then_it_does_no_retry(
238108
mocker: pytest_mock.MockerFixture,
239109
):

0 commit comments

Comments
 (0)