-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from adybbroe/feature-netrc-authentication
Get username and password from .netrc file if available
- Loading branch information
Showing
3 changed files
with
111 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/python | ||
# Copyright (c) 2015. | ||
# Copyright (c) 2015, 2020. | ||
# | ||
|
||
# Author(s): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2020 Pytroll | ||
|
||
# Author(s): | ||
|
||
# Adam.Dybbroe <[email protected]> | ||
|
||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
|
||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
|
||
# GNU General Public License for more details. | ||
|
||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Test the movers | ||
""" | ||
|
||
from unittest.mock import patch | ||
|
||
|
||
@patch('netrc.netrc') | ||
def test_open_connection(netrc): | ||
"""Check getting the netrc authentication.""" | ||
from trollmoves.movers import FtpMover | ||
|
||
username = 'myusername' | ||
password = 'mypasswd' | ||
account = None | ||
|
||
origin = '/path/to/mydata/filename.ext' | ||
|
||
netrc.side_effect = FileNotFoundError('Failed retrieve authentification details from netrc file') | ||
|
||
with patch('trollmoves.movers.FTP') as mymock: | ||
destination = 'ftp://localhost.smhi.se/data/satellite/archive/' | ||
ftp_mover = FtpMover(origin, destination) | ||
ftp_mover.open_connection() | ||
|
||
mymock.return_value.login.assert_called_once_with() | ||
|
||
netrc.return_value.hosts = {'localhost.smhi.se': ('myusername', None, 'mypasswd')} | ||
netrc.return_value.authenticators.return_value = (username, account, password) | ||
netrc.side_effect = None | ||
|
||
with patch('trollmoves.movers.FTP') as mymock: | ||
destination = 'ftp://localhost.smhi.se/data/satellite/archive/' | ||
ftp_mover = FtpMover(origin, destination) | ||
ftp_mover.open_connection() | ||
|
||
mymock.return_value.login.assert_called_once_with(username, password) | ||
|
||
with patch('trollmoves.movers.FTP') as mymock: | ||
destination = 'ftp://auser:[email protected]/data/satellite/archive/' | ||
ftp_mover = FtpMover(origin, destination) | ||
ftp_mover.open_connection() | ||
|
||
mymock.return_value.login.assert_called_once_with('auser', 'apasswd') |