def test_get_additional_data(self, mock_copy): TestConnector.test_get_additional_data(self) p = self.get_obj() metadata = Mock() p.entries = {"foo.xml": Mock(), "foo.yml": Mock()} rv = p.get_additional_data(metadata) expected = dict() for name, entry in p.entries.items(): entry.get_additional_data.assert_called_with(metadata) expected[name] = entry.get_additional_data.return_value self.assertItemsEqual(rv, expected)
def test_get_additional_data(self): TestConnector.test_get_additional_data(self) th = self.get_obj() modules = ['foo', 'bar'] rv = dict() for mname in modules: module = Mock() module._module_name = mname rv[mname] = module th.entries['%s.py' % mname] = module actual = th.get_additional_data(Mock()) self.assertItemsEqual(actual, rv)
def test_get_additional_data(self, mock_copy): TestConnector.test_get_additional_data(self) p = self.get_obj() metadata = Mock() p.store.entries = {"foo.xml": Mock(), "foo.yml": Mock()} rv = p.get_additional_data(metadata) expected = dict() for name, entry in p.store.entries.items(): entry.get_additional_data.assert_called_with(metadata) expected[name] = entry.get_additional_data.return_value self.assertItemsEqual(rv, expected)
def test_get_additional_groups(self): TestConnector.test_get_additional_groups(self) probes = self.get_probes_object() test_cgroups = self.get_test_cgroups() probes.cgroups = self.get_test_cgroups() for cname in test_cgroups.keys(): metadata = Mock() metadata.hostname = cname self.assertEqual(test_cgroups[cname], probes.get_additional_groups(metadata)) # test a non-existent client metadata = Mock() metadata.hostname = "nonexistent" self.assertEqual(probes.get_additional_groups(metadata), list())
def test_get_additional_data(self, mock_copy): TestConnector.test_get_additional_data(self) p = self.get_obj() automatch = Mock() automatch.xdata = lxml.etree.Element("Properties", automatch="true") automatch.XMLMatch.return_value = "automatch" raw = Mock() raw.xdata = lxml.etree.Element("Properties") raw.XMLMatch.return_value = "raw" nevermatch = Mock() nevermatch.xdata = lxml.etree.Element("Properties", automatch="false") nevermatch.XMLMatch.return_value = "nevermatch" p.store.entries = { "/foo/automatch.xml": automatch, "/foo/raw.xml": raw, "/foo/nevermatch.xml": nevermatch, } # we make copy just return the object it was asked to copy so # that we can test the return value of get_additional_data(), # which copies every object it doesn't XMLMatch() mock_copy.side_effect = lambda o: o # test with automatch default to false p.core.setup.cfp.getboolean.return_value = False metadata = Mock() self.assertItemsEqual( p.get_additional_data(metadata), { "/foo/automatch.xml": automatch.XMLMatch.return_value, "/foo/raw.xml": raw, "/foo/nevermatch.xml": nevermatch }) automatch.XMLMatch.assert_called_with(metadata) self.assertFalse(raw.XMLMatch.called) self.assertFalse(nevermatch.XMLMatch.called) # test with automatch default to true p.core.setup.cfp.getboolean.return_value = True self.assertItemsEqual( p.get_additional_data(metadata), { "/foo/automatch.xml": automatch.XMLMatch.return_value, "/foo/raw.xml": raw.XMLMatch.return_value, "/foo/nevermatch.xml": nevermatch }) automatch.XMLMatch.assert_called_with(metadata) raw.XMLMatch.assert_called_with(metadata) self.assertFalse(nevermatch.XMLMatch.called)
def test_get_additional_data(self, mock_copy): TestConnector.test_get_additional_data(self) p = self.get_obj() automatch = Mock() automatch.xdata = lxml.etree.Element("Properties", automatch="true") automatch.XMLMatch.return_value = "automatch" raw = Mock() raw.xdata = lxml.etree.Element("Properties") raw.XMLMatch.return_value = "raw" nevermatch = Mock() nevermatch.xdata = lxml.etree.Element("Properties", automatch="false") nevermatch.XMLMatch.return_value = "nevermatch" p.store.entries = {"/foo/automatch.xml": automatch, "/foo/raw.xml": raw, "/foo/nevermatch.xml": nevermatch} # we make copy just return the object it was asked to copy so # that we can test the return value of get_additional_data(), # which copies every object it doesn't XMLMatch() mock_copy.side_effect = lambda o: o # test with automatch default to false p.core.setup.cfp.getboolean.return_value = False metadata = Mock() self.assertItemsEqual( p.get_additional_data(metadata), { "/foo/automatch.xml": automatch.XMLMatch.return_value, "/foo/raw.xml": raw, "/foo/nevermatch.xml": nevermatch, }, ) automatch.XMLMatch.assert_called_with(metadata) self.assertFalse(raw.XMLMatch.called) self.assertFalse(nevermatch.XMLMatch.called) # test with automatch default to true p.core.setup.cfp.getboolean.return_value = True self.assertItemsEqual( p.get_additional_data(metadata), { "/foo/automatch.xml": automatch.XMLMatch.return_value, "/foo/raw.xml": raw.XMLMatch.return_value, "/foo/nevermatch.xml": nevermatch, }, ) automatch.XMLMatch.assert_called_with(metadata) raw.XMLMatch.assert_called_with(metadata) self.assertFalse(nevermatch.XMLMatch.called)
def test_get_additional_data(self): TestConnector.test_get_additional_data(self) probes = self.get_probes_object() test_probedata = self.get_test_probedata() probes.probedata = self.get_test_probedata() for cname in test_probedata.keys(): metadata = Mock() metadata.hostname = cname self.assertEqual(test_probedata[cname], probes.get_additional_data(metadata)) # test a non-existent client metadata = Mock() metadata.hostname = "nonexistent" self.assertEqual(probes.get_additional_data(metadata), ClientProbeDataSet())