-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref #1281 - add get_downloader() to base importer.
- Loading branch information
Showing
2 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import unittest | ||
from unittest import TestCase | ||
|
||
import mock | ||
from mock import patch, Mock | ||
|
||
from pulp.plugins.importer import Importer | ||
|
||
|
||
class TestImporter(unittest.TestCase): | ||
class TestImporter(TestCase): | ||
|
||
@mock.patch('pulp.plugins.importer.sys.exit', autospec=True) | ||
@patch('pulp.plugins.importer.LocalFileDownloader') | ||
@patch('pulp.plugins.importer.importer_config_to_nectar_config') | ||
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) | ||
local.assert_called_once_with(to_nectar.return_value) | ||
self.assertEqual(downloader, local.return_value) | ||
|
||
@patch('pulp.plugins.importer.HTTPThreadedDownloader') | ||
@patch('pulp.plugins.importer.importer_config_to_nectar_config') | ||
def test_get_http_downloader(self, to_nectar, http): | ||
url = 'http://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) | ||
|
||
@patch('pulp.plugins.importer.HTTPThreadedDownloader') | ||
@patch('pulp.plugins.importer.importer_config_to_nectar_config') | ||
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) | ||
|
||
@patch('pulp.plugins.importer.importer_config_to_nectar_config', Mock()) | ||
def test_get_downloader_invalid_scheme(self): | ||
url = 'ftpx://martin.com/test' | ||
self.assertRaises(ValueError, Importer.get_downloader, Mock(), url) | ||
|
||
@patch('pulp.plugins.importer.sys.exit', autospec=True) | ||
def test_cancel_sync_repo_calls_sys_exit(self, mock_sys_exit): | ||
Importer().cancel_sync_repo() | ||
mock_sys_exit.assert_called_once_with() |