Changeset 1494:30df847fea39


Ignore:
Timestamp:
Apr 21, 2014, 12:04:51 PM (5 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Added unit tests for `session_factory` helper.

Most tests are done with a mock class, but there's also a test in
`test_real_ftp.py` that will use `M2Crypto.ftpslib.FTP_TLS` to check
if the workaround in the `Session` class in
`ftputil.session.session_factory` works.

Note that since M2Crypto isn't available for Python 3, the real
FTP test is skipped for Python 3. (This requires the `unittest2`
module or here the `unittest` in Python 2.7 and 3.3.)
Location:
test
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • test/test_real_ftp.py

    r1460 r1494  
    2121import ftputil.error
    2222import ftputil.file_transfer
     23import ftputil.session
    2324import ftputil.stat_cache
    2425
     
    816817        self.assertFalse(objects_after_test - objects_before_test)
    817818
     819    @unittest.skipIf(ftputil.compat.python_version > 2,
     820                     "test requires M2Crypto which only works on Python 2")
     821    def test_m2crypto_session(self):
     822        """
     823        Test if a session with `M2Crypto.ftpslib.FTP_TLS` is set up
     824        correctly and works with unicode input.
     825        """
     826        # See ticket #78.
     827        #
     828        # M2Crypto is only available for Python 2.
     829        import M2Crypto
     830        factory = ftputil.session.session_factory(
     831                    base_class=M2Crypto.ftpslib.FTP_TLS,
     832                    encrypt_data_channel=True)
     833        with ftputil.FTPHost(*self.login_data, session_factory=factory) as host:
     834            # Test if unicode argument works.
     835            files = host.listdir(".")
     836        self.assertTrue("CONTENTS" in files)
     837
     838
    818839
    819840if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.