Exemple #1
0
    def test_delete(self, mock_get_distributor, mock_delete):
        mock_get_distributor.return_value = None

        RepoPublishScheduleManager.delete(self.repo, self.distributor,
                                          self.schedule_id)

        mock_delete.assert_called_once_with(self.schedule_id)
Exemple #2
0
    def test_matching_distributor(self, mock_get_distributor):
        mock_get_distributor.return_value = None

        RepoPublishScheduleManager.validate_distributor(
            'repo1', 'distributor1')

        mock_get_distributor.assert_called_once_with('repo1', 'distributor1')
Exemple #3
0
    def test_update_overrides(self, mock_get_distributor, mock_update):
        mock_get_distributor.return_value = None

        RepoPublishScheduleManager.update(self.repo, self.distributor, self.schedule_id,
                                       {'override_config': {'foo': 'bar'}})

        mock_update.assert_called_once_with(self.schedule_id,
                                            {'kwargs': {'overrides': {'foo': 'bar'}}})
Exemple #4
0
    def test_validate_options(self, mock_get_distributor,
                              mock_validate_options, mock_update):
        mock_get_distributor.return_value = {'id': self.distributor}

        RepoPublishScheduleManager.update(self.repo, self.distributor,
                                          self.schedule_id, self.updates)

        mock_validate_options.assert_called_once_with(self.updates)
Exemple #5
0
    def test_calls_delete_resource(self, mock_delete_by):
        resource = RepoDistributor.build_resource_tag(self.repo,
                                                      self.distributor)

        RepoPublishScheduleManager.delete_by_distributor_id(
            self.repo, self.distributor)

        mock_delete_by.assert_called_once_with(resource)
Exemple #6
0
    def test_update_overrides(self, mock_get_distributor, mock_update):
        mock_get_distributor.return_value = None

        RepoPublishScheduleManager.update(
            self.repo, self.distributor, self.schedule_id, {"override_config": {"foo": "bar"}}
        )

        mock_update.assert_called_once_with(self.schedule_id, {"kwargs": {"overrides": {"foo": "bar"}}})
Exemple #7
0
    def test_utils_validation(self, mock_validate_keys, mock_validate_options,
                              mock_validate_distributor, mock_save):
        RepoPublishScheduleManager.create(self.repo, self.distributor,
                                          self.options, self.schedule)

        mock_validate_keys.assert_called_once_with(self.options,
                                                   ('override_config', ))
        mock_validate_options.assert_called_once_with(self.schedule, None,
                                                      True)
Exemple #8
0
    def remove_distributor(repo_id, distributor_id):
        """
        Removes a distributor from a repository.

        @param repo_id: identifies the repo
        @type  repo_id: str

        @param distributor_id: identifies the distributor to delete
        @type  distributor_id: str

        @raise MissingResource: if repo_id doesn't correspond to a valid repo
        @raise MissingResource: if there is no distributor with the given ID
        """

        distributor_coll = RepoDistributor.get_collection()
        repo_obj = model.Repository.objects.get_repo_or_missing_resource(repo_id)

        repo_distributor = distributor_coll.find_one({'repo_id': repo_id, 'id': distributor_id})
        if repo_distributor is None:
            raise MissingResource(distributor=distributor_id)

        # remove schedules
        RepoPublishScheduleManager().delete_by_distributor_id(repo_id, repo_distributor['id'])

        # Call the distributor's cleanup method
        distributor_type_id = repo_distributor['distributor_type_id']
        distributor_instance, plugin_config = plugin_api.get_distributor_by_id(distributor_type_id)

        call_config = PluginCallConfiguration(plugin_config, repo_distributor['config'])

        transfer_repo = repo_obj.to_transfer_repo()
        distributor_instance.distributor_removed(transfer_repo, call_config)

        # Update the database to reflect the removal
        distributor_coll.remove({'_id': repo_distributor['_id']}, safe=True)
Exemple #9
0
    def test_update(self, mock_get_distributor, mock_update):
        mock_get_distributor.return_value = {'id': self.distributor}

        ret = RepoPublishScheduleManager.update(self.repo, self.distributor, self.schedule_id, self.updates)

        mock_update.assert_called_once_with(self.schedule_id, self.updates)
        # make sure it passes through the return value from utils.update
        self.assertEqual(ret, mock_update.return_value)
Exemple #10
0
    def test_update(self, mock_get_distributor, mock_update):
        mock_get_distributor.return_value = {"id": self.distributor}

        ret = RepoPublishScheduleManager.update(self.repo, self.distributor, self.schedule_id, self.updates)

        mock_update.assert_called_once_with(self.schedule_id, self.updates)
        # make sure it passes through the return value from utils.update
        self.assertEqual(ret, mock_update.return_value)
Exemple #11
0
    def test_save(self, m_dist_qs, m_save):
        ret = RepoPublishScheduleManager.create(
            self.repo_id, self.distributor_id, self.options, self.schedule, 3, False
        )

        m_save.assert_called_once_with()
        self.assertTrue(isinstance(ret, ScheduledCall))
        self.assertEqual(ret.iso_schedule, self.schedule)
        self.assertEqual(ret.failure_threshold, 3)
        self.assertTrue(ret.enabled is False)
