def setUp(self): self.unit_key = { 'image_checksum': data.cirros_img_metadata['image_checksum'] } self.source_repo = Repository('repo_source') self.dest_repo = Repository('repo_dest') self.conduit = mock.MagicMock() self.config = PluginCallConfiguration({}, {})
def setUp(self): self.source_repo = Repository('repo-source') self.dest_repo = Repository('repo-dest') self.rpm_units = model_factory.rpm_units(2) self.category_units = model_factory.category_units(2) self.group_units = model_factory.group_units(2) self.group1_names = self.group_units[0].metadata[ 'default_package_names'] self.group2_names = self.group_units[1].metadata[ 'default_package_names'] self.conduit = mock.MagicMock() self.config = PluginCallConfiguration({}, {}, {})
def test_relative_path_conflicts_with_both(self): repo = Repository('test') config = {'relative_url': 'zoo_repo'} conflicting_distributor = [{ 'repo_id': 'zoo_repo', 'config': { 'relative_url': 'zoo_repo' } }, { 'repo_id': 'zoo_repo', 'config': {} }] conduit = mock.MagicMock() conduit.get_repo_distributors_by_relative_url = mock.MagicMock( return_value=conflicting_distributor) error_messages = [] configuration._check_for_relative_path_conflicts( repo, config, conduit, error_messages) messages = [ ('Relative URL [zoo_repo] for repository [test] conflicts with existing ' 'relative URL [zoo_repo] for repository [zoo_repo]'), ('Relative URL [zoo_repo] for repository [test] conflicts with repo id for ' 'existing repository [zoo_repo]') ] self.assertEqual(len(error_messages), 2) self.assertEqual(error_messages, messages)
def test_ensure_tz_specified(self): """ If the timezone is specified, the result should be the same. """ dt = datetime.datetime.now(dateutils.local_tz()) new_date = Repository._ensure_tz_specified(dt) self.assertEquals(new_date.tzinfo, dateutils.utc_tz())
def test_ensure_tz_none_object(self): """ Test _ensure_tz_specified with None. """ dt = None new_date = Repository._ensure_tz_specified(dt) self.assertEquals(new_date, None)
def test_ensure_tz_not_specified(self): """ Make sure that a date without a timezone is given one. """ dt = datetime.datetime.utcnow() new_date = Repository._ensure_tz_specified(dt) self.assertEquals(new_date.tzinfo, dateutils.utc_tz())
def setUp(self): super(TestSyncRepo, self).setUp() self.repo = Repository('repo1', working_dir='/a/b/c') self.repo.repo_obj = model.Repository(repo_id=self.repo.id) self.sync_conduit = mock.MagicMock() self.config = mock.MagicMock() self.importer = DockerImporter()
def test_publish_repo(self, mock_publisher): repo = Repository('test') config = PluginCallConfiguration(None, None) conduit = RepoPublishConduit(repo.id, 'foo_repo') self.distributor.publish_repo(repo, conduit, config) mock_publisher.return_value.assert_called_once()
def setUp(self): self.metadata_files = metadata.MetadataFiles('http://pulpproject.org', '/a/b/c', DownloaderConfig()) self.repo = Repository('repo1') self.config = PluginCallConfiguration({}, {}) self.conduit = RepoSyncConduit(self.repo.id, 'yum_importer', 'abc123')
def _init_publisher(self): repo = Repository(self.repo_id, working_dir=self.working_dir) self.repo = repo conduit = RepoPublishConduit(repo.id, YUM_DISTRIBUTOR_ID) conduit.last_publish = mock.Mock(return_value=None) conduit.get_repo_scratchpad = mock.Mock(return_value={}) config_defaults = {'http': True, 'https': True, 'relative_url': None, 'http_publish_dir': os.path.join(self.published_dir, 'http'), 'https_publish_dir': os.path.join(self.published_dir, 'https')} config = PluginCallConfiguration(None, None) config.default_config.update(config_defaults) self.publisher = publish.BaseYumRepoPublisher(repo, conduit, config, YUM_DISTRIBUTOR_ID, working_dir=self.working_dir) self.publisher.get_checksum_type = mock.Mock(return_value=None) # mock out the repomd_file_context, so _publish_<step> can be called # outside of the publish() method self.publisher.repomd_file_context = mock.MagicMock() self.publisher.all_steps = mock.MagicMock()
def setUp(self): self.repo = Repository('repo_source') self.conduit = mock.MagicMock() self.config = PluginCallConfiguration({}, {}) self.mock_unit = mock.Mock(type_id=constants.IMAGE_TYPE_ID, unit_key={'image_id': 'foo'}, metadata={})
def test_cert_based_auth_ca_no_cert(self, mock_delete_protected_repo): repo = Repository('test') config = {'auth_ca': 'looks not so legit'} configuration.process_cert_based_auth(repo, config) mock_delete_protected_repo.assert_called_once_with(repo.id)
def setUp(self): self.working_dir = tempfile.mkdtemp() self.repo = Repository('test') self.repo.working_dir = self.working_dir self.config = PluginCallConfiguration(None, None) self.conduit = RepoPublishConduit(self.repo.id, TYPE_ID_DISTRIBUTOR_EXPORT)
def test_remove_cert_based_auth(self, mock_delete_protected_repo): repo = Repository('test') config = {} configuration.remove_cert_based_auth(repo, config) mock_delete_protected_repo.assert_called_once_with(repo.id)
def test_validate_config(self, *mock_methods): config_kwargs = {'http': True, 'https': True, 'relative_url': None, 'auth_ca': 'CA', 'auth_cert': 'CERT', 'checksum_type': 'sha256', 'http_publish_dir': '/http/path/', 'https_publish_dir': 'https/path/', 'protected': True, 'skip': {'drpms': 1}, 'skip_pkg_tags': True, 'generate_sqlite': False} repo = Repository('test') config = self._generate_call_config(**config_kwargs) conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM) valid, reasons = configuration.validate_config(repo, config, conduit) for mock_method in mock_methods: self.assertEqual(mock_method.call_count, 1) self.assertTrue(valid) self.assertEqual(reasons, None)
def test_uses_passed_available_units_when_requested(self, mock_find_units, mock_associate): """ Assert that if the step is constructed with available_units passed in, the step's parent's available_units attribute is ignored. """ demo_1 = self.DemoModel(key_field='a') demo_2 = self.DemoModel(key_field='b') demo_3 = self.DemoModel(key_field='c') self.parent.available_units = [demo_1, demo_2] available_units = [demo_1, demo_2, demo_3] fake_repo = Repository(id='fake-repo', repo_obj='fake_repo') step = publish_step.GetLocalUnitsStep('fake_importer_type', repo=fake_repo, available_units=available_units) step.parent = self.parent step.conduit = MagicMock() existing_demo = self.DemoModel(key_field='b', id='foo') mock_find_units.return_value = [existing_demo] step.process_main() # The parent step's available units only has demo 1 and 2, so this asserts that that is # being ignored and the correct available_units is being used instead. mock_find_units.assert_called_once_with((demo_1, demo_2, demo_3)) # the one that exists is associated mock_associate.assert_called_once_with('fake_repo', existing_demo) # the two that do not exist yet are added to the download list self.assertEqual(step.units_to_download, [demo_1, demo_3])
def setUp(self): super(TestGetLocalUnitsStep, self).setUp() self.parent = MagicMock() fake_repo = Repository(id='fake-repo', repo_obj='fake_repo') self.step = publish_step.GetLocalUnitsStep('fake_importer_type', repo=fake_repo) self.step.parent = self.parent self.step.conduit = MagicMock() self.parent.available_units = []
def test_get_repo_relative_path_repo_id(self): repo_id = 'Highlander' repo = Repository(repo_id) config = self._generate_call_config() relative_dir = configuration.get_repo_relative_path(repo, config) self.assertEqual(relative_dir, repo_id)
def test_publish_repo(self, mock_publish): repo = Repository('test') config = PluginCallConfiguration(None, None) conduit = RepoPublishConduit(repo.id, TYPE_ID_DISTRIBUTOR_YUM) self.distributor.publish_repo(repo, conduit, config) mock_publish.Publisher.return_value.publish.assert_called_once()
def test_validate_config(self, mock_validate_config): repo = Repository('test') config = PluginCallConfiguration(None, None) conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM) self.distributor.validate_config(repo, config, conduit) mock_validate_config.assert_called_once_with(repo, config, conduit)
def setUp(self): self.working_dir = tempfile.mkdtemp(prefix='puppet-sync-tests') self.repo = Repository('test-repo', working_dir=self.working_dir) self.conduit = MockConduit() self.config = PluginCallConfiguration({}, { constants.CONFIG_FEED: FEED, }) self.method = SynchronizeWithPuppetForge(self.repo, self.conduit, self.config)
def test_init_no_values(self): repo = Repository('foo') self.assertEquals('foo', repo.id) self.assertEquals(None, repo.display_name) self.assertEquals(None, repo.description) self.assertEquals(None, repo.notes) self.assertEquals(None, repo.working_dir) self.assertEquals({}, repo.content_unit_counts) self.assertEquals(None, repo.last_unit_added) self.assertEquals(None, repo.last_unit_removed)
def test_get_repo_relative_path_configured(self): repo_id = 'Spaniard' repo = Repository(repo_id) configured_relative_url = '/there/can/be/only/one/' config = self._generate_call_config(relative_url=configured_relative_url) relative_url = configuration.get_repo_relative_path(repo, config) # get_relative_path should strip off the leading '/' self.assertEqual(relative_url, configured_relative_url[1:])
def setUp(self): self.working_dir = tempfile.mkdtemp(prefix='working_') self.repo_id = 'publish-test-repo' self.repo = Repository(self.repo_id, working_dir=self.working_dir) self.conduit = RepoPublishConduit(self.repo_id, 'test_plugin_id') self.conduit.get_repo_scratchpad = Mock(return_value={}) self.config = PluginCallConfiguration(None, None) self.pluginstep = PluginStep("base-step", repo=self.repo, conduit=self.conduit, config=self.config, plugin_type='test_plugin_type')
def test_sync_calls_sync(self, mock_sync_run): repo = Repository('repo1') sync_conduit = importer_mocks.get_sync_conduit(pkg_dir='/a/b/c') config = importer_mocks.get_basic_config( **{importer_constants.KEY_FEED: 'http://fake.com/iso_feed/'}) self.iso_importer.sync_repo(repo, sync_conduit, config) # make sure the sync workflow is called with the right stuff mock_sync_run.assert_called_once_with(sync_conduit, config) mock_sync_run.return_value.perform_sync.assert_called_once_with()
def test_cert_based_auth_ca_and_cert(self, mock_write_consumer_cert_bundle, mock_add_protected_repo): repo = Repository('test') config = {'auth_ca': 'looks legit', 'auth_cert': '1234567890'} bundle = {'ca': config['auth_ca'], 'cert': config['auth_cert']} configuration.process_cert_based_auth(repo, config) mock_write_consumer_cert_bundle.assert_called_once_with(repo.id, bundle) mock_add_protected_repo.assert_called_once_with(repo.id, repo.id)
def setUp(self): self.working_dir = tempfile.mkdtemp(prefix='puppet-sync-tests') self.repo = Repository('test-repo', working_dir=self.working_dir) self.conduit = MockConduit() self.config = PluginCallConfiguration({}, { constants.CONFIG_FEED: FEED, }) self.is_cancelled_call = mock.MagicMock().is_cancelled_call self.run = PuppetModuleSyncRun(self.repo, self.conduit, self.config, self.is_cancelled_call)
def test_relative_path_conflicts_none(self): repo = Repository('test') config = {} conduit = mock.MagicMock() conduit.get_repo_distributors_by_relative_url = mock.MagicMock(return_value=[]) error_messages = [] configuration._check_for_relative_path_conflicts(repo, config, conduit, error_messages) self.assertEqual(conduit.get_repo_distributors_by_relative_url.call_count, 1) self.assertEqual(len(error_messages), 0)
def setUp(self): self.temp_dir = tempfile.mkdtemp() self.working_directory = os.path.join(self.temp_dir, 'working') self.publish_directory = os.path.join(self.temp_dir, 'publish') self.content_directory = os.path.join(self.temp_dir, 'content') os.makedirs(self.working_directory) os.makedirs(self.publish_directory) os.makedirs(self.content_directory) repo = Repository('foo_repo_id', working_dir=self.working_directory) config = PluginCallConfiguration(None, None) conduit = RepoPublishConduit(repo.id, 'foo_repo') self.parent = PublishStep('test-step', repo, conduit, config)
def setUp(self): self.working_directory = tempfile.mkdtemp() self.source_dir = os.path.join(self.working_directory, 'src') self.target_dir = os.path.join(self.working_directory, 'target') os.makedirs(self.source_dir) os.makedirs(self.target_dir) self.repo = Repository(id='foo', working_dir=self.target_dir) config = PluginCallConfiguration(None, None) conduit = RepoPublishConduit(self.repo.id, 'foo_repo') conduit.get_repo_scratchpad = Mock(return_value={}) self.parent = steps.PluginStep('test-step', self.repo, conduit, config)
def test_finalize(self, mock_repo_controller): repo = Repository('repo1') repo.repo_obj = model.Repository(repo_id=repo.id) step = publish_step.SaveUnitsStep('foo_type', repo=repo) step.finalize() mock_repo_controller.rebuild_content_unit_counts.assert_called_once_with(repo.repo_obj)