def test__url_with_repo_credentials(self): import base64 from spacewalk.satellite_tools.reposync import RepoSync credentials_id = 777 urls = [ 'http://some.url?credentials=abc_%s' % credentials_id, 'http://some-other.url' ] repo_sync = RepoSync(channel_label="channel-label", repo_type=RTYPE, url=urls) username = "******" password = "******" config = { 'return_value.fetchone_dict.return_value': { "username": "******", "password": base64.encodestring(password.encode()).decode() } } patcher = patch('spacewalk.satellite_tools.reposync.rhnSQL.prepare', **config) with patcher as mock_prepare: self.assertEqual( repo_sync._url_with_repo_credentials(urls[0]), 'http://{0}:{1}@some.url'.format(username, password)) mock_prepare.assert_called_once_with( 'SELECT username, password FROM suseCredentials WHERE id = :id' ) mock_prepare().execute.assert_called_once_with(id=credentials_id)
def test_pass_multiple_urls_params(self): from spacewalk.satellite_tools.reposync import RepoSync urls = ['http://some.url', 'http://some-other.url'] repo_sync = RepoSync(channel_label="channel-label", repo_type=RTYPE, url=urls) repo_sync.sync()
def test__url_with_repo_credentials(self): import base64 from spacewalk.satellite_tools.reposync import RepoSync credentials_id = 777 urls = [ 'http://some.url?credentials=abc_%s' % credentials_id, 'http://some-other.url' ] repo_sync = RepoSync( channel_label="channel-label", repo_type=RTYPE, url=urls ) username = "******" password = "******" config = { 'return_value.fetchone_dict.return_value': { "username": "******", "password": base64.encodestring(password) } } patcher = patch( 'spacewalk.satellite_tools.reposync.rhnSQL.prepare', **config ) with patcher as mock_prepare: self.assertEqual( repo_sync._url_with_repo_credentials(urls[0]), 'http://{0}:{1}@some.url'.format(username, password) ) mock_prepare.assert_called_once_with( 'SELECT username, password FROM suseCredentials WHERE id = :id' ) mock_prepare().execute.assert_called_once_with(id=credentials_id)
def test_pass_multiple_urls_params(self): from spacewalk.satellite_tools.reposync import RepoSync urls = ['http://some.url', 'http://some-other.url'] repo_sync = RepoSync( channel_label="channel-label", repo_type=RTYPE, url=urls ) repo_sync.sync()
def test_pass_multiple_urls_params(self): from spacewalk.satellite_tools.reposync import RepoSync urls = ['http://some.url', 'http://some-other.url'] repo_sync = RepoSync(channel_label="channel-label", repo_type=RTYPE, url=urls) repo_sync = _mock_sync(spacewalk.satellite_tools.reposync, repo_sync) CFG = Mock() CFG.MOUNT_POINT = '/tmp' CFG.PREPENDED_DIR = '' CFG.AUTO_GENERATE_BOOTSTRAP_REPO = 1 with patch("uyuni.common.context_managers.CFG", CFG): repo_sync.sync()
def test_set_repo_credentials_with_multiple_urls(self, mocked_method): from spacewalk.satellite_tools.reposync import RepoSync urls = ['http://some.url', 'http://some-other.url'] data = { 'metadata_signed': 'N', 'repo_label': None, 'id': None, 'source_url': urls, 'repo_type': 'yum' } repo_sync = RepoSync(channel_label="channel-label", repo_type=RTYPE, url=urls) repo_sync.set_repo_credentials(data) self.assertEqual(repo_sync._url_with_repo_credentials.call_args_list, [call(urls[0]), call(urls[1])])
def test_set_repo_credentials_with_multiple_urls(self, mocked_method): from spacewalk.satellite_tools.reposync import RepoSync urls = ['http://some.url', 'http://some-other.url'] data = { 'metadata_signed': 'N', 'repo_label': None, 'id': None, 'source_url': urls, 'repo_type': 'yum' } repo_sync = RepoSync( channel_label="channel-label", repo_type=RTYPE, url=urls ) repo_sync.set_repo_credentials(data) self.assertEqual( repo_sync._url_with_repo_credentials.call_args_list, [call(urls[0]), call(urls[1])] )
def test_rhnSQL_should_return_source_urls_as_list(self): from spacewalk.satellite_tools.reposync import RepoSync url1 = 'http://url.one' url2 = 'http://url.two' patcher = patch( 'spacewalk.satellite_tools.reposync.rhnSQL.prepare', **{ 'return_value.fetchall_dict.return_value': [ { 'metadata_signed': 'N', 'repo_label': 'channel-label-1', 'id': 508, 'source_url': url1, 'repo_type': 'yum' }, { 'metadata_signed': 'Y', 'repo_label': 'channel-label-2', 'id': 509, 'source_url': url2, 'repo_type': 'yum' } ] } ) with patcher as mock_prepare: repo_sync = RepoSync( channel_label="channel-label", repo_type=RTYPE ) self.assertEqual( repo_sync.urls, [ { 'metadata_signed': 'N', 'repo_label': 'channel-label-1', 'id': 508, 'source_url': [url1], 'repo_type': 'yum' }, { 'metadata_signed': 'Y', 'repo_label': 'channel-label-2', 'id': 509, 'source_url': [url2], 'repo_type': 'yum' } ] )