Skip to content

Commit 7dc8e86

Browse files
committed
fix(tests): upgrade pytest-httpx
Signed-off-by: Fatih Acar <[email protected]>
1 parent 3de4ab8 commit 7dc8e86

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

tests/unit/sdk/checks/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ async def mock_gql_query_my_query(httpx_mock: HTTPXMock) -> HTTPXMock:
1717
method="POST",
1818
json=response,
1919
url="http://localhost:8000/api/query/my_query?branch=main&update_group=false",
20+
is_reusable=True,
2021
)
2122
return httpx_mock

tests/unit/sdk/conftest.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,7 @@ async def mock_branches_list_query(httpx_mock: HTTPXMock) -> HTTPXMock:
14671467
method="POST",
14681468
json=response,
14691469
match_headers={"X-Infrahub-Tracker": "query-branch-all"},
1470+
is_reusable=True,
14701471
)
14711472
return httpx_mock
14721473

@@ -1599,8 +1600,8 @@ async def mock_repositories_query(httpx_mock: HTTPXMock) -> HTTPXMock:
15991600
}
16001601
}
16011602

1602-
httpx_mock.add_response(method="POST", url="http://mock/graphql/main", json=response1)
1603-
httpx_mock.add_response(method="POST", url="http://mock/graphql/cr1234", json=response2)
1603+
httpx_mock.add_response(method="POST", url="http://mock/graphql/main", json=response1, is_reusable=True)
1604+
httpx_mock.add_response(method="POST", url="http://mock/graphql/cr1234", json=response2, is_reusable=True)
16041605
return httpx_mock
16051606

16061607

@@ -1640,6 +1641,7 @@ async def mock_query_repository_page1_1(
16401641
method="POST",
16411642
json=response,
16421643
match_headers={"X-Infrahub-Tracker": "query-corerepository-page1"},
1644+
is_reusable=True,
16431645
)
16441646
return httpx_mock
16451647

@@ -1743,6 +1745,7 @@ async def mock_query_repository_page1_2(
17431745
method="POST",
17441746
json=response,
17451747
match_headers={"X-Infrahub-Tracker": "query-corerepository-page1"},
1748+
is_reusable=True,
17461749
)
17471750
return httpx_mock
17481751

@@ -1783,6 +1786,7 @@ async def mock_query_repository_page2_2(
17831786
method="POST",
17841787
json=response,
17851788
match_headers={"X-Infrahub-Tracker": "query-corerepository-page2"},
1789+
is_reusable=True,
17861790
)
17871791
return httpx_mock
17881792

@@ -1795,6 +1799,7 @@ async def mock_schema_query_01(httpx_mock: HTTPXMock) -> HTTPXMock:
17951799
method="GET",
17961800
url="http://mock/api/schema?branch=main",
17971801
json=ujson.loads(response_text),
1802+
is_reusable=True,
17981803
)
17991804
return httpx_mock
18001805

@@ -1803,7 +1808,10 @@ async def mock_schema_query_01(httpx_mock: HTTPXMock) -> HTTPXMock:
18031808
async def mock_schema_query_02(httpx_mock: HTTPXMock) -> HTTPXMock:
18041809
response_text = (get_fixtures_dir() / "schema_02.json").read_text(encoding="UTF-8")
18051810
httpx_mock.add_response(
1806-
method="GET", url=re.compile(r"^http://mock/api/schema\?branch=(main|cr1234)"), json=ujson.loads(response_text)
1811+
method="GET",
1812+
url=re.compile(r"^http://mock/api/schema\?branch=(main|cr1234)"),
1813+
json=ujson.loads(response_text),
1814+
is_reusable=True,
18071815
)
18081816
return httpx_mock
18091817

@@ -2141,14 +2149,14 @@ async def mock_query_mutation_location_create_failed(httpx_mock: HTTPXMock) -> H
21412149

21422150
@pytest.fixture
21432151
async def mock_query_infrahub_version(httpx_mock: HTTPXMock) -> HTTPXMock:
2144-
httpx_mock.add_response(method="POST", json={"data": {"InfrahubInfo": {"version": "1.1.0"}}})
2152+
httpx_mock.add_response(method="POST", json={"data": {"InfrahubInfo": {"version": "1.1.0"}}}, is_reusable=True)
21452153
return httpx_mock
21462154

21472155

21482156
@pytest.fixture
21492157
async def mock_query_infrahub_user(httpx_mock: HTTPXMock) -> HTTPXMock:
21502158
response_text = (get_fixtures_dir() / "account_profile.json").read_text(encoding="UTF-8")
2151-
httpx_mock.add_response(method="POST", json=ujson.loads(response_text))
2159+
httpx_mock.add_response(method="POST", json=ujson.loads(response_text), is_reusable=True)
21522160
return httpx_mock
21532161

21542162

@@ -2492,7 +2500,7 @@ async def mock_query_location_batch_count(
24922500
httpx_mock: HTTPXMock, client: InfrahubClient, mock_schema_query_01
24932501
) -> HTTPXMock:
24942502
response = {"data": {"BuiltinLocation": {"count": 30}}}
2495-
httpx_mock.add_response(method="POST", url="http://mock/graphql/main", json=response)
2503+
httpx_mock.add_response(method="POST", url="http://mock/graphql/main", json=response, is_reusable=True)
24962504
return httpx_mock
24972505

24982506

@@ -2505,6 +2513,7 @@ async def mock_query_location_batch(httpx_mock: HTTPXMock, client: InfrahubClien
25052513
method="POST",
25062514
json=ujson.loads(response_text),
25072515
match_headers={"X-Infrahub-Tracker": f"query-builtinlocation-page{i}"},
2516+
is_reusable=True,
25082517
)
25092518
return httpx_mock
25102519

tests/unit/sdk/test_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ async def test_method_get_by_id(httpx_mock: HTTPXMock, clients, mock_schema_quer
243243
method="POST",
244244
json=response,
245245
match_headers={"X-Infrahub-Tracker": "query-corerepository-page1"},
246+
is_reusable=True,
246247
)
247248

248249
if client_type == "standard":
@@ -291,6 +292,7 @@ async def test_method_get_by_hfid(httpx_mock: HTTPXMock, clients, mock_schema_qu
291292
method="POST",
292293
json=response,
293294
match_headers={"X-Infrahub-Tracker": "query-corerepository-page1"},
295+
is_reusable=True,
294296
)
295297

296298
if client_type == "standard":
@@ -338,6 +340,7 @@ async def test_method_get_by_default_filter(httpx_mock: HTTPXMock, clients, mock
338340
method="POST",
339341
json=response,
340342
match_headers={"X-Infrahub-Tracker": "query-corerepository-page1"},
343+
is_reusable=True,
341344
)
342345

343346
if client_type == "standard":

0 commit comments

Comments
 (0)