def test_last_modified(self): dt = pytz.UTC.localize(dateparser.parse('27 Apr 10:26')) with mock.patch('ftplib.FTP') as ftp_class: ftp = ftp_class.return_value ftp.dir.side_effect = self.mock_ftp_dir('*.zip', 10) downloader = FtpDownloader('host', 'user', 'pass') downloader.list('*.zip') last_modified = downloader.last_modified('1.zip') self.assertEqual(dt, last_modified)
def test_find_dir_with_latest_file_matching(self): mock_files = ['dir-a/file-2014-05-06', 'dir-b/file-2015-06-07', 'dir-c/file-2015-10-29'] with mock.patch('ftplib.FTP'): downloader = FtpDownloader('host', 'user', 'pass') downloader.list = mock.MagicMock(return_value=mock_files) self.assertEqual( downloader.find_dir_with_latest_file_matching('*/file-*'), 'dir-c' )
def test_find_dir_with_latest_file_matching(self): mock_files = [ 'dir-a/file-2014-05-06', 'dir-b/file-2015-06-07', 'dir-c/file-2015-10-29' ] with mock.patch('ftplib.FTP'): downloader = FtpDownloader('host', 'user', 'pass') downloader.list = mock.MagicMock(return_value=mock_files) self.assertEqual( downloader.find_dir_with_latest_file_matching('*/file-*'), 'dir-c')
def test_list_files(self): num_files = 10 pattern = '*.zip' with mock.patch('ftplib.FTP') as ftp_class: ftp = ftp_class.return_value ftp.dir.side_effect = self.mock_ftp_dir(pattern, num_files) downloader = FtpDownloader('host', 'user', 'pass') files = downloader.list(pattern) ftp.dir.assertCalledWith(pattern) self.assertEqual(num_files, len(files)) for i in range(num_files): self.assertEqual('%s.zip' % i, files[i])