|
4 | 4 |
|
5 | 5 | from tests.generated_helpers import load_fixture |
6 | 6 |
|
7 | | -from workos.common.models import AuthMethodMismatchError |
| 7 | +from workos.common.models import ( |
| 8 | + ConnectApplicationM2M, |
| 9 | + ConnectApplicationOAuth, |
| 10 | + ConnectApplicationOAuthRedirectUris, |
| 11 | +) |
8 | 12 |
|
9 | 13 |
|
10 | 14 | class TestModelRoundTrip: |
11 | | - def test_auth_method_mismatch_error_round_trip(self): |
12 | | - data = load_fixture("auth_method_mismatch_error.json") |
13 | | - instance = AuthMethodMismatchError.from_dict(data) |
| 15 | + def test_connect_application_oauth_round_trip(self): |
| 16 | + data = load_fixture("connect_application_oauth.json") |
| 17 | + instance = ConnectApplicationOAuth.from_dict(data) |
14 | 18 | serialized = instance.to_dict() |
15 | 19 | assert serialized == data |
16 | | - restored = AuthMethodMismatchError.from_dict(serialized) |
| 20 | + restored = ConnectApplicationOAuth.from_dict(serialized) |
17 | 21 | assert restored.to_dict() == serialized |
18 | 22 |
|
19 | | - def test_auth_method_mismatch_error_minimal_payload(self): |
| 23 | + def test_connect_application_oauth_minimal_payload(self): |
20 | 24 | data = { |
21 | | - "code": "auth_method_mismatch", |
22 | | - "message": "This installation uses oauth authentication. Use the POST /:slug/token endpoint instead.", |
| 25 | + "object": "connect_application", |
| 26 | + "id": "conn_app_01HXYZ123456789ABCDEFGHIJ", |
| 27 | + "client_id": "client_01HXYZ123456789ABCDEFGHIJ", |
| 28 | + "description": None, |
| 29 | + "name": "My Application", |
| 30 | + "scopes": ["openid", "profile", "email"], |
| 31 | + "created_at": "2026-01-15T12:00:00.000Z", |
| 32 | + "updated_at": "2026-01-15T12:00:00.000Z", |
| 33 | + "application_type": "oauth", |
| 34 | + "redirect_uris": [{"uri": "https://example.com/callback", "default": True}], |
| 35 | + "uses_pkce": True, |
| 36 | + "is_first_party": True, |
23 | 37 | } |
24 | | - instance = AuthMethodMismatchError.from_dict(data) |
| 38 | + instance = ConnectApplicationOAuth.from_dict(data) |
25 | 39 | serialized = instance.to_dict() |
26 | | - assert serialized["code"] == data["code"] |
27 | | - assert serialized["message"] == data["message"] |
| 40 | + assert serialized["object"] == data["object"] |
| 41 | + assert serialized["id"] == data["id"] |
| 42 | + assert serialized["client_id"] == data["client_id"] |
| 43 | + assert serialized["description"] == data["description"] |
| 44 | + assert serialized["name"] == data["name"] |
| 45 | + assert serialized["scopes"] == data["scopes"] |
| 46 | + assert serialized["created_at"] == data["created_at"] |
| 47 | + assert serialized["updated_at"] == data["updated_at"] |
| 48 | + assert serialized["application_type"] == data["application_type"] |
| 49 | + assert serialized["redirect_uris"] == data["redirect_uris"] |
| 50 | + assert serialized["uses_pkce"] == data["uses_pkce"] |
| 51 | + assert serialized["is_first_party"] == data["is_first_party"] |
| 52 | + |
| 53 | + def test_connect_application_oauth_omits_absent_optional_non_nullable_fields(self): |
| 54 | + data = { |
| 55 | + "object": "connect_application", |
| 56 | + "id": "conn_app_01HXYZ123456789ABCDEFGHIJ", |
| 57 | + "client_id": "client_01HXYZ123456789ABCDEFGHIJ", |
| 58 | + "description": "An application for managing user access", |
| 59 | + "name": "My Application", |
| 60 | + "scopes": ["openid", "profile", "email"], |
| 61 | + "created_at": "2026-01-15T12:00:00.000Z", |
| 62 | + "updated_at": "2026-01-15T12:00:00.000Z", |
| 63 | + "application_type": "oauth", |
| 64 | + "redirect_uris": [{"uri": "https://example.com/callback", "default": True}], |
| 65 | + "uses_pkce": True, |
| 66 | + "is_first_party": True, |
| 67 | + } |
| 68 | + instance = ConnectApplicationOAuth.from_dict(data) |
| 69 | + serialized = instance.to_dict() |
| 70 | + assert "was_dynamically_registered" not in serialized |
| 71 | + assert "organization_id" not in serialized |
| 72 | + |
| 73 | + def test_connect_application_oauth_preserves_nullable_fields(self): |
| 74 | + data = { |
| 75 | + "object": "connect_application", |
| 76 | + "id": "conn_app_01HXYZ123456789ABCDEFGHIJ", |
| 77 | + "client_id": "client_01HXYZ123456789ABCDEFGHIJ", |
| 78 | + "description": None, |
| 79 | + "name": "My Application", |
| 80 | + "scopes": ["openid", "profile", "email"], |
| 81 | + "created_at": "2026-01-15T12:00:00.000Z", |
| 82 | + "updated_at": "2026-01-15T12:00:00.000Z", |
| 83 | + "application_type": "oauth", |
| 84 | + "redirect_uris": [{"uri": "https://example.com/callback", "default": True}], |
| 85 | + "uses_pkce": True, |
| 86 | + "is_first_party": True, |
| 87 | + "was_dynamically_registered": True, |
| 88 | + "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT", |
| 89 | + } |
| 90 | + instance = ConnectApplicationOAuth.from_dict(data) |
| 91 | + serialized = instance.to_dict() |
| 92 | + assert serialized["description"] is None |
| 93 | + |
| 94 | + def test_connect_application_oauth_redirect_uris_round_trip(self): |
| 95 | + data = load_fixture("connect_application_oauth_redirect_uris.json") |
| 96 | + instance = ConnectApplicationOAuthRedirectUris.from_dict(data) |
| 97 | + serialized = instance.to_dict() |
| 98 | + assert serialized == data |
| 99 | + restored = ConnectApplicationOAuthRedirectUris.from_dict(serialized) |
| 100 | + assert restored.to_dict() == serialized |
| 101 | + |
| 102 | + def test_connect_application_oauth_redirect_uris_minimal_payload(self): |
| 103 | + data = {"uri": "https://example.com/callback", "default": True} |
| 104 | + instance = ConnectApplicationOAuthRedirectUris.from_dict(data) |
| 105 | + serialized = instance.to_dict() |
| 106 | + assert serialized["uri"] == data["uri"] |
| 107 | + assert serialized["default"] == data["default"] |
| 108 | + |
| 109 | + def test_connect_application_m2m_round_trip(self): |
| 110 | + data = load_fixture("connect_application_m2m.json") |
| 111 | + instance = ConnectApplicationM2M.from_dict(data) |
| 112 | + serialized = instance.to_dict() |
| 113 | + assert serialized == data |
| 114 | + restored = ConnectApplicationM2M.from_dict(serialized) |
| 115 | + assert restored.to_dict() == serialized |
| 116 | + |
| 117 | + def test_connect_application_m2m_minimal_payload(self): |
| 118 | + data = { |
| 119 | + "object": "connect_application", |
| 120 | + "id": "conn_app_01HXYZ123456789ABCDEFGHIJ", |
| 121 | + "client_id": "client_01HXYZ123456789ABCDEFGHIJ", |
| 122 | + "description": None, |
| 123 | + "name": "My Application", |
| 124 | + "scopes": ["openid", "profile", "email"], |
| 125 | + "created_at": "2026-01-15T12:00:00.000Z", |
| 126 | + "updated_at": "2026-01-15T12:00:00.000Z", |
| 127 | + "application_type": "m2m", |
| 128 | + "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT", |
| 129 | + } |
| 130 | + instance = ConnectApplicationM2M.from_dict(data) |
| 131 | + serialized = instance.to_dict() |
| 132 | + assert serialized["object"] == data["object"] |
| 133 | + assert serialized["id"] == data["id"] |
| 134 | + assert serialized["client_id"] == data["client_id"] |
| 135 | + assert serialized["description"] == data["description"] |
| 136 | + assert serialized["name"] == data["name"] |
| 137 | + assert serialized["scopes"] == data["scopes"] |
| 138 | + assert serialized["created_at"] == data["created_at"] |
| 139 | + assert serialized["updated_at"] == data["updated_at"] |
| 140 | + assert serialized["application_type"] == data["application_type"] |
| 141 | + assert serialized["organization_id"] == data["organization_id"] |
| 142 | + |
| 143 | + def test_connect_application_m2m_preserves_nullable_fields(self): |
| 144 | + data = { |
| 145 | + "object": "connect_application", |
| 146 | + "id": "conn_app_01HXYZ123456789ABCDEFGHIJ", |
| 147 | + "client_id": "client_01HXYZ123456789ABCDEFGHIJ", |
| 148 | + "description": None, |
| 149 | + "name": "My Application", |
| 150 | + "scopes": ["openid", "profile", "email"], |
| 151 | + "created_at": "2026-01-15T12:00:00.000Z", |
| 152 | + "updated_at": "2026-01-15T12:00:00.000Z", |
| 153 | + "application_type": "m2m", |
| 154 | + "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT", |
| 155 | + } |
| 156 | + instance = ConnectApplicationM2M.from_dict(data) |
| 157 | + serialized = instance.to_dict() |
| 158 | + assert serialized["description"] is None |
0 commit comments