41
41
42
42
43
43
@pytest .mark .asyncio
44
- # @pytest.mark.usefixtures("toolbox_server")
44
+ @pytest .mark .usefixtures ("toolbox_server" )
45
45
class TestE2EClient :
46
46
@pytest_asyncio .fixture (scope = "function" )
47
47
async def toolbox (self ):
@@ -86,7 +86,7 @@ async def test_run_tool(self, get_n_rows_tool: ToolboxTool):
86
86
assert "row3" not in response
87
87
88
88
async def test_run_tool_missing_params (self , get_n_rows_tool ):
89
- with pytest .raises (TypeError , match = "num_rows * Field required [type=missing, input_value={}, input_type=dict] " ):
89
+ with pytest .raises (TypeError , match = "missing a required argument: 'num_rows' " ):
90
90
await get_n_rows_tool ()
91
91
92
92
async def test_run_tool_wrong_param_type (self , get_n_rows_tool : ToolboxTool ):
@@ -107,75 +107,75 @@ async def test_bind_params(self, toolbox, get_n_rows_tool):
107
107
assert "row3" in response
108
108
assert "row4" not in response
109
109
110
- # # #### Auth tests
111
- # async def test_run_tool_unauth_with_auth(self, toolbox, auth_token2):
112
- # """Tests running a tool that doesn't require auth, with auth provided."""
113
- # tool = await toolbox.load_tool(
114
- # "get-row-by-id", auth_token_getters={"my-test-auth": lambda: auth_token2}
115
- # )
116
- # response = await tool(id="2")
117
- # assert "row2" in response
118
- #
119
- # async def test_run_tool_no_auth(self, toolbox):
120
- # """Tests running a tool requiring auth without providing auth."""
121
- # tool = await toolbox.load_tool(
122
- # "get-row-by-id-auth",
123
- # )
124
- # with pytest.raises(
125
- # Exception,
126
- # match="tool invocation not authorized. Please make sure your specify correct auth headers",
127
- # ):
128
- # await tool(id="2")
129
- #
130
- # async def test_run_tool_wrong_auth(self, toolbox, auth_token2):
131
- # """Tests running a tool with incorrect auth."""
132
- # tool = await toolbox.load_tool(
133
- # "get-row-by-id-auth",
134
- # )
135
- # auth_tool = tool.add_auth_token_getters({"my-test-auth": lambda: auth_token2})
136
- # with pytest.raises(
137
- # Exception,
138
- # match="tool invocation not authorized",
139
- # ):
140
- # await auth_tool(id="2")
141
- #
142
- # async def test_run_tool_auth(self, toolbox, auth_token1):
143
- # """Tests running a tool with correct auth."""
144
- # tool = await toolbox.load_tool(
145
- # "get-row-by-id-auth",
146
- # )
147
- # auth_tool = tool.add_auth_token_getters({"my-test-auth": lambda: auth_token1})
148
- # response = await auth_tool(id="2")
149
- # assert "row2" in response
150
- #
151
- # async def test_run_tool_param_auth_no_auth(self, toolbox):
152
- # """Tests running a tool with a param requiring auth, without auth."""
153
- # tool = await toolbox.load_tool("get-row-by-email-auth")
154
- # with pytest.raises(
155
- # Exception,
156
- # match="One or more of the following authn services are required to invoke this tool: my-test-auth",
157
- # ):
158
- # await tool()
159
- #
160
- # async def test_run_tool_param_auth(self, toolbox, auth_token1):
161
- # """Tests running a tool with a param requiring auth, with correct auth."""
162
- # tool = await toolbox.load_tool(
163
- # "get-row-by-email-auth",
164
- # auth_token_getters={"my-test-auth": lambda: auth_token1},
165
- # )
166
- # response = await tool()
167
- # assert "row4" in response
168
- # assert "row5" in response
169
- # assert "row6" in response
170
- #
171
- # async def test_run_tool_param_auth_no_field(self, toolbox, auth_token1):
172
- # """Tests running a tool with a param requiring auth, with insufficient auth."""
173
- # tool = await toolbox.load_tool(
174
- # "get-row-by-content-auth",
175
- # auth_token_getters={"my-test-auth": lambda: auth_token1},
176
- # )
177
- # with pytest.raises(
178
- # Exception,
179
- # match="no field named row_data in claims",
180
- # ):
181
- # await tool()
110
+ ##### Auth tests
111
+ async def test_run_tool_unauth_with_auth (self , toolbox , auth_token2 ):
112
+ """Tests running a tool that doesn't require auth, with auth provided."""
113
+ tool = await toolbox .load_tool (
114
+ "get-row-by-id" , auth_token_getters = {"my-test-auth" : lambda : auth_token2 }
115
+ )
116
+ response = await tool (id = "2" )
117
+ assert "row2" in response
118
+
119
+ async def test_run_tool_no_auth (self , toolbox ):
120
+ """Tests running a tool requiring auth without providing auth."""
121
+ tool = await toolbox .load_tool (
122
+ "get-row-by-id-auth" ,
123
+ )
124
+ with pytest .raises (
125
+ Exception ,
126
+ match = "tool invocation not authorized. Please make sure your specify correct auth headers" ,
127
+ ):
128
+ await tool (id = "2" )
129
+
130
+ async def test_run_tool_wrong_auth (self , toolbox , auth_token2 ):
131
+ """Tests running a tool with incorrect auth."""
132
+ tool = await toolbox .load_tool (
133
+ "get-row-by-id-auth" ,
134
+ )
135
+ auth_tool = tool .add_auth_token_getters ({"my-test-auth" : lambda : auth_token2 })
136
+ with pytest .raises (
137
+ Exception ,
138
+ match = "tool invocation not authorized" ,
139
+ ):
140
+ await auth_tool (id = "2" )
141
+
142
+ async def test_run_tool_auth (self , toolbox , auth_token1 ):
143
+ """Tests running a tool with correct auth."""
144
+ tool = await toolbox .load_tool (
145
+ "get-row-by-id-auth" ,
146
+ )
147
+ auth_tool = tool .add_auth_token_getters ({"my-test-auth" : lambda : auth_token1 })
148
+ response = await auth_tool (id = "2" )
149
+ assert "row2" in response
150
+
151
+ async def test_run_tool_param_auth_no_auth (self , toolbox ):
152
+ """Tests running a tool with a param requiring auth, without auth."""
153
+ tool = await toolbox .load_tool ("get-row-by-email-auth" )
154
+ with pytest .raises (
155
+ Exception ,
156
+ match = "One or more of the following authn services are required to invoke this tool: my-test-auth" ,
157
+ ):
158
+ await tool ()
159
+
160
+ async def test_run_tool_param_auth (self , toolbox , auth_token1 ):
161
+ """Tests running a tool with a param requiring auth, with correct auth."""
162
+ tool = await toolbox .load_tool (
163
+ "get-row-by-email-auth" ,
164
+ auth_token_getters = {"my-test-auth" : lambda : auth_token1 },
165
+ )
166
+ response = await tool ()
167
+ assert "row4" in response
168
+ assert "row5" in response
169
+ assert "row6" in response
170
+
171
+ async def test_run_tool_param_auth_no_field (self , toolbox , auth_token1 ):
172
+ """Tests running a tool with a param requiring auth, with insufficient auth."""
173
+ tool = await toolbox .load_tool (
174
+ "get-row-by-content-auth" ,
175
+ auth_token_getters = {"my-test-auth" : lambda : auth_token1 },
176
+ )
177
+ with pytest .raises (
178
+ Exception ,
179
+ match = "no field named row_data in claims" ,
180
+ ):
181
+ await tool ()
0 commit comments