@@ -85,3 +85,145 @@ def test_empty_filter_result():
8585 toolset = StackOneToolSet (api_key = "test_key" )
8686 tools = toolset .get_tools (filter_pattern = "unknown_*" )
8787 assert len (tools ) == 0
88+
89+
90+ def test_toolset_with_base_url ():
91+ """Test StackOneToolSet with a custom base_url"""
92+ mock_spec_content = {
93+ "paths" : {
94+ "/employee/{id}" : {
95+ "get" : {
96+ "operationId" : "hris_get_employee" ,
97+ "summary" : "Get employee details" ,
98+ "parameters" : [
99+ {
100+ "in" : "path" ,
101+ "name" : "id" ,
102+ "schema" : {"type" : "string" },
103+ "description" : "Employee ID" ,
104+ }
105+ ],
106+ }
107+ }
108+ }
109+ }
110+
111+ # Create mock tool definition with default URL
112+ mock_tool_def = ToolDefinition (
113+ description = "Get employee details" ,
114+ parameters = ToolParameters (
115+ type = "object" ,
116+ properties = {
117+ "id" : {
118+ "type" : "string" ,
119+ "description" : "Employee ID" ,
120+ }
121+ },
122+ ),
123+ execute = ExecuteConfig (
124+ method = "GET" ,
125+ url = "https://api.stackone.com/employee/{id}" ,
126+ name = "hris_get_employee" ,
127+ headers = {},
128+ parameter_locations = {"id" : "path" },
129+ ),
130+ )
131+
132+ # Create mock tool definition with development URL
133+ mock_tool_def_dev = ToolDefinition (
134+ description = "Get employee details" ,
135+ parameters = ToolParameters (
136+ type = "object" ,
137+ properties = {
138+ "id" : {
139+ "type" : "string" ,
140+ "description" : "Employee ID" ,
141+ }
142+ },
143+ ),
144+ execute = ExecuteConfig (
145+ method = "GET" ,
146+ url = "https://api.example-dev.com/employee/{id}" ,
147+ name = "hris_get_employee" ,
148+ headers = {},
149+ parameter_locations = {"id" : "path" },
150+ ),
151+ )
152+
153+ # Create mock tool definition with experimental URL
154+ mock_tool_def_exp = ToolDefinition (
155+ description = "Get employee details" ,
156+ parameters = ToolParameters (
157+ type = "object" ,
158+ properties = {
159+ "id" : {
160+ "type" : "string" ,
161+ "description" : "Employee ID" ,
162+ }
163+ },
164+ ),
165+ execute = ExecuteConfig (
166+ method = "GET" ,
167+ url = "https://api.example-exp.com/employee/{id}" ,
168+ name = "hris_get_employee" ,
169+ headers = {},
170+ parameter_locations = {"id" : "path" },
171+ ),
172+ )
173+
174+ # Mock the OpenAPIParser and file operations
175+ with (
176+ patch ("stackone_ai.toolset.OAS_DIR" ) as mock_dir ,
177+ patch ("stackone_ai.toolset.OpenAPIParser" ) as mock_parser_class ,
178+ ):
179+ # Setup mocks
180+ mock_path = MagicMock ()
181+ mock_path .exists .return_value = True
182+ mock_dir .__truediv__ .return_value = mock_path
183+ mock_dir .glob .return_value = [mock_path ]
184+
185+ # Setup parser mock for default URL
186+ mock_parser = MagicMock ()
187+ mock_parser .spec = mock_spec_content
188+ mock_parser .parse_tools .return_value = {"hris_get_employee" : mock_tool_def }
189+
190+ # Setup parser mock for development URL
191+ mock_parser_dev = MagicMock ()
192+ mock_parser_dev .spec = mock_spec_content
193+ mock_parser_dev .parse_tools .return_value = {"hris_get_employee" : mock_tool_def_dev }
194+
195+ # Setup parser mock for experimental URL
196+ mock_parser_exp = MagicMock ()
197+ mock_parser_exp .spec = mock_spec_content
198+ mock_parser_exp .parse_tools .return_value = {"hris_get_employee" : mock_tool_def_exp }
199+
200+ # Configure the mock parser class to return different instances based on base_url
201+ def get_parser (spec_path , base_url = None ):
202+ if base_url == "https://api.example-dev.com" :
203+ return mock_parser_dev
204+ elif base_url == "https://api.example-exp.com" :
205+ return mock_parser_exp
206+ return mock_parser
207+
208+ mock_parser_class .side_effect = get_parser
209+
210+ # Test with default URL
211+ toolset = StackOneToolSet (api_key = "test_key" )
212+ tools = toolset .get_tools (filter_pattern = "hris_*" )
213+ tool = tools .get_tool ("hris_get_employee" )
214+ assert tool is not None
215+ assert tool ._execute_config .url == "https://api.stackone.com/employee/{id}"
216+
217+ # Test with development URL
218+ toolset_dev = StackOneToolSet (api_key = "test_key" , base_url = "https://api.example-dev.com" )
219+ tools_dev = toolset_dev .get_tools (filter_pattern = "hris_*" )
220+ tool_dev = tools_dev .get_tool ("hris_get_employee" )
221+ assert tool_dev is not None
222+ assert tool_dev ._execute_config .url == "https://api.example-dev.com/employee/{id}"
223+
224+ # Test with experimental URL
225+ toolset_exp = StackOneToolSet (api_key = "test_key" , base_url = "https://api.example-exp.com" )
226+ tools_exp = toolset_exp .get_tools (filter_pattern = "hris_*" )
227+ tool_exp = tools_exp .get_tool ("hris_get_employee" )
228+ assert tool_exp is not None
229+ assert tool_exp ._execute_config .url == "https://api.example-exp.com/employee/{id}"
0 commit comments