|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -from google.adk.a2a.converters.utils import _from_a2a_context_id |
16 | 15 | from google.adk.a2a.converters.utils import _get_adk_metadata_key |
17 | | -from google.adk.a2a.converters.utils import _to_a2a_context_id |
18 | | -from google.adk.a2a.converters.utils import ADK_CONTEXT_ID_PREFIX |
19 | 16 | from google.adk.a2a.converters.utils import ADK_METADATA_KEY_PREFIX |
20 | 17 | import pytest |
21 | 18 |
|
@@ -48,157 +45,3 @@ def test_get_adk_metadata_key_whitespace(self): |
48 | 45 | key = " " |
49 | 46 | result = _get_adk_metadata_key(key) |
50 | 47 | assert result == f"{ADK_METADATA_KEY_PREFIX}{key}" |
51 | | - |
52 | | - def test_to_a2a_context_id_success(self): |
53 | | - """Test successful context ID generation.""" |
54 | | - app_name = "test-app" |
55 | | - user_id = "test-user" |
56 | | - session_id = "test-session" |
57 | | - |
58 | | - result = _to_a2a_context_id(app_name, user_id, session_id) |
59 | | - |
60 | | - expected = f"{ADK_CONTEXT_ID_PREFIX}/test-app/test-user/test-session" |
61 | | - assert result == expected |
62 | | - |
63 | | - def test_to_a2a_context_id_empty_app_name(self): |
64 | | - """Test context ID generation with empty app name.""" |
65 | | - with pytest.raises( |
66 | | - ValueError, |
67 | | - match=( |
68 | | - "All parameters \\(app_name, user_id, session_id\\) must be" |
69 | | - " non-empty" |
70 | | - ), |
71 | | - ): |
72 | | - _to_a2a_context_id("", "user", "session") |
73 | | - |
74 | | - def test_to_a2a_context_id_empty_user_id(self): |
75 | | - """Test context ID generation with empty user ID.""" |
76 | | - with pytest.raises( |
77 | | - ValueError, |
78 | | - match=( |
79 | | - "All parameters \\(app_name, user_id, session_id\\) must be" |
80 | | - " non-empty" |
81 | | - ), |
82 | | - ): |
83 | | - _to_a2a_context_id("app", "", "session") |
84 | | - |
85 | | - def test_to_a2a_context_id_empty_session_id(self): |
86 | | - """Test context ID generation with empty session ID.""" |
87 | | - with pytest.raises( |
88 | | - ValueError, |
89 | | - match=( |
90 | | - "All parameters \\(app_name, user_id, session_id\\) must be" |
91 | | - " non-empty" |
92 | | - ), |
93 | | - ): |
94 | | - _to_a2a_context_id("app", "user", "") |
95 | | - |
96 | | - def test_to_a2a_context_id_none_values(self): |
97 | | - """Test context ID generation with None values.""" |
98 | | - with pytest.raises( |
99 | | - ValueError, |
100 | | - match=( |
101 | | - "All parameters \\(app_name, user_id, session_id\\) must be" |
102 | | - " non-empty" |
103 | | - ), |
104 | | - ): |
105 | | - _to_a2a_context_id(None, "user", "session") |
106 | | - |
107 | | - def test_to_a2a_context_id_special_characters(self): |
108 | | - """Test context ID generation with special characters.""" |
109 | | - app_name = "test-app@2024" |
110 | | - user_id = "user_123" |
111 | | - session_id = "session-456" |
112 | | - |
113 | | - result = _to_a2a_context_id(app_name, user_id, session_id) |
114 | | - |
115 | | - expected = f"{ADK_CONTEXT_ID_PREFIX}/test-app@2024/user_123/session-456" |
116 | | - assert result == expected |
117 | | - |
118 | | - def test_from_a2a_context_id_success(self): |
119 | | - """Test successful context ID parsing.""" |
120 | | - context_id = f"{ADK_CONTEXT_ID_PREFIX}/test-app/test-user/test-session" |
121 | | - |
122 | | - app_name, user_id, session_id = _from_a2a_context_id(context_id) |
123 | | - |
124 | | - assert app_name == "test-app" |
125 | | - assert user_id == "test-user" |
126 | | - assert session_id == "test-session" |
127 | | - |
128 | | - def test_from_a2a_context_id_none_input(self): |
129 | | - """Test context ID parsing with None input.""" |
130 | | - result = _from_a2a_context_id(None) |
131 | | - assert result == (None, None, None) |
132 | | - |
133 | | - def test_from_a2a_context_id_empty_string(self): |
134 | | - """Test context ID parsing with empty string.""" |
135 | | - result = _from_a2a_context_id("") |
136 | | - assert result == (None, None, None) |
137 | | - |
138 | | - def test_from_a2a_context_id_invalid_prefix(self): |
139 | | - """Test context ID parsing with invalid prefix.""" |
140 | | - context_id = "INVALID/test-app/test-user/test-session" |
141 | | - |
142 | | - result = _from_a2a_context_id(context_id) |
143 | | - |
144 | | - assert result == (None, None, None) |
145 | | - |
146 | | - def test_from_a2a_context_id_too_few_parts(self): |
147 | | - """Test context ID parsing with too few parts.""" |
148 | | - context_id = f"{ADK_CONTEXT_ID_PREFIX}/test-app/test-user" |
149 | | - |
150 | | - result = _from_a2a_context_id(context_id) |
151 | | - |
152 | | - assert result == (None, None, None) |
153 | | - |
154 | | - def test_from_a2a_context_id_too_many_parts(self): |
155 | | - """Test context ID parsing with too many parts.""" |
156 | | - context_id = ( |
157 | | - f"{ADK_CONTEXT_ID_PREFIX}/test-app/test-user/test-session/extra" |
158 | | - ) |
159 | | - |
160 | | - result = _from_a2a_context_id(context_id) |
161 | | - |
162 | | - assert result == (None, None, None) |
163 | | - |
164 | | - def test_from_a2a_context_id_empty_components(self): |
165 | | - """Test context ID parsing with empty components.""" |
166 | | - context_id = f"{ADK_CONTEXT_ID_PREFIX}//test-user/test-session" |
167 | | - |
168 | | - result = _from_a2a_context_id(context_id) |
169 | | - |
170 | | - assert result == (None, None, None) |
171 | | - |
172 | | - def test_from_a2a_context_id_no_dollar_separator(self): |
173 | | - """Test context ID parsing without dollar separators.""" |
174 | | - context_id = f"{ADK_CONTEXT_ID_PREFIX}-test-app-test-user-test-session" |
175 | | - |
176 | | - result = _from_a2a_context_id(context_id) |
177 | | - |
178 | | - assert result == (None, None, None) |
179 | | - |
180 | | - def test_roundtrip_context_id(self): |
181 | | - """Test roundtrip conversion: to -> from.""" |
182 | | - app_name = "test-app" |
183 | | - user_id = "test-user" |
184 | | - session_id = "test-session" |
185 | | - |
186 | | - # Convert to context ID |
187 | | - context_id = _to_a2a_context_id(app_name, user_id, session_id) |
188 | | - |
189 | | - # Convert back |
190 | | - parsed_app, parsed_user, parsed_session = _from_a2a_context_id(context_id) |
191 | | - |
192 | | - assert parsed_app == app_name |
193 | | - assert parsed_user == user_id |
194 | | - assert parsed_session == session_id |
195 | | - |
196 | | - def test_from_a2a_context_id_special_characters(self): |
197 | | - """Test context ID parsing with special characters.""" |
198 | | - context_id = f"{ADK_CONTEXT_ID_PREFIX}/test-app@2024/user_123/session-456" |
199 | | - |
200 | | - app_name, user_id, session_id = _from_a2a_context_id(context_id) |
201 | | - |
202 | | - assert app_name == "test-app@2024" |
203 | | - assert user_id == "user_123" |
204 | | - assert session_id == "session-456" |
0 commit comments