Skip to content

Commit

Permalink
Merge pull request #176 from TAlonglong/issue175
Browse files Browse the repository at this point in the history
Handle destination as urlparse type. Add test.
  • Loading branch information
mraspaud authored Aug 22, 2023
2 parents a19decd + 6370294 commit ae2b9bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion trollmoves/movers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def move_it(pathname, destination, attrs=None, hook=None, rel_path=None, backup_
be appended to the destination path.
"""
dest_url = urlparse(destination)
try:
dest_url = urlparse(destination)
except AttributeError:
dest_url = destination
if rel_path is not None:
new_path = os.path.join(dest_url.path, rel_path)
else:
Expand Down
18 changes: 18 additions & 0 deletions trollmoves/tests/test_ssh_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,23 @@ def test_scp_move(self, mock_scp_client, mock_sshclient):
mocked_scp_client.put.assert_called_once_with(self.origin, urlparse(self.destination_no_port).path)


@patch('paramiko.SSHClient.connect', autospec=True)
@patch('scp.SCPClient', autospec=True)
def test_move_it_destination_types(self, patch_scpclient, patch_connect):
"""Test move_it handles destination string and urlparse types."""
import os
from trollmoves.movers import move_it

expected_destination = urlparse("scp://hostname/path/name")
pathname = os.path.join(self.dest_dir, "dest.ext")

destination = "scp://hostname/path/name"
ret_destination = move_it(pathname, destination)
assert ret_destination == expected_destination

urlparse_destination = urlparse("scp://hostname/path/name")
ret_destination = move_it(pathname, urlparse_destination)
assert ret_destination == expected_destination

if __name__ == '__main__':
unittest.main()

0 comments on commit ae2b9bb

Please sign in to comment.