11from datetime import datetime , timezone
2+ from unittest .mock import Mock , patch
23
34import pytest
5+ from groundlight import ExperimentalApi
46from groundlight .edge import (
57 DEFAULT ,
68 DISABLED ,
@@ -316,10 +318,6 @@ def test_inference_config_validation_errors():
316318
317319def test_edge_get_config_parses_response ():
318320 """gl.edge.get_config() parses the HTTP response into an EdgeEndpointConfig."""
319- from unittest .mock import Mock , patch
320-
321- from groundlight import ExperimentalApi
322-
323321 payload = {
324322 "global_config" : {"refresh_rate" : REFRESH_RATE_SECONDS },
325323 "edge_inference_configs" : {"default" : {"enabled" : True }},
@@ -339,3 +337,50 @@ def test_edge_get_config_parses_response():
339337 assert config .global_config .refresh_rate == REFRESH_RATE_SECONDS
340338 assert config .edge_inference_configs ["default" ].name == "default"
341339 assert [d .detector_id for d in config .detectors ] == [DET_1 ]
340+
341+
342+ def test_edge_set_config_sends_payload_and_polls ():
343+ """gl.edge.set_config() PUTs the config then polls readiness until all detectors are ready."""
344+ config = EdgeEndpointConfig ()
345+ config .add_detector (DET_1 , DEFAULT )
346+
347+ put_response = Mock ()
348+ put_response .raise_for_status = Mock ()
349+
350+ readiness_response = Mock ()
351+ readiness_response .json .return_value = {DET_1 : {"ready" : True }}
352+ readiness_response .raise_for_status = Mock ()
353+
354+ get_response = Mock ()
355+ get_response .json .return_value = config .to_payload ()
356+ get_response .raise_for_status = Mock ()
357+
358+ def route_request (method , url , ** kwargs ):
359+ if method == "PUT" :
360+ return put_response
361+ if "/edge-detector-readiness" in url :
362+ return readiness_response
363+ return get_response
364+
365+ gl = ExperimentalApi ()
366+ with patch ("requests.request" , side_effect = route_request ):
367+ result = gl .edge .set_config (config )
368+
369+ assert isinstance (result , EdgeEndpointConfig )
370+ assert [d .detector_id for d in result .detectors ] == [DET_1 ]
371+
372+
373+ def test_edge_get_detector_readiness ():
374+ """gl.edge.get_detector_readiness() returns a dict mapping detector IDs to booleans."""
375+ mock_response = Mock ()
376+ mock_response .json .return_value = {
377+ DET_1 : {"ready" : True },
378+ DET_2 : {"ready" : False },
379+ }
380+ mock_response .raise_for_status = Mock ()
381+
382+ gl = ExperimentalApi ()
383+ with patch ("requests.request" , return_value = mock_response ):
384+ readiness = gl .edge .get_detector_readiness ()
385+
386+ assert readiness == {DET_1 : True , DET_2 : False }
0 commit comments