Changeset 849:0997baf2fa68

Show
Ignore:
Timestamp:
2010-02-11 20:36:28 (6 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Added unit test for download operations. Improved `make_file` method.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • _test_real_ftp.py

    r843 r849  
    1 # Copyright (C) 2003-2009, Stefan Schwarzer 
     1# Copyright (C) 2003-2010, Stefan Schwarzer 
    22# All rights reserved. 
    33# 
     
    139139        self.cleaner.add_file(path) 
    140140        file_ = self.host.file(path, 'wb') 
     141        # write something; otherwise the FTP server might not update 
     142        #  the time of last modification if the file existed before 
     143        file_.write("\n") 
    141144        file_.close() 
    142145 
    143146    def make_local_file(self): 
    144         fobj = file('_localfile_', 'wb') 
     147        fobj = file('_local_file_', 'wb') 
    145148        fobj.write("abc\x12\x34def\t") 
    146149        fobj.close() 
     
    459462        host = self.host 
    460463        host.synchronize_times() 
     464        local_file = '_local_file_' 
     465        remote_file = '_remote_file_' 
    461466        # make local file and upload it 
    462467        self.make_local_file() 
     
    465470        time.sleep(65) 
    466471        try: 
    467             self.cleaner.add_file('_remotefile_') 
    468             host.upload('_localfile_', '_remotefile_', 'b') 
     472            self.cleaner.add_file(remote_file) 
     473            host.upload(local_file, remote_file, 'b') 
    469474            # retry; shouldn't be uploaded 
    470             uploaded = host.upload_if_newer('_localfile_', '_remotefile_', 'b') 
     475            uploaded = host.upload_if_newer(local_file, remote_file, 'b') 
    471476            self.assertEqual(uploaded, False) 
    472477            # rewrite the local file 
    473478            self.make_local_file() 
    474             time.sleep(65) 
    475479            # retry; should be uploaded now 
    476             uploaded = host.upload_if_newer('_localfile_', '_remotefile_', 'b') 
     480            uploaded = host.upload_if_newer(local_file, remote_file, 'b') 
    477481            self.assertEqual(uploaded, True) 
    478482        finally: 
    479483            # clean up 
    480             os.unlink('_localfile_') 
     484            os.unlink(local_file) 
     485 
     486    def test_download(self): 
     487        host = self.host 
     488        host.synchronize_times() 
     489        local_file = '_local_file_' 
     490        remote_file = '_remote_file_' 
     491        # make a remote file 
     492        self.make_file(remote_file) 
     493        # file should be downloaded as it's not present yet 
     494        downloaded = host.download_if_newer(remote_file, local_file, 'b') 
     495        self.assertEqual(downloaded, True) 
     496        try: 
     497            # local file is present and newer, so shouldn't download 
     498            downloaded = host.download_if_newer(remote_file, local_file, 'b') 
     499            self.assertEqual(downloaded, False) 
     500            # wait; else small time differences between client and server 
     501            #  actually could trigger the update 
     502            time.sleep(65) 
     503            # re-make the remote file 
     504            self.make_file(remote_file) 
     505            # local file is present but older, so should download 
     506            downloaded = host.download_if_newer(remote_file, local_file, 'b') 
     507            self.assertEqual(downloaded, True) 
     508        finally: 
     509            # clean up 
     510            os.unlink(local_file) 
    481511 
    482512    # 
     
    486516        host = self.host 
    487517        self.assertRaises(ftp_error.PermanentError, host.remove, "nonexistent") 
    488      
     518 
    489519    def test_remove_existent_file(self): 
    490520        self.cleaner.add_file('_testfile_')