def test_load_from_config(self, mock_service): autospec_method(self.collection.get_names) autospec_method(self.collection.add) service_configs = {'a': mock.Mock(), 'b': mock.Mock()} context = mock.create_autospec(command_context.CommandContext) result = list(self.collection.load_from_config(service_configs, context)) expected = [mock.call(config, context) for config in service_configs.itervalues()] assert_mock_calls(expected, mock_service.from_config.mock_calls) expected = [mock.call(s) for s in result] assert_mock_calls(expected, self.collection.add.mock_calls)
def test_load_from_config(self, mock_service): autospec_method(self.collection.get_names) autospec_method(self.collection.add) service_configs = {'a': mock.Mock(), 'b': mock.Mock()} context = mock.create_autospec(command_context.CommandContext) result = list(self.collection.load_from_config( service_configs, context, )) expected = [mock.call(config, context) for config in six.itervalues(service_configs)] assert_mock_calls(expected, mock_service.from_config.mock_calls) expected = [mock.call(s) for s in result] assert_mock_calls(expected, self.collection.add.mock_calls)
def test_load_from_config(self): autospec_method(self.collection.jobs.filter_by_name) autospec_method(self.collection.add) factory = mock.create_autospec(job.JobSchedulerFactory) job_configs = {'a': mock.Mock(), 'b': mock.Mock()} result = self.collection.load_from_config(job_configs, factory, True) result = list(result) self.collection.jobs.filter_by_name.assert_called_with(job_configs) expected_calls = [mock.call(v) for v in job_configs.itervalues()] assert_mock_calls(expected_calls, factory.build.mock_calls) assert_length(self.collection.add.mock_calls, len(job_configs) * 2) assert_length(result, len(job_configs)) job_schedulers = [call[1][0] for call in self.collection.add.mock_calls[::2]] for job_scheduler in job_schedulers: job_scheduler.schedule.assert_called_with() job_scheduler.get_job.assert_called_with()
def test_load_from_config(self): autospec_method(self.collection.jobs.filter_by_name) autospec_method(self.collection.add) factory = mock.create_autospec(JobSchedulerFactory) job_configs = {'a': mock.Mock(), 'b': mock.Mock()} result = self.collection.load_from_config(job_configs, factory, True) result = list(result) self.collection.jobs.filter_by_name.assert_called_with(job_configs) expected_calls = [mock.call(v) for v in job_configs.values()] assert_mock_calls(expected_calls, factory.build.mock_calls) assert_length(self.collection.add.mock_calls, len(job_configs) * 2) assert_length(result, len(job_configs)) job_schedulers = [ call[1][0] for call in self.collection.add.mock_calls[::2] ] for job_scheduler in job_schedulers: job_scheduler.schedule.assert_called_with() job_scheduler.get_job.assert_called_with()
def test_filter_by_name(self): autospec_method(self.collection.remove) self.collection.update(dict.fromkeys(['c', 'd', 'e'])) self.collection.filter_by_name(['a', 'c']) expected = [mock.call(name) for name in ['d', 'e']] assert_mock_calls(expected, self.collection.remove.mock_calls)