def handle(self, *args, **options):
        destination_dir = None
        if len(args) == 1:
            destination_dir = args[0]
        destination_dir = destination_dir or "/tmp/addressbase_basic"

        downloader = AddressBaseBasicDownloader()
        downloaded_files = downloader.download(destination_dir)
    def handle(self, *args, **options):
        destination_dir = None
        if len(args) == 1:
            destination_dir = args[0]
        destination_dir = destination_dir or '/tmp/addressbase_basic'

        downloader = AddressBaseBasicDownloader()
        downloaded_files = downloader.download(destination_dir)
 def test_downloads_files_matching_pattern(self):
     self._mock_find_dir()
     with mock.patch('ftplib.FTP') as ftp_class, self.mock_env():
         ftp = ftp_class.return_value
         AddressBaseBasicDownloader().download(self.root_dir.full_path)
         self.assertTrue(ftp.dir.called)
         self.assertEqual('*_csv.zip', ftp.dir.call_args[0][0])
 def test_passes_ftp_credentials(self):
     with mock.patch('ftplib.FTP') as ftp_class, self.mock_env():
         ftp = ftp_class.return_value
         AddressBaseBasicDownloader().download(self.root_dir.full_path)
         ftp_class.assertCalledWith('osmmftp.os.uk')
         ftp.login.assertCalledWith(self.env['OS_FTP_USERNAME'],
                                    self.env['OS_FTP_PASSWORD'])
         ftp.cwd.assertCalledWith(self.env['OS_FTP_ORDER_DIR'])
    def test_complains_if_ftp_credentials_not_set(self):
        self._mock_find_dir()
        logger = 'postcode_api.downloaders.addressbase_basic.log'
        with mock.patch('ftplib.FTP'), \
                mock.patch(logger) as log, \
                self.mock_env({}):

            AddressBaseBasicDownloader().download(self.root_dir.full_path)

            log.error.assert_has_calls([
                mock.call('OS_FTP_USERNAME not set!'),
                mock.call('OS_FTP_PASSWORD not set!')
            ])
 def _download(self, destination_dir):
     print 'downloading'
     downloader = AddressBaseBasicDownloader()
     return downloader.download(destination_dir)
 def test_finds_dir_with_latest_full_file(self):
     self._mock_find_dir()
     with mock.patch('ftplib.FTP'), self.mock_env():
         dl = AddressBaseBasicDownloader()
         dl.download(self.root_dir.full_path)
         self.assertTrue(dl.find_dir_with_latest_full_file.called)
 def test_finds_dir_with_latest_full_file(self):
     self._mock_find_dir()
     with mock.patch('ftplib.FTP'), self.mock_env():
         dl = AddressBaseBasicDownloader()
         dl.download(self.root_dir.full_path)
         self.assertTrue(dl.find_dir_with_latest_full_file.called)