Skip to content

Commit 1f82219

Browse files
Abel Milashclaude
andcommitted
Add AsyncDataverseClient context= kwarg tests
Mirror TestOperationContextClient from test_operation_context.py: - context= kwarg stores OperationContext in _config - no context= leaves operation_context as None - config= + context= together raise ValueError - config= alone wires operation_context correctly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent dce049e commit 1f82219

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

tests/unit/aio/test_async_client.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from PowerPlatform.Dataverse.aio.operations.async_files import AsyncFileOperations
1414
from PowerPlatform.Dataverse.aio.operations.async_dataframe import AsyncDataFrameOperations
1515
from PowerPlatform.Dataverse.aio.operations.async_batch import AsyncBatchOperations
16+
from PowerPlatform.Dataverse.core.config import DataverseConfig, OperationContext
1617

1718

1819
def _make_credential() -> MagicMock:
@@ -204,3 +205,37 @@ async def test_scoped_odata_raises_when_closed(self):
204205
with pytest.raises(RuntimeError, match="closed"):
205206
async with client._scoped_odata():
206207
pass
208+
209+
210+
class TestAsyncDataverseClientOperationContext:
211+
"""Tests for the context= kwarg on AsyncDataverseClient."""
212+
213+
def test_context_kwarg_sets_config(self):
214+
"""context= stores OperationContext in _config.operation_context."""
215+
ctx = OperationContext(user_agent_context="app=test/1.0;agent=claude-code")
216+
client = AsyncDataverseClient("https://org.crm.dynamics.com", _make_credential(), context=ctx)
217+
assert client._config.operation_context.user_agent_context == "app=test/1.0;agent=claude-code"
218+
219+
def test_no_context_leaves_config_default(self):
220+
"""Without context=, operation_context defaults to None."""
221+
client = AsyncDataverseClient("https://org.crm.dynamics.com", _make_credential())
222+
assert client._config.operation_context is None
223+
224+
def test_config_and_context_raises(self):
225+
"""Providing both config= and context= raises ValueError."""
226+
ctx = OperationContext(user_agent_context="app=test/1.0")
227+
config = DataverseConfig(operation_context=ctx)
228+
with pytest.raises(ValueError, match="config.*context|context.*config"):
229+
AsyncDataverseClient(
230+
"https://org.crm.dynamics.com",
231+
_make_credential(),
232+
config=config,
233+
context=OperationContext(user_agent_context="app=other/2.0"),
234+
)
235+
236+
def test_config_alone_works(self):
237+
"""Providing config= without context= uses config's operation_context."""
238+
ctx = OperationContext(user_agent_context="app=test/1.0;skill=dv")
239+
config = DataverseConfig(operation_context=ctx)
240+
client = AsyncDataverseClient("https://org.crm.dynamics.com", _make_credential(), config=config)
241+
assert client._config.operation_context.user_agent_context == "app=test/1.0;skill=dv"

0 commit comments

Comments
 (0)