コード例 #1
0
    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)
コード例 #2
0
ファイル: TestTemplateHelper.py プロジェクト: xschlef/bcfg2
    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)
コード例 #3
0
ファイル: TestProperties.py プロジェクト: PhilMiller/bcfg2
    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)
コード例 #4
0
ファイル: TestProperties.py プロジェクト: psteinbachs/bcfg2
    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)
コード例 #5
0
ファイル: TestProperties.py プロジェクト: psteinbachs/bcfg2
    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)
コード例 #6
0
ファイル: TestProbes.py プロジェクト: ab/bcfg2
    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())
コード例 #7
0
    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())