Exemple #12
0
    def test_save(self, mock_get_distributor, mock_save):
        mock_get_distributor.return_value = {"id": "distributor1"}

        ret = RepoPublishScheduleManager.create(self.repo, self.distributor, self.options, self.schedule, 3, False)

        mock_save.assert_called_once_with()
        self.assertTrue(isinstance(ret, ScheduledCall))
        self.assertEqual(ret.iso_schedule, self.schedule)
        self.assertEqual(ret.failure_threshold, 3)
        self.assertTrue(ret.enabled is False)
Exemple #13
0
    def test_save(self, mock_get_distributor, mock_save):
        mock_get_distributor.return_value = {'id': 'distributor1'}

        ret = RepoPublishScheduleManager.create(self.repo, self.distributor, self.options,
                                                self.schedule, 3, False)

        mock_save.assert_called_once_with()
        self.assertTrue(isinstance(ret, ScheduledCall))
        self.assertEqual(ret.iso_schedule, self.schedule)
        self.assertEqual(ret.failure_threshold, 3)
        self.assertTrue(ret.enabled is False)
Exemple #14
0
 def test_list(self, mock_get_by_resource, m_dist_qs):
     ret = RepoPublishScheduleManager.list("repo1", "distributor1")
     mock_get_by_resource.assert_called_once_with(m_dist_qs.get_or_404.return_value.resource_tag)
     self.assertTrue(ret is mock_get_by_resource.return_value)
Exemple #15
0
 def test_validate_options(self, mock_validate_options, mock_update, m_dist_qs):
     RepoPublishScheduleManager.update(self.repo, self.distributor, self.schedule_id, self.updates)
     mock_validate_options.assert_called_once_with(self.updates)
Exemple #16
0
 def test_delete(self, m_dist_qs, m_delete):
     RepoPublishScheduleManager.delete(self.repo_id, self.distributor_id, self.schedule_id)
     m_dist_qs.get_or_404.assert_called_once_with(repo_id=self.repo_id, distributor_id=self.distributor_id)
     m_delete.assert_called_once_with(self.schedule_id)
Exemple #17
0
 def test_calls_delete_resource(self, m_dist_qs, mock_delete_by):
     RepoPublishScheduleManager.delete_by_distributor_id(self.repo, self.distributor)
     distributor = m_dist_qs.get_or_404.return_value
     mock_delete_by.assert_called_once_with(distributor.resource_tag)
Exemple #18
0
    def test_validate_distributor(self, mock_get_by_resource, mock_validate_distributor):
        RepoPublishScheduleManager.list("repo1", "distributor1")

        mock_validate_distributor.assert_called_once_with("repo1", "distributor1")
Exemple #19
0
    def test_list(self, mock_get_by_resource, mock_validate_distributor):
        ret = RepoPublishScheduleManager.list('repo1', 'distributor1')

        mock_get_by_resource.assert_called_once_with(
            RepoDistributor.build_resource_tag('repo1', 'distributor1'))
        self.assertTrue(ret is mock_get_by_resource.return_value)
Exemple #20
0
    def test_validate_distributor(self, mock_get_by_resource,
                                  mock_validate_distributor):
        RepoPublishScheduleManager.list('repo1', 'distributor1')

        mock_validate_distributor.assert_called_once_with(
            'repo1', 'distributor1')
Exemple #21
0
    def test_matching_distributor(self, mock_get_distributor):
        mock_get_distributor.return_value = None

        RepoPublishScheduleManager.validate_distributor("repo1", "distributor1")

        mock_get_distributor.assert_called_once_with("repo1", "distributor1")
Exemple #22
0
    def test_calls_delete_resource(self, mock_delete_by):
        resource = RepoDistributor.build_resource_tag(self.repo, self.distributor)

        RepoPublishScheduleManager.delete_by_distributor_id(self.repo, self.distributor)

        mock_delete_by.assert_called_once_with(resource)
Exemple #23
0
    def test_delete(self, mock_get_distributor, mock_delete):
        mock_get_distributor.return_value = None

        RepoPublishScheduleManager.delete(self.repo, self.distributor, self.schedule_id)

        mock_delete.assert_called_once_with(self.schedule_id)
Exemple #24
0
    def test_list(self, mock_get_by_resource, mock_validate_distributor):
        ret = RepoPublishScheduleManager.list("repo1", "distributor1")

        mock_get_by_resource.assert_called_once_with(RepoDistributor.build_resource_tag("repo1", "distributor1"))
        self.assertTrue(ret is mock_get_by_resource.return_value)
Exemple #25
0
    def test_validate_options(self, mock_get_distributor, mock_validate_options, mock_update):
        mock_get_distributor.return_value = {"id": self.distributor}

        RepoPublishScheduleManager.update(self.repo, self.distributor, self.schedule_id, self.updates)

        mock_validate_options.assert_called_once_with(self.updates)
Exemple #26
0
    def test_utils_validation(self, mock_validate_keys, mock_validate_options, mock_validate_distributor, mock_save):
        RepoPublishScheduleManager.create(self.repo, self.distributor, self.options, self.schedule)

        mock_validate_keys.assert_called_once_with(self.options, ("override_config",))
        mock_validate_options.assert_called_once_with(self.schedule, None, True)