def test_get_local_downloader(self, to_nectar, local): url = 'file:///martin.com/test' config = Mock() # test downloader = Importer.get_downloader(config, url) # validation to_nectar.assert_called_once_with(config.flatten.return_value, working_dir=None) local.assert_called_once_with(to_nectar.return_value) self.assertEqual(downloader, local.return_value)
def test_local(self): """ Test with a file:// scheme. """ url = 'file:///martin.com/test' nectar_config = config.DownloaderConfig(max_concurrent=23) downloader = Importer.build_downloader(url, nectar_config) self.assertTrue(isinstance(downloader, local.LocalFileDownloader)) self.assertEqual(downloader.config.max_concurrent, 23)
def test_http(self): """ Test with http:// as the scheme. """ url = 'http://martin.com/test' nectar_config = config.DownloaderConfig(max_speed=42) downloader = Importer.build_downloader(url, nectar_config) self.assertTrue(isinstance(downloader, threaded.HTTPThreadedDownloader)) self.assertEqual(downloader.config.max_speed, 42)
def test_get_https_downloader(self, to_nectar, http): url = 'https://martin.com/test' config = Mock() # test downloader = Importer.get_downloader(config, url) # validation to_nectar.assert_called_once_with(config.flatten.return_value) http.assert_called_once_with(to_nectar.return_value) self.assertEqual(downloader, http.return_value)
def test_local(self): """ Test with a file:// scheme. """ url = 'file:///martin.com/test' importer = Mock() importer.config = {importer_constants.KEY_MAX_DOWNLOADS: 123} downloader = Importer.get_downloader_for_db_importer(importer, url, '/working/dir') self.assertTrue(isinstance(downloader, local.LocalFileDownloader)) self.assertEqual(downloader.config.max_concurrent, 123) self.assertEqual(downloader.config.working_dir, '/working/dir')
def test_http(self): """ Test with http:// as the scheme. """ url = 'http://martin.com/test' importer = Mock() importer.config = {importer_constants.KEY_MAX_SPEED: 5555} downloader = Importer.get_downloader_for_db_importer(importer, url, '/working/dir') self.assertTrue(isinstance(downloader, threaded.HTTPThreadedDownloader)) self.assertEqual(downloader.config.max_speed, 5555) self.assertEqual(downloader.config.working_dir, '/working/dir')
def test_https(self, _process_ssl_settings): """ Test with https:// as the scheme. """ url = 'https://martin.com/test' nectar_config = config.DownloaderConfig( ssl_ca_cert='CA Cert', ssl_ca_cert_path='/path/to/ca.crt', ssl_client_cert='Client Cert', ssl_client_cert_path='/path/to/client.crt', ssl_client_key='Client Cert', ssl_client_key_path='/path/to/client.key') downloader = Importer.build_downloader(url, nectar_config) self.assertTrue(isinstance(downloader, threaded.HTTPThreadedDownloader)) self.assertEqual(downloader.config.ssl_ca_cert_path, '/path/to/ca.crt') self.assertEqual(downloader.config.ssl_client_cert_path, '/path/to/client.crt') self.assertEqual(downloader.config.ssl_client_key_path, '/path/to/client.key') _process_ssl_settings.assert_called_once_with()
def test_https(self, _process_ssl_settings): """ Test with https:// as the scheme. """ url = 'https://martin.com/test' importer = Mock() importer.config = { importer_constants.KEY_SSL_CA_CERT: 'CA Cert', importer_constants.KEY_SSL_CLIENT_CERT: 'Client Cert', importer_constants.KEY_SSL_CLIENT_KEY: 'Client Key'} importer.tls_ca_cert_path = '/path/to/ca.crt' importer.tls_client_cert_path = '/path/to/client.crt' importer.tls_client_key_path = '/path/to/client.key' downloader = Importer.get_downloader_for_db_importer(importer, url, '/working/dir') self.assertTrue(isinstance(downloader, threaded.HTTPThreadedDownloader)) self.assertEqual(downloader.config.ssl_ca_cert_path, '/path/to/ca.crt') self.assertEqual(downloader.config.ssl_client_cert_path, '/path/to/client.crt') self.assertEqual(downloader.config.ssl_client_key_path, '/path/to/client.key') self.assertEqual(downloader.config.working_dir, '/working/dir') _process_ssl_settings.assert_called_once_with()
def test_cancel_sync_repo_calls_sys_exit(self, mock_sys_exit): Importer().cancel_sync_repo() mock_sys_exit.assert_called_once_with()