1+ import io
12import json
23from types import SimpleNamespace
34
1314)
1415
1516
17+ def _make_proc (* , stdout : str = "" , stderr : str = "" , returncode : int = 0 ):
18+ return SimpleNamespace (
19+ returncode = returncode ,
20+ stdout_text = io .StringIO (stdout ),
21+ stderr_text = io .StringIO (stderr ),
22+ )
23+
24+
1625def test_resolve_pool_id_prefers_explicit ():
1726 assert resolve_pool_id ("Pool42" , None ) == "Pool42"
1827
@@ -43,12 +52,15 @@ def test_checkout_org_from_pool_parses_username(monkeypatch):
4352 "poolId" : "Pool42" ,
4453 }
4554
46- def fake_run (command , check , text , capture_output , env ):
47- assert command [:4 ] == ["sf" , "clariti" , "org" , "checkout" ]
48- assert "--json" in command
49- return SimpleNamespace (returncode = 0 , stdout = json .dumps (payload ), stderr = "" )
55+ def fake_sfdx (command , ** kwargs ):
56+ assert command == "clariti org checkout"
57+ args = kwargs ["args" ]
58+ assert args [0 ] == "--json"
59+ assert "--pool-id" in args and "Pool42" in args
60+ assert "--alias" in args and "MyAlias" in args
61+ return _make_proc (stdout = json .dumps (payload ))
5062
51- monkeypatch .setattr ("cumulusci.utils.clariti.subprocess.run " , fake_run )
63+ monkeypatch .setattr ("cumulusci.utils.clariti.sfdx " , fake_sfdx )
5264
5365 result = checkout_org_from_pool ("Pool42" , alias = "MyAlias" )
5466
@@ -68,11 +80,11 @@ def test_checkout_org_from_pool_reads_nested_username(monkeypatch):
6880 },
6981 }
7082
71- def fake_run (command , check , text , capture_output , env ):
72- assert "--pool-id" in command
73- return SimpleNamespace ( returncode = 0 , stdout = json .dumps (payload ), stderr = "" )
83+ def fake_sfdx (command , ** kwargs ):
84+ assert "--pool-id" in kwargs [ "args" ]
85+ return _make_proc ( stdout = json .dumps (payload ))
7486
75- monkeypatch .setattr ("cumulusci.utils.clariti.subprocess.run " , fake_run )
87+ monkeypatch .setattr ("cumulusci.utils.clariti.sfdx " , fake_sfdx )
7688
7789 result = checkout_org_from_pool ("PoolNested" )
7890
@@ -86,22 +98,22 @@ def test_checkout_org_from_pool_without_pool_id(monkeypatch):
8698 "poolId" : "Pool-From-Config" ,
8799 }
88100
89- def fake_run (command , check , text , capture_output , env ):
90- assert "--pool-id" not in command
91- return SimpleNamespace ( returncode = 0 , stdout = json .dumps (payload ), stderr = "" )
101+ def fake_sfdx (command , ** kwargs ):
102+ assert "--pool-id" not in kwargs [ "args" ]
103+ return _make_proc ( stdout = json .dumps (payload ))
92104
93- monkeypatch .setattr ("cumulusci.utils.clariti.subprocess.run " , fake_run )
105+ monkeypatch .setattr ("cumulusci.utils.clariti.sfdx " , fake_sfdx )
94106
95107 result = checkout_org_from_pool (None )
96108
97109 assert result .username == "user@example.com"
98110
99111
100112def test_checkout_org_from_pool_handles_failure (monkeypatch ):
101- def fake_run (command , check , text , capture_output , env ):
102- return SimpleNamespace ( returncode = 1 , stdout = "" , stderr = "No orgs available" )
113+ def fake_sfdx (command , ** kwargs ):
114+ return _make_proc ( stdout = "" , stderr = "No orgs available" , returncode = 1 )
103115
104- monkeypatch .setattr ("cumulusci.utils.clariti.subprocess.run " , fake_run )
116+ monkeypatch .setattr ("cumulusci.utils.clariti.sfdx " , fake_sfdx )
105117
106118 with pytest .raises (ClaritiError ) as exc :
107119 checkout_org_from_pool ("EmptyPool" )
@@ -117,12 +129,10 @@ def test_checkout_org_from_pool_formats_json_error(monkeypatch):
117129 "message" : "Failed to get org from pool: No healthy orgs available in this pool" ,
118130 }
119131
120- def fake_run (command , check , text , capture_output , env ):
121- return SimpleNamespace (
122- returncode = 1 , stdout = json .dumps (payload ), stderr = ""
123- )
132+ def fake_sfdx (command , ** kwargs ):
133+ return _make_proc (stdout = json .dumps (payload ), stderr = "" , returncode = 1 )
124134
125- monkeypatch .setattr ("cumulusci.utils.clariti.subprocess.run " , fake_run )
135+ monkeypatch .setattr ("cumulusci.utils.clariti.sfdx " , fake_sfdx )
126136
127137 with pytest .raises (ClaritiError ) as exc :
128138 checkout_org_from_pool ("Pool42" )
@@ -139,12 +149,10 @@ def test_checkout_org_from_pool_formats_json_error_debug(monkeypatch):
139149 "message" : "Failed" , "extra" : "details" ,
140150 }
141151
142- def fake_run (command , check , text , capture_output , env ):
143- return SimpleNamespace (
144- returncode = 1 , stdout = json .dumps (payload ), stderr = ""
145- )
152+ def fake_sfdx (command , ** kwargs ):
153+ return _make_proc (stdout = json .dumps (payload ), stderr = "" , returncode = 1 )
146154
147- monkeypatch .setattr ("cumulusci.utils.clariti.subprocess.run " , fake_run )
155+ monkeypatch .setattr ("cumulusci.utils.clariti.sfdx " , fake_sfdx )
148156
149157 from cumulusci .core .debug import set_debug_mode
150158
@@ -159,11 +167,12 @@ def fake_run(command, check, text, capture_output, env):
159167
160168
161169def test_set_sf_alias_success (monkeypatch ):
162- def fake_run (command , check , text , capture_output , env ):
163- assert command == ["sf" , "alias" , "set" , "target=user@example.com" ]
164- return SimpleNamespace (returncode = 0 , stdout = "" , stderr = "" )
170+ def fake_sfdx (command , ** kwargs ):
171+ assert command == "alias set"
172+ assert kwargs ["args" ] == ["target=user@example.com" ]
173+ return _make_proc ()
165174
166- monkeypatch .setattr ("cumulusci.utils.clariti.subprocess.run " , fake_run )
175+ monkeypatch .setattr ("cumulusci.utils.clariti.sfdx " , fake_sfdx )
167176
168177 success , message = set_sf_alias ("target" , "user@example.com" )
169178
@@ -172,10 +181,10 @@ def fake_run(command, check, text, capture_output, env):
172181
173182
174183def test_set_sf_alias_failure (monkeypatch ):
175- def fake_run (command , check , text , capture_output , env ):
176- return SimpleNamespace ( returncode = 1 , stdout = "" , stderr = "Alias failure" )
184+ def fake_sfdx (command , ** kwargs ):
185+ return _make_proc ( stdout = "" , stderr = "Alias failure" , returncode = 1 )
177186
178- monkeypatch .setattr ("cumulusci.utils.clariti.subprocess.run " , fake_run )
187+ monkeypatch .setattr ("cumulusci.utils.clariti.sfdx " , fake_sfdx )
179188
180189 success , message = set_sf_alias ("target" , "username" )
181190
0 commit comments