def test_remote_listing_iteration_does_not_exist(self, remote_iterdir, remote_exists, mock_method): process = Mock() process.communicate = Mock(return_value=(b'one/\ntwo@\nthree*\nfour\n', b'No such file or directory')) mock_method.return_value = process remote_exists.side_effect = [False, False, True] remote_iterdir.return_value = list([{ 'type': 'dir', 'name': 'one' }, { 'type': 'link', 'name': 'two' }, { 'type': 'file', 'name': 'three' }, { 'type': 'file', 'name': 'four' }]) path = Mock() path.as_posix = Mock(return_value='/') ssh = Ssh() with self.assertRaises(PathNotFoundException) as context: result = ssh.remote_listing('remotehost', path) assert result == list()
def test_remote_listing(self, mock_method): process = Mock() process.communicate = Mock(return_value=(b'one/\ntwo@\nthree*\nfour\n', b'stderr')) mock_method.return_value = process path = Mock() path.as_posix = Mock(return_value='/') ssh = Ssh() result = ssh.remote_listing('remotehost', path) assert result == list([{ 'type': 'dir', 'name': 'one' }, { 'type': 'link', 'name': 'two' }, { 'type': 'file', 'name': 'three' }, { 'type': 'file', 'name': 'four' }])