44 IOP_URL=http://localhost:52773 pytest src/tests/e2e/remote/
55"""
66import pytest
7+ import requests
8+
9+
10+ @pytest .fixture (scope = "module" )
11+ def default_production (remote_director ):
12+ """Default production name for the configured namespace.
13+
14+ Falls back to the first production found in the list; skips only when
15+ no production exists at all.
16+ """
17+ prod = remote_director .get_default_production ()
18+ if prod in ("" , "Not defined" ):
19+ prods = remote_director .list_productions ()
20+ if not prods :
21+ pytest .skip ("No productions available" )
22+ prod = next (iter (prods ))
23+ return prod
24+
25+
26+ @pytest .fixture (scope = "module" )
27+ def first_active_component (remote_director , default_production ):
28+ """Name of the first enabled component in the default production, or skip."""
29+ try :
30+ remote_director .start_production (default_production )
31+ except (RuntimeError , requests .exceptions .HTTPError ):
32+ pass # already running
33+
34+ components = remote_director .export_production (default_production )
35+ production_data = list (components .values ())[0 ]
36+ items = production_data .get ("Item" , [])
37+ if isinstance (items , dict ):
38+ items = [items ]
39+ active = [item for item in items if item .get ("@Enabled" , "1" ) == "1" ]
40+ if not active :
41+ pytest .skip ("No active components found in the default production" )
42+ return active [0 ]["@Name" ]
743
844
945class TestComponentTesting :
10- def test_test_component_returns_response (self , remote_director ):
46+ def test_test_component_returns_response (self , remote_director , default_production ):
1147 """POST /test with a basic Ens.StringRequest should return a valid response."""
12- default_target = remote_director .get_default_production ()
13- if default_target in ("" , "Not defined" ):
14- pytest .skip ("No default production defined" )
15-
16- # This test uses Ens.StringRequest as a generic smoke test.
48+ # Uses Ens.StringRequest as a generic smoke test.
1749 # Adjust target and classname to match your environment.
1850 try :
1951 result = remote_director .test_component (
@@ -35,38 +67,20 @@ def test_test_component_bad_target_raises(self, remote_director):
3567 body = '{"StringValue": "ping"}' ,
3668 )
3769
38- def test_test_component_bad_classname_raises (self , remote_director ):
70+ def test_test_component_bad_classname_raises (self , remote_director , default_production ):
3971 """Sending with a non-existent classname should raise RuntimeError."""
40- default_target = remote_director .get_default_production ()
41- if default_target in ("" , "Not defined" ):
42- pytest .skip ("No default production defined" )
43-
4472 with pytest .raises (RuntimeError ):
4573 remote_director .test_component (
4674 target = None ,
4775 classname = "This.Class.DoesNotExist" ,
4876 body = '{"StringValue": "ping"}' ,
4977 )
5078
51- def test_test_component_restart (self , remote_director ):
79+ def test_test_component_restart (self , remote_director , first_active_component ):
5280 """Test that the restart option in test_component works without error."""
53- default_target = remote_director .get_default_production ()
54- if default_target in ("" , "Not defined" ):
55- pytest .skip ("No default production defined" )
56-
57- # export the default production's components and pick one to target for this test
58- components = remote_director .export_components ()
59- active_components = [c for c in components if c ["active" ]]
60-
61-
62- if not active_components :
63- pytest .skip ("No active components found in the default production" )
64-
65- target_component = active_components [0 ]["name" ]
66-
6781 result = remote_director .test_component (
68- target = target_component ,
69- classname = "Ens.StringRequest" ,
82+ target = first_active_component ,
83+ classname = None ,
7084 body = '{"StringValue": "ping"}' ,
7185 restart = True ,
7286 )
0 commit comments