Skip to content

Commit ce32e85

Browse files
committed
add test with passing additional aiohttp parameters, remove potential headers key conflict in passing arguments
1 parent f78daba commit ce32e85

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

python_graphql_client/graphql_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ async def execute_async(
7272
async with session.post(
7373
self.endpoint,
7474
json=request_body,
75-
headers={**self.headers, **headers},
76-
**{**self.options, **kwargs},
75+
**{**self.options, **kwargs, "headers": {**self.headers, **headers}},
7776
) as response:
7877
return await response.json()
7978

tests/test_graphql_client.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,34 @@ async def test_execute_basic_query(self, mock_post):
171171
"http://www.test-api.com/", json={"query": query}, headers={}
172172
)
173173

174+
@patch("aiohttp.ClientSession.post")
175+
async def test_execute_basic_query_with_aiohttp_parameters(self, mock_post):
176+
"""Sends a graphql POST request to an endpoint."""
177+
mock_post.return_value.__aenter__.return_value.json = AsyncMock()
178+
client = GraphqlClient(endpoint="http://www.test-api.com/")
179+
query = """
180+
{
181+
tests {
182+
status
183+
}
184+
}
185+
"""
186+
187+
await client.execute_async(
188+
query,
189+
timeout=10,
190+
verify_ssl=False,
191+
headers={"Authorization": "Bearer token"},
192+
)
193+
194+
mock_post.assert_called_once_with(
195+
"http://www.test-api.com/",
196+
json={"query": query},
197+
headers={"Authorization": "Bearer token"},
198+
timeout=10,
199+
verify_ssl=False,
200+
)
201+
174202
@patch("aiohttp.ClientSession.post")
175203
async def test_execute_query_with_variables(self, mock_post):
176204
"""Sends a graphql POST request with variables."""

0 commit comments

Comments
 (0)