def test_gets_correct_collection(self, mock_get_collection): """ make sure this operation uses the correct collection """ mock_get_collection.return_value.find_and_modify.return_value = SCHEDULES[0] utils.update(self.schedule_id, {'enabled': True}) mock_get_collection.assert_called_once_with()
def test_gets_correct_collection(self, mock_get_collection): """ make sure this operation uses the correct collection """ mock_get_collection.return_value.find_and_modify.return_value = SCHEDULES[ 0] utils.update(self.schedule_id, {'enabled': True}) mock_get_collection.assert_called_once_with()
def update(cls, repo_id, importer_id, schedule_id, updates): """ Update an existing sync schedule. :param repo_id: unique ID for a repository :type repo_id: basestring :param importer_id: unique ID for an importer :type importer_id: basestring :param schedule_id: unique ID for a schedule :type schedule_id: basestring :param updates: dictionary of updates to apply :type updates: dict :return ScheduledCall instance as it appears after the update :rtype pulp.server.db.model.dispatch.ScheduledCall """ cls.validate_importer(repo_id, importer_id) # legacy logic that can't be explained if 'override_config' in updates: updates['kwargs'] = {'overrides': updates.pop('override_config')} utils.validate_updated_schedule_options(updates) return utils.update(schedule_id, updates)
def update_schedule(consumer_id, schedule_id, units=None, options=None, schedule_data=None): """ :param consumer_id: a unique ID for a consumer :type consumer_id: basestring :param schedule_id: a unique ID for the schedule being updated :type schedule_id: basestring :param units: A list of content units to be installed, each as a dict in the form: { type_id:<str>, unit_key:<dict> } :type units: list :param options: a dictionary that will be passed to the action-appropriate task as the "options" argument :type options: dict :param schedule_data: dictionary of keys and values that should be applied as updates to the schedule. Keys must be in ScheduledCall.USER_UPDATE_FIELDS :return: instance of ScheduledCall representing the post-update state :rtype: pulp.server.db.models.dispatch.ScheduledCall """ ConsumerScheduleManager._validate_consumer(consumer_id) schedule_updates = copy.copy(schedule_data) or {} if units is not None: schedule_updates.setdefault("kwargs", {})["units"] = units if options is not None: schedule_updates.setdefault("kwargs", {})["options"] = options return utils.update(schedule_id, schedule_updates)
def update_schedule(consumer_id, schedule_id, units=None, options=None, schedule_data=None): """ :param consumer_id: a unique ID for a consumer :type consumer_id: basestring :param schedule_id: a unique ID for the schedule being updated :type schedule_id: basestring :param units: A list of content units to be installed, each as a dict in the form: { type_id:<str>, unit_key:<dict> } :type units: list :param options: a dictionary that will be passed to the action-appropriate task as the "options" argument :type options: dict :param schedule_data: dictionary of keys and values that should be applied as updates to the schedule. Keys must be in ScheduledCall.USER_UPDATE_FIELDS :return: instance of ScheduledCall representing the post-update state :rtype: pulp.server.db.models.dispatch.ScheduledCall """ ConsumerScheduleManager._validate_consumer(consumer_id) schedule_updates = copy.copy(schedule_data) or {} if units is not None: schedule_updates.setdefault('kwargs', {})['units'] = units if options is not None: schedule_updates.setdefault('kwargs', {})['options'] = options return utils.update(schedule_id, schedule_updates)
def test_update(self, mock_get): mock_find = mock_get.return_value.find_and_modify mock_find.return_value = SCHEDULES[0] ret = utils.update(self.schedule_id, {'enabled': True}) self.assertEqual(mock_find.call_count, 1) self.assertEqual(len(mock_find.call_args[0]), 0) self.assertEqual(mock_find.call_args[1]['query'], {'_id': ObjectId(self.schedule_id)}) self.assertTrue(mock_find.call_args[1]['update']['$set']['enabled'] is True) last_updated = mock_find.call_args[1]['update']['$set']['last_updated'] # make sure the last_updated value is within the last tenth of a second self.assertTrue(time.time() - last_updated < .1) # make sure it asks for the new version of the schedule to be returned self.assertTrue(mock_find.call_args[1]['new'] is True) self.assertTrue(isinstance(ret, ScheduledCall))
def test_update_iso_schedule(self, mock_get, mock_pickle): mock_find = mock_get.return_value.find_and_modify mock_find.return_value = SCHEDULES[0] mock_pickle.return_value = "NEW_SCHEDULE" new_iso_sched = '2014-08-27T00:38:00Z/PT24H' ret = utils.update(self.schedule_id, {'iso_schedule': new_iso_sched}) self.assertEqual(mock_find.call_count, 1) self.assertEqual(len(mock_find.call_args[0]), 0) self.assertEqual(mock_find.call_args[1]['query'], {'_id': ObjectId(self.schedule_id)}) self.assertTrue(mock_find.call_args[1]['update']['$set']['iso_schedule'] == new_iso_sched) self.assertTrue(mock_find.call_args[1]['update']['$set']['schedule'] == "NEW_SCHEDULE") last_updated = mock_find.call_args[1]['update']['$set']['last_updated'] # make sure the last_updated value is within the last tenth of a second self.assertTrue(time.time() - last_updated < .1) # make sure it asks for the new version of the schedule to be returned self.assertTrue(mock_find.call_args[1]['new'] is True) self.assertTrue(isinstance(ret, ScheduledCall))
def update(cls, repo_id, distributor_id, schedule_id, updates): """ Update an existing scheduled publish for the given repository 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 :param schedule_id: unique ID for a schedule :type schedule_id: basestring :param updates: dictionary of updates to apply :type updates: dict :return ScheduledCall instance as it appears after the update :rtype pulp.server.db.model.dispatch.ScheduledCall """ model.Distributor.objects.get_or_404(repo_id=repo_id, distributor_id=distributor_id) if "override_config" in updates: updates["kwargs"] = {"overrides": updates.pop("override_config")} utils.validate_updated_schedule_options(updates) return utils.update(schedule_id, updates)
def update(cls, repo_id, distributor_id, schedule_id, updates): """ Update an existing scheduled publish for the given repository 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 :param schedule_id: unique ID for a schedule :type schedule_id: basestring :param updates: dictionary of updates to apply :type updates: dict :return ScheduledCall instance as it appears after the update :rtype pulp.server.db.model.dispatch.ScheduledCall """ cls.validate_distributor(repo_id, distributor_id) if 'override_config' in updates: updates['kwargs'] = {'overrides': updates.pop('override_config')} utils.validate_updated_schedule_options(updates) return utils.update(schedule_id, updates)
def test_update_iso_schedule(self, mock_get): mock_find = mock_get.return_value.find_and_modify mock_find.return_value = SCHEDULES[0] new_iso_sched = '2014-08-27T00:38:00Z/PT24H' ret = utils.update(self.schedule_id, {'iso_schedule': new_iso_sched}) self.assertEqual(mock_find.call_count, 1) self.assertEqual(len(mock_find.call_args[0]), 0) self.assertEqual(mock_find.call_args[1]['query'], {'_id': ObjectId(self.schedule_id)}) update_values = mock_find.call_args[1]['update']['$set'] self.assertTrue(update_values['iso_schedule'] == new_iso_sched) self.assertTrue(update_values['first_run'] == '2014-08-27T00:38:00Z') self.assertTrue('next_run' in update_values) self.assertTrue('schedule' in update_values) last_updated = mock_find.call_args[1]['update']['$set']['last_updated'] # make sure the last_updated value is within the last tenth of a second self.assertTrue(time.time() - last_updated < .1) # make sure it asks for the new version of the schedule to be returned self.assertTrue(mock_find.call_args[1]['new'] is True) self.assertTrue(isinstance(ret, ScheduledCall))