Advertisement
Guest User

Untitled

a guest
Jun 10th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. def to_ftp(self, output_path, file_name, host, username, password):
  2. """Upload file to FTP server."""
  3.  
  4. ftp = ftplib.FTP(host)
  5. ftp.login(username, password)
  6. full_path = os.path.join(output_path, file_name)
  7. with open(full_path, "r") as ftp_file:
  8. ftp.storbinary(" ".join(["STOR", file_name]), ftp_file.read)
  9.  
  10. @patch("ppc_model.io.ftplib.FTP")
  11. def test_store_call(self, mock_ftp):
  12. """The *storbinary* call must use the right arguments."""
  13.  
  14. with patch("ppc_model.io.open", mock_open(read_data=None)) as m:
  15. self.writer.to_ftp(output_path="./output", file_name="output.zip",
  16. host="myftp", username="username", password="password")
  17. mock_ftp.return_value.storbinary.assert_called_once_with(
  18. "STOR output.zip", m.read())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement