|
13 | 13 | from PowerPlatform.Dataverse.aio.operations.async_files import AsyncFileOperations |
14 | 14 | from PowerPlatform.Dataverse.aio.operations.async_dataframe import AsyncDataFrameOperations |
15 | 15 | from PowerPlatform.Dataverse.aio.operations.async_batch import AsyncBatchOperations |
| 16 | +from PowerPlatform.Dataverse.core.config import DataverseConfig, OperationContext |
16 | 17 |
|
17 | 18 |
|
18 | 19 | def _make_credential() -> MagicMock: |
@@ -204,3 +205,37 @@ async def test_scoped_odata_raises_when_closed(self): |
204 | 205 | with pytest.raises(RuntimeError, match="closed"): |
205 | 206 | async with client._scoped_odata(): |
206 | 207 | 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