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()
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()
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)
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)
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))
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)
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))
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))
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))
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))
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)
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
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