Skip to content

Commit 003fb3a

Browse files
committed
Add simple test for coverage
1 parent 88d0217 commit 003fb3a

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

tests/unit/sdk/test_client.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pytest_httpx import HTTPXMock
55

66
from infrahub_sdk import InfrahubClient, InfrahubClientSync
7-
from infrahub_sdk.exceptions import NodeNotFoundError
7+
from infrahub_sdk.exceptions import GraphQLError, NodeNotFoundError
88
from infrahub_sdk.node import InfrahubNode, InfrahubNodeSync
99
from tests.unit.sdk.conftest import BothClients
1010

@@ -800,3 +800,35 @@ async def test_clone_define_branch(clients: BothClients, client_type: str) -> No
800800
assert clone.default_branch == clone_branch
801801
assert original_branch != clone_branch
802802
assert clone.store._default_branch == clone_branch
803+
804+
805+
@pytest.mark.parametrize("client_type", client_types)
806+
async def test_execute_graphql_error(httpx_mock: HTTPXMock, clients, client_type) -> None:
807+
httpx_mock.add_response(method="POST", json={"errors": ["foo"]}, is_reusable=True)
808+
809+
query = """
810+
query GetTags {
811+
BuiltinTag {
812+
edges {
813+
node {
814+
id
815+
display_label
816+
}
817+
}
818+
}
819+
}
820+
"""
821+
822+
if client_type == "standard":
823+
with pytest.raises(GraphQLError):
824+
await clients.standard.execute_graphql(query=query, raise_for_error=True)
825+
826+
response = await clients.standard.execute_graphql(query=query, raise_for_error=False)
827+
else:
828+
with pytest.raises(GraphQLError):
829+
clients.sync.execute_graphql(query=query, raise_for_error=True)
830+
831+
response = clients.sync.execute_graphql(query=query, raise_for_error=False)
832+
833+
assert response
834+
assert response[0] == "foo"

0 commit comments

Comments
 (0)