Changeset 104

Show
Ignore:
Timestamp:
2002-03-29 21:50:41 (7 years ago)
Author:
schwa
Message:
FTPHostWrapper: constructor now takes one argument, the factory to use.
TestLogin.test_invalid_login: rewritten to use failing session class.
TestLogin.test_invalid_login: removed assertion that on failed login
    the risen exception has to be _identical_ to FTPOSError, not one
    of its derived classes. (ftplib.FTP raises an error_perm on failed
    logins!)
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/_test_ftputil.py

    r100 r104  
    3030# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    3131 
    32 # $Id: _test_ftputil.py,v 1.22 2002/03/29 18:33:55 schwa Exp $ 
     32# $Id: _test_ftputil.py,v 1.23 2002/03/29 21:50:41 schwa Exp $ 
    3333 
    3434# Ideas for future development: 
     
    4343import time 
    4444import operator 
     45import _mock_ftplib 
    4546 
    4647class FTPHostWrapper(ftputil.FTPHost): 
    47     def __init__(self, *args, **kwargs): 
    48         import _mock_ftplib 
    49         kwargs['session_factory'] = _mock_ftplib.FTP 
    50         ftputil.FTPHost.__init__(self, *args, **kwargs) 
     48    def __init__(self, session_factory): 
     49        ftputil.FTPHost.__init__(self, 'dummy_host', 'dummy_user', 
     50          'dummy_password', session_factory=session_factory) 
    5151 
    5252 
     
    5555 
    5656    def setUp(self): 
    57         self.host = FTPHostWrapper(host_name, user, password
     57        self.host = FTPHostWrapper(
    5858        self.rootdir = self.host.getcwd() 
    5959        self.testdir = self.host.path.join( 
     
    6868 
    6969 
     70 
    7071class TestLogin(unittest.TestCase): 
    7172    """Test invalid logins.""" 
     
    7576        # plain FTPOSError, no derived class 
    7677        self.assertRaises(ftputil.FTPOSError, FTPHostWrapper, 
    77           'nonexistent.ho.st.na.me', 'me', 'password') 
    78         try: 
    79             FTPHostWrapper('nonexistent.ho.st.na.me') 
    80         except ftputil.FTPOSError, obj: 
    81             pass 
    82         self.failUnless(obj.__class__ is ftputil.FTPOSError) 
     78                          _mock_ftplib.FailOnLoginSession) 
    8379 
    8480 
     
    598594 
    599595if __name__ == '__main__': 
    600     host_name = 'ftp.ndh.net' 
    601     user = 'sschwarzer' 
    602     password = getpass.getpass('Password for %s@%s: ' % 
    603                                (user, host_name) ) 
    604596    unittest.main() 
    605597