def setUp(self, mock_gfc, mock_ps): mock_module = self._mock_module() collectors = self._collectors(mock_module) fact_collector = \ assible_collector.AssibleFactCollector(collectors=collectors, namespace=ns) self.facts = fact_collector.collect( module=mock_module, collected_facts=self.collected_facts)
def _collect(self, _mock_module, collected_facts=None): _collectors = self._collectors(_mock_module) fact_collector = \ assible_collector.AssibleFactCollector(collectors=_collectors, namespace=ns, filter_spec=_mock_module.params['filter']) facts_dict = fact_collector.collect(module=_mock_module, collected_facts=collected_facts) return facts_dict
def setUp(self): self.patcher = patch('platform.system') mock_platform = self.patcher.start() mock_platform.return_value = 'OpenBSD' mock_module = self._mock_module() collectors = self._collectors(mock_module) fact_collector = \ assible_collector.AssibleFactCollector(collectors=collectors, namespace=ns) self.facts = fact_collector.collect(module=mock_module)
def test1(self): gather_subset = ['all'] mock_module = self._mock_module(gather_subset=gather_subset) collectors = self._collectors(mock_module) fact_collector = \ assible_collector.AssibleFactCollector(collectors=collectors, namespace=ns) res = fact_collector.collect(module=mock_module) self.assertIsInstance(res, dict) # just assert it's not almost empty # with run_command and get_file_content mock, many facts are empty, like network self.assertGreater(len(res), 20)
def test_empty_all_collector_classes(self): mock_module = self._mock_module() all_collector_classes = [] collectors = self._collectors( mock_module, all_collector_classes=all_collector_classes) fact_collector = \ assible_collector.AssibleFactCollector(collectors=collectors, namespace=ns) res = fact_collector.collect() self.assertIsInstance(res, dict) # just assert it's not almost empty self.assertLess(len(res), 3)
def test_concat_collector(self): _mock_module = mock_module(gather_subset=['all', '!facter', '!ohai']) _collectors = self._collectors(_mock_module) _collectors.append(ConCatFactCollector()) fact_collector = \ assible_collector.AssibleFactCollector(collectors=_collectors, namespace=ns, filter_spec=_mock_module.params['filter']) collected_facts = {} facts_dict = fact_collector.collect(module=_mock_module, collected_facts=collected_facts) self.assertIn('concat_fact', facts_dict) self.assertTrue('THE_NEEDED_FACT_VALUE' in facts_dict['concat_fact'])
def test(self): gather_subset = ['all'] mock_module = self._mock_module(gather_subset=gather_subset) all_collector_classes = [EnvFactCollector] collectors = self._collectors( mock_module, all_collector_classes=all_collector_classes) fact_collector = \ assible_collector.AssibleFactCollector(collectors=collectors, namespace=ns) res = fact_collector.collect(module=mock_module) self.assertIsInstance(res, dict) self.assertIn('env', res) self.assertIn('gather_subset', res) self.assertEqual(res['gather_subset'], ['all'])