@@ -57,14 +57,51 @@ def mock_kong_responses(self) -> Dict[str, Any]:
5757 "plugins" : {
5858 "data" : [
5959 {
60- "id" : "plugin-1" ,
60+ "id" : "plugin-global-1" ,
61+ "name" : "cors" ,
62+ "config" : {},
63+ "created_at" : 1618846400 ,
64+ }
65+ ],
66+ "offset" : None ,
67+ },
68+ "plugins_by_service" : {
69+ "data" : [
70+ {
71+ "id" : "plugin-service-1" ,
6172 "name" : "rate-limiting" ,
62- "config" : {"minute" : 100 , "hour" : 1000 },
6373 "service" : {"id" : "service-1" },
74+ "config" : {"minute" : 100 },
6475 "created_at" : 1618846400 ,
6576 }
66- ]
77+ ],
78+ "offset" : None ,
79+ },
80+ "plugins_by_route" : {
81+ "data" : [
82+ {
83+ "id" : "plugin-route-1" ,
84+ "name" : "jwt" ,
85+ "route" : {"id" : "route-1" },
86+ "config" : {"key" : "value" },
87+ "created_at" : 1618846400 ,
88+ }
89+ ],
90+ "offset" : None ,
6791 },
92+ "plugins_by_consumer" : {
93+ "data" : [
94+ {
95+ "id" : "plugin-consumer-1" ,
96+ "name" : "key-auth" ,
97+ "consumer" : {"id" : "consumer-1" },
98+ "config" : {},
99+ "created_at" : 1618846400 ,
100+ }
101+ ],
102+ "offset" : None ,
103+ },
104+ "consumers" : {"data" : [{"id" : "consumer-1" , "username" : "test-consumer" }]},
68105 "status" : {
69106 "database" : {"reachable" : True },
70107 "server" : {"connections_accepted" : 100 },
@@ -213,6 +250,93 @@ async def test_kong_client_route_operations_integration(
213250 assert routes [0 ]["name" ] == "test-route"
214251 mock_request .assert_called_with ("GET" , "/routes" , params = {"size" : 10 })
215252
253+ @pytest .mark .asyncio
254+ async def test_kong_client_plugins_operations_integration (
255+ self , mock_kong_responses : Dict [str , Any ]
256+ ) -> None :
257+ config = KongClientConfig (base_url = "http://kong-admin:8001" )
258+ async with KongClient (config ) as client :
259+ with patch .object (client , "_request" ) as mock_request :
260+ mock_response = mock_kong_responses ["plugins" ]
261+ mock_request .return_value = mock_response
262+
263+ result = await client .get_plugins (params = {"name" : "jwt" , "size" : 10 })
264+
265+ assert result ["data" ] == mock_response ["data" ]
266+ assert result ["offset" ] == mock_response .get (
267+ "offset"
268+ ) or mock_response .get ("next" )
269+ # Validate call parameters
270+ mock_request .assert_called_with (
271+ "GET" ,
272+ "/plugins" ,
273+ params = {"name" : "jwt" , "size" : 10 },
274+ json_data = None ,
275+ )
276+
277+ async def test_get_plugins_by_service (self , mock_kong_responses : Dict [str , Any ]):
278+ """Test get_plugins_by_service tool."""
279+ config = KongClientConfig (base_url = "http://kong-admin:8001" )
280+ async with KongClient (config ) as client :
281+ with patch .object (client , "_request" ) as mock_request :
282+ service_id = "service-1"
283+ mock_response = mock_kong_responses ["plugins_by_service" ]
284+ mock_request .return_value = mock_response
285+
286+ result = await client .get_plugins_by_service (
287+ service_id , params = {"size" : 5 }
288+ )
289+
290+ assert result ["data" ] == mock_response ["data" ]
291+ mock_request .assert_called_with (
292+ "GET" ,
293+ f"/services/{ service_id } /plugins" ,
294+ params = {"size" : 5 },
295+ json_data = None ,
296+ )
297+
298+ async def test_get_plugins_by_route (self , mock_kong_responses : Dict [str , Any ]):
299+ """Test get_plugins_by_route tool."""
300+ config = KongClientConfig (base_url = "http://kong-admin:8001" )
301+ async with KongClient (config ) as client :
302+ with patch .object (client , "_request" ) as mock_request :
303+ route_id = "route-1"
304+ mock_response = mock_kong_responses ["plugins_by_route" ]
305+ mock_request .return_value = mock_response
306+
307+ result = await client .get_plugins_by_route (
308+ route_id , params = {"offset" : "cursor0" }
309+ )
310+
311+ assert result ["data" ] == mock_response ["data" ]
312+ mock_request .assert_called_with (
313+ "GET" ,
314+ f"/routes/{ route_id } /plugins" ,
315+ params = {"offset" : "cursor0" },
316+ json_data = None ,
317+ )
318+
319+ async def test_get_plugins_by_consumer (self , mock_kong_responses : Dict [str , Any ]):
320+ """Test get_plugins_by_consumer tool."""
321+ config = KongClientConfig (base_url = "http://kong-admin:8001" )
322+ async with KongClient (config ) as client :
323+ with patch .object (client , "_request" ) as mock_request :
324+ consumer_id = "consumer-1"
325+ mock_response = mock_kong_responses ["plugins_by_consumer" ]
326+ mock_request .return_value = mock_response
327+
328+ result = await client .get_plugins_by_consumer (
329+ consumer_id , params = {"size" : 3 }
330+ )
331+
332+ assert result ["data" ] == mock_response ["data" ]
333+ mock_request .assert_called_with (
334+ "GET" ,
335+ f"/consumers/{ consumer_id } /plugins" ,
336+ params = {"size" : 3 },
337+ json_data = None ,
338+ )
339+
216340 @pytest .mark .asyncio
217341 async def test_kong_client_error_handling_integration (self ) -> None :
218342 """Test Kong client error handling in integration scenarios."""
0 commit comments