6
6
from paramiko import AuthenticationException , PasswordRequiredException , SSHException
7
7
8
8
import pyinfra
9
- from pyinfra .api import Config , MaskString , State , StringCommand
9
+ from pyinfra .api import Config , Host , MaskString , State , StringCommand
10
10
from pyinfra .api .connect import connect_all
11
11
from pyinfra .api .exceptions import ConnectError , PyinfraError
12
12
@@ -850,11 +850,13 @@ def test_put_file_su_user_fail_acl(self, fake_sftp_client, fake_ssh_client):
850
850
def test_put_file_su_user_fail_copy (self , fake_sftp_client , fake_ssh_client ):
851
851
inventory = make_inventory (hosts = ("anotherhost" ,))
852
852
State (inventory , Config ())
853
+
853
854
host = inventory .get_host ("anotherhost" )
855
+ assert isinstance (host , Host )
854
856
host .connect ()
855
857
856
858
stdout_mock = mock .MagicMock ()
857
- exit_codes = [0 , 1 ]
859
+ exit_codes = [0 , 0 , 1 ]
858
860
stdout_mock .channel .recv_exit_status .side_effect = lambda : exit_codes .pop (0 )
859
861
fake_ssh_client ().exec_command .return_value = (
860
862
mock .MagicMock (),
@@ -865,7 +867,7 @@ def test_put_file_su_user_fail_copy(self, fake_sftp_client, fake_ssh_client):
865
867
fake_open = mock .mock_open (read_data = "test!" )
866
868
with mock .patch ("pyinfra.api.util.open" , fake_open , create = True ):
867
869
status = host .put_file (
868
- "not-a-file" ,
870
+ fake_open () ,
869
871
"not-another-file" ,
870
872
print_output = True ,
871
873
_su_user = "centos" ,
@@ -881,7 +883,7 @@ def test_put_file_su_user_fail_copy(self, fake_sftp_client, fake_ssh_client):
881
883
get_pty = False ,
882
884
)
883
885
884
- fake_ssh_client ().exec_command .assert_called_with (
886
+ fake_ssh_client ().exec_command .assert_any_call (
885
887
(
886
888
"su centos -c 'sh -c '\" '\" 'cp "
887
889
"/tmp/pyinfra-43db9984686317089fefcf2e38de527e4cb44487 "
0 commit comments