2
3
from unittest.mock import Mock
4
5
+import httpx
6
import pytest
6
-
7
+from composio.client import HttpClient
8
from composio.client.types import (
9
auth_config_create_response,
10
+ auth_config_delete_response,
11
auth_config_list_response,
12
auth_config_retrieve_response,
13
+ auth_config_update_response,
14
+ auth_config_update_status_response,
15
)
16
from composio.core.models.auth_configs import AuthConfigs
17
+from pydantic import BaseModel
18
19
20
class TestAuthConfigs:
271
self, auth_configs, mock_client
272
):
273
"""Test updating custom auth config with credentials."""
269
- mock_response = {"id": "auth_12345", "status": "success"}
274
+ mock_response = auth_config_update_response.AuthConfigUpdateResponse(
275
+ success=True, message="Successfully updated auth config"
276
+ )
277
mock_client.auth_configs.update.return_value = mock_response
278
279
options = {
295
296
def test_update_default_auth_config_with_scopes(self, auth_configs, mock_client):
297
"""Test updating default auth config with scopes."""
291
- mock_response = {"id": "auth_12345", "status": "success"}
298
+ mock_response = auth_config_update_response.AuthConfigUpdateResponse(
299
+ success=True, message="Successfully updated auth config"
300
+ )
301
mock_client.auth_configs.update.return_value = mock_response
302
303
options = {
316
317
def test_update_with_is_enabled_for_tool_router(self, auth_configs, mock_client):
318
"""Test updating auth config with isEnabledForToolRouter."""
310
- mock_response = {"id": "auth_12345", "status": "success"}
319
+ mock_response = auth_config_update_response.AuthConfigUpdateResponse(
320
+ success=True, message="Successfully updated auth config"
321
+ )
322
mock_client.auth_configs.update.return_value = mock_response
323
324
options = {
335
336
def test_update_with_tool_access_config(self, auth_configs, mock_client):
337
"""Test updating auth config with tool access configuration."""
327
- mock_response = {"id": "auth_12345", "status": "success"}
338
+ mock_response = auth_config_update_response.AuthConfigUpdateResponse(
339
+ success=True, message="Successfully updated auth config"
340
+ )
341
mock_client.auth_configs.update.return_value = mock_response
342
343
options = {
356
357
def test_update_with_large_credential_object(self, auth_configs, mock_client):
358
"""Test updating auth config with large credential object."""
346
- mock_response = {"id": "auth_12345", "status": "success"}
359
+ mock_response = auth_config_update_response.AuthConfigUpdateResponse(
360
+ success=True, message="Successfully updated auth config"
361
+ )
362
mock_client.auth_configs.update.return_value = mock_response
363
364
large_credentials = {
398
# Delete tests
399
def test_delete_auth_config_by_id(self, auth_configs, mock_client):
400
"""Test deleting auth config by ID."""
386
- mock_response = {"id": "auth_12345", "status": "deleted"}
401
+ mock_response = auth_config_delete_response.AuthConfigDeleteResponse(
402
+ success=True, message="Successfully deleted auth config"
403
+ )
404
mock_client.auth_configs.delete.return_value = mock_response
405
406
result = auth_configs.delete("auth_12345")
420
# Enable/Disable tests
421
def test_enable_auth_config(self, auth_configs, mock_client):
422
"""Test enabling auth config."""
406
- mock_response = {"id": "auth_12345", "status": "ENABLED"}
423
+ mock_response = (
424
+ auth_config_update_status_response.AuthConfigUpdateStatusResponse(
425
+ success=True, message="Successfully updated auth config status"
426
+ )
427
+ )
428
mock_client.auth_configs.update_status.return_value = mock_response
429
430
result = auth_configs.enable("auth_12345")
436
437
def test_disable_auth_config(self, auth_configs, mock_client):
438
"""Test disabling auth config."""
418
- mock_response = {"id": "auth_12345", "status": "DISABLED"}
439
+ mock_response = (
440
+ auth_config_update_status_response.AuthConfigUpdateStatusResponse(
441
+ success=True, message="Successfully updated auth config status"
442
+ )
443
+ )
444
mock_client.auth_configs.update_status.return_value = mock_response
445
446
result = auth_configs.disable("auth_12345")
471
# Edge cases
472
def test_update_with_missing_optional_fields(self, auth_configs, mock_client):
473
"""Test update works with only required fields."""
449
- mock_response = {"id": "auth_12345", "status": "success"}
474
+ mock_response = auth_config_update_response.AuthConfigUpdateResponse(
475
+ success=True, message="Successfully updated auth config"
476
+ )
477
mock_client.auth_configs.update.return_value = mock_response
478
479
options = {
592
593
def test_update_overload_custom_type(self, auth_configs, mock_client):
594
"""Test update with custom type."""
568
- mock_response = {"id": "auth_12345", "status": "success"}
595
+ mock_response = auth_config_update_response.AuthConfigUpdateResponse(
596
+ success=True, message="Successfully updated auth config"
597
+ )
598
mock_client.auth_configs.update.return_value = mock_response
599
600
options = {
607
608
def test_update_overload_default_type(self, auth_configs, mock_client):
609
"""Test update with default type."""
581
- mock_response = {"id": "auth_12345", "status": "success"}
610
+ mock_response = auth_config_update_response.AuthConfigUpdateResponse(
611
+ success=True, message="Successfully updated auth config"
612
+ )
613
mock_client.auth_configs.update.return_value = mock_response
614
615
options = {
619
result = auth_configs.update("auth_12345", options=options)
620
621
assert result == mock_response
622
+
623
+
624
+@pytest.mark.parametrize(
625
+ ("operation", "method", "path", "response_type"),
626
+ [
627
+ (
628
+ "update_custom",
629
+ "PATCH",
630
+ "/api/v3.1/auth_configs/ac_test",
631
+ auth_config_update_response.AuthConfigUpdateResponse,
632
+ ),
633
+ (
634
+ "update_default",
635
+ "PATCH",
636
+ "/api/v3.1/auth_configs/ac_test",
637
+ auth_config_update_response.AuthConfigUpdateResponse,
638
+ ),
639
+ (
640
+ "delete",
641
+ "DELETE",
642
+ "/api/v3.1/auth_configs/ac_test",
643
+ auth_config_delete_response.AuthConfigDeleteResponse,
644
+ ),
645
+ (
646
+ "enable",
647
+ "PATCH",
648
+ "/api/v3.1/auth_configs/ac_test/ENABLED",
649
+ auth_config_update_status_response.AuthConfigUpdateStatusResponse,
650
+ ),
651
+ (
652
+ "disable",
653
+ "PATCH",
654
+ "/api/v3.1/auth_configs/ac_test/DISABLED",
655
+ auth_config_update_status_response.AuthConfigUpdateStatusResponse,
656
+ ),
657
+ ],
658
+)
659
+def test_mutation_response_through_generated_client(
660
+ operation, method, path, response_type
661
+):
662
+ """Parse HTTP through the real client instead of mocking its return value."""
663
+ payload = {"success": True, "message": "Successfully updated auth config"}
664
+ requests = []
665
+
666
+ def handler(request: httpx.Request) -> httpx.Response:
667
+ requests.append(request)
668
+ return httpx.Response(200, json=payload)
669
+
670
+ with HttpClient(
671
+ provider="test",
672
+ api_key="test",
673
+ _environment_variables={},
674
+ http_client=httpx.Client(transport=httpx.MockTransport(handler)),
675
+ ) as client:
676
+ auth_configs = AuthConfigs(client)
677
+ calls = {
678
+ "update_custom": lambda: auth_configs.update(
679
+ "ac_test",
680
+ options={"type": "custom", "credentials": {"scopes": "read:user"}},
681
+ ),
682
+ "update_default": lambda: auth_configs.update(
683
+ "ac_test",
684
+ options={"type": "default", "is_enabled_for_tool_router": True},
685
+ ),
686
+ "delete": lambda: auth_configs.delete("ac_test"),
687
+ "enable": lambda: auth_configs.enable("ac_test"),
688
+ "disable": lambda: auth_configs.disable("ac_test"),
689
+ }
690
+ result = calls[operation]()
691
+
692
+ assert len(requests) == 1
693
+ assert requests[0].method == method
694
+ assert requests[0].url.path == path
695
+ assert isinstance(result, response_type)
696
+ assert isinstance(result, BaseModel)
697
+ assert result.success is True
698
+ assert result.message == payload["message"]
699
+ assert result.model_dump(exclude_unset=True) == payload