Ejemplo n.º 1
0
    def test_gets_correct_collection(self, mock_get_collection):
        """
        make sure this operation uses the correct collection
        """
        utils.get_by_resource('resource1')

        mock_get_collection.assert_called_once_with()
Ejemplo n.º 2
0
    def test_gets_correct_collection(self, mock_get_collection):
        """
        make sure this operation uses the correct collection
        """
        utils.get_by_resource('resource1')

        mock_get_collection.assert_called_once_with()
Ejemplo n.º 3
0
    def test_empty_result(self, mock_query):
        mock_query.return_value = []

        ret = list(utils.get_by_resource('resource1'))

        self.assertEqual(mock_query.call_count, 1)

        self.assertEqual(len(ret), 0)
Ejemplo n.º 4
0
    def test_empty_result(self, mock_query):
        mock_query.return_value = []

        ret = list(utils.get_by_resource('resource1'))

        self.assertEqual(mock_query.call_count, 1)

        self.assertEqual(len(ret), 0)
Ejemplo n.º 5
0
Archivo: repo.py Proyecto: pcreech/pulp
    def list(cls, repo_id, importer_id):
        """
        Returns an iterator of ScheduledCall instances that represent schedules
        for the specified repo and importer.

        :param repo_id:     unique ID for a repository
        :type  repo_id:     basestring
        :param importer_id: unique ID for an importer
        :type  importer_id: basestring

        :return:    iterator of ScheduledCall instances
        :rtype:     iterator
        """
        importer_controller.get_valid_importer(repo_id, importer_id)
        return utils.get_by_resource(importer_controller.build_resource_tag(repo_id, importer_id))
Ejemplo n.º 6
0
Archivo: repo.py Proyecto: pcreech/pulp
    def list(cls, repo_id, distributor_id):
        """
        Returns an iterator of ScheduledCall instances that represent schedules
        for the specified repo and distributor.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param distributor_id:  unique ID for a distributor
        :type  distributor_id:  basestring

        :return:    iterator of ScheduledCall instances
        :rtype:     iterator
        """
        dist = model.Distributor.objects.get_or_404(repo_id=repo_id, distributor_id=distributor_id)
        return utils.get_by_resource(dist.resource_tag)
Ejemplo n.º 7
0
    def list(cls, repo_id, importer_id):
        """
        Returns an iterator of ScheduledCall instances that represent schedules
        for the specified repo and importer.

        :param repo_id:     unique ID for a repository
        :type  repo_id:     basestring
        :param importer_id: unique ID for an importer
        :type  importer_id: basestring

        :return:    iterator of ScheduledCall instances
        :rtype:     iterator
        """
        cls.validate_importer(repo_id, importer_id)

        return utils.get_by_resource(RepoImporter.build_resource_tag(repo_id, importer_id))
Ejemplo n.º 8
0
    def list(cls, repo_id, distributor_id):
        """
        Returns an iterator of ScheduledCall instances that represent schedules
        for the specified repo and distributor.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param distributor_id:  unique ID for an distributor
        :type  distributor_id:  basestring

        :return:    iterator of ScheduledCall instances
        :rtype:     iterator
        """
        cls.validate_distributor(repo_id, distributor_id)

        return utils.get_by_resource(RepoDistributor.build_resource_tag(repo_id, distributor_id))
Ejemplo n.º 9
0
    def test_query(self, mock_query):
        mock_query.return_value = SCHEDULES

        ret = list(utils.get_by_resource('resource1'))

        self.assertEqual(mock_query.call_count, 1)
        # there should only be 1 argument, a criteria
        self.assertEqual(len(mock_query.call_args[0]), 1)
        criteria = mock_query.call_args[0][0]
        self.assertTrue(isinstance(criteria, Criteria))
        self.assertEqual(criteria.filters, {'resource': 'resource1'})

        # three instances of ScheduledCall should be returned
        self.assertEqual(len(ret), 3)
        for schedule in ret:
            self.assertTrue(isinstance(schedule, ScheduledCall))
Ejemplo n.º 10
0
    def test_query(self, mock_query):
        mock_query.return_value = SCHEDULES

        ret = list(utils.get_by_resource('resource1'))

        self.assertEqual(mock_query.call_count, 1)
        # there should only be 1 argument, a criteria
        self.assertEqual(len(mock_query.call_args[0]), 1)
        criteria = mock_query.call_args[0][0]
        self.assertTrue(isinstance(criteria, Criteria))
        self.assertEqual(criteria.filters, {'resource': 'resource1'})

        # three instances of ScheduledCall should be returned
        self.assertEqual(len(ret), 3)
        for schedule in ret:
            self.assertTrue(isinstance(schedule, ScheduledCall))
Ejemplo n.º 11
0
    def list(cls, repo_id, distributor_id):
        """
        Returns an iterator of ScheduledCall instances that represent schedules
        for the specified repo and distributor.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param distributor_id:  unique ID for a distributor
        :type  distributor_id:  basestring

        :return:    iterator of ScheduledCall instances
        :rtype:     iterator
        """
        dist = model.Distributor.objects.get_or_404(
            repo_id=repo_id, distributor_id=distributor_id)
        return utils.get_by_resource(dist.resource_tag)
Ejemplo n.º 12
0
    def get(consumer_id, action=None):
        """
        Get a collection of schedules for the given consumer and action. If no
        action is specified, then all actions will be included.

        :param consumer_id: a unique ID for a consumer
        :type  consumer_id: basestring
        :param action:      a unique identifier for an action, one of
                            UNIT_INSTALL_ACTION, UNIT_UPDATE_ACTION,
                            UNIT_UNINSTALL_ACTION
        :type  action:      basestring

        :return:    iterator of ScheduledCall instances
        :rtype:     iterator
        """
        results = utils.get_by_resource(Consumer.build_resource_tag(consumer_id))
        if action:
            task = ACTIONS_TO_TASKS[action]
            return itertools.ifilter(lambda schedule: schedule.task == task.name, results)
        else:
            return results
Ejemplo n.º 13
0
    def get(consumer_id, action=None):
        """
        Get a collection of schedules for the given consumer and action. If no
        action is specified, then all actions will be included.

        :param consumer_id: a unique ID for a consumer
        :type  consumer_id: basestring
        :param action:      a unique identifier for an action, one of
                            UNIT_INSTALL_ACTION, UNIT_UPDATE_ACTION,
                            UNIT_UNINSTALL_ACTION
        :type  action:      basestring

        :return:    iterator of ScheduledCall instances
        :rtype:     iterator
        """
        results = utils.get_by_resource(
            Consumer.build_resource_tag(consumer_id))
        if action:
            task = ACTIONS_TO_TASKS[action]
            return itertools.ifilter(
                lambda schedule: schedule.task == task.name, results)
        else:
            return results