Exemple #1
0
    def test_HandlesEntry(self):
        modules = self.get_obj()
        modules._get_module_filename = Mock()
        modules.Entries['SEModule']['/foo.pp'] = Mock()
        modules.Entries['SEModule']['/bar.pp'] = Mock()
        for el in [
                lxml.etree.Element("Path", name="foo.pp"),
                lxml.etree.Element("SEModule", name="baz.pp")
        ]:
            modules._get_module_filename.return_value = "/" + el.get("name")
            self.assertFalse(modules.HandlesEntry(el, Mock()))
            if el.tag == "SEModule":
                modules._get_module_filename.assert_called_with(el)

        for el in [
                lxml.etree.Element("SEModule", name="foo.pp"),
                lxml.etree.Element("SEModule", name="bar.pp")
        ]:
            modules._get_module_filename.return_value = "/" + el.get("name")
            self.assertTrue(modules.HandlesEntry(el, Mock()),
                            msg="SEModules fails to handle %s" %
                            el.get("name"))
            modules._get_module_filename.assert_called_with(el)

        TestGroupSpool.test_HandlesEntry(self)
Exemple #2
0
    def test_HandlesEntry(self, mock_get_name):
        modules = self.get_obj()
        handler = Mock()
        modules.Entries['SELinux']['/foo.pp'] = handler
        mock_get_name.return_value = "/foo.pp"
        
        entry = lxml.etree.Element("SELinux", type="module", name="foo")
        metadata = Mock()
        self.assertEqual(modules.HandleEntry(entry, metadata),
                         handler.return_value)
        mock_get_name.assert_called_with(entry)
        self.assertEqual(entry.get("name"), mock_get_name.return_value)
        handler.assert_called_with(entry, metadata)

        TestGroupSpool.test_HandlesEntry(self)
Exemple #3
0
    def test_HandleEntry(self):
        modules = self.get_obj()
        modules._get_module_name = Mock()
        handler = Mock()
        modules.Entries['SEModule']['/foo.pp'] = handler
        modules._get_module_name.return_value = "foo"

        entry = lxml.etree.Element("SEModule", type="module", name="foo")
        metadata = Mock()
        self.assertEqual(modules.HandleEntry(entry, metadata),
                         handler.return_value)
        modules._get_module_name.assert_called_with(entry)
        self.assertEqual(entry.get("name"),
                         modules._get_module_name.return_value)
        handler.assert_called_with(entry, metadata)

        TestGroupSpool.test_HandlesEntry(self)
Exemple #4
0
    def test_HandlesEntry(self):
        modules = self.get_obj()
        modules._get_module_filename = Mock()
        modules.Entries['SEModule']['/foo.pp'] = Mock()
        modules.Entries['SEModule']['/bar.pp'] = Mock()
        for el in [lxml.etree.Element("Path", name="foo.pp"),
                   lxml.etree.Element("SEModule", name="baz.pp")]:
            modules._get_module_filename.return_value = "/" + el.get("name")
            self.assertFalse(modules.HandlesEntry(el, Mock()))
            if el.tag == "SEModule":
                modules._get_module_filename.assert_called_with(el)

        for el in [lxml.etree.Element("SEModule", name="foo.pp"),
                   lxml.etree.Element("SEModule", name="bar.pp")]:
            modules._get_module_filename.return_value = "/" + el.get("name")
            self.assertTrue(modules.HandlesEntry(el, Mock()),
                            msg="SEModules fails to handle %s" % el.get("name"))
            modules._get_module_filename.assert_called_with(el)

        TestGroupSpool.test_HandlesEntry(self)
Exemple #5
0
    def test_add_entry(self):
        @patch("%s.%s.add_entry" % (self.test_obj.__base__.__module__,
                                    self.test_obj.__base__.__name__))
        def inner(mock_add_entry):
            modules = self.get_obj()
            modules.event_path = Mock()

            evt = Mock()
            evt.filename = "test.pp.G10_foo"

            modules.event_path.return_value = \
                os.path.join(datastore,
                             self.test_obj.__name__,
                             "test.pp",
                             "test.pp.G10_foo")
            modules.add_entry(evt)
            self.assertEqual(modules.filename_pattern, "test.pp")
            mock_add_entry.assert_called_with(modules, evt)
            modules.event_path.assert_called_with(evt)

        inner()
        TestGroupSpool.test_add_entry(self)
Exemple #6
0
    def test_add_entry(self):
        @patch("%s.%s.add_entry" % (self.test_obj.__base__.__module__,
                                    self.test_obj.__base__.__name__))
        def inner(mock_add_entry):
            modules = self.get_obj()
            modules.event_path = Mock()

            evt = Mock()
            evt.filename = "test.pp.G10_foo"

            modules.event_path.return_value = \
                os.path.join(datastore,
                             self.test_obj.__name__,
                             "test.pp",
                             "test.pp.G10_foo")
            modules.add_entry(evt)
            self.assertEqual(modules.filename_pattern, "test.pp")
            mock_add_entry.assert_called_with(modules, evt)
            modules.event_path.assert_called_with(evt)

        inner()
        TestGroupSpool.test_add_entry(self)
Exemple #7
0
    def test_HandlesEntry(self, mock_get_name):
        modules = self.get_obj()
        modules.Entries['SELinux']['/foo.pp'] = Mock()
        modules.Entries['SELinux']['/bar.pp'] = Mock()
        for el in [lxml.etree.Element("Path", name="/foo.pp"),
                   lxml.etree.Element("SELinux", type="fcontext",
                                      name="/foo.pp"),
                   lxml.etree.Element("SELinux", type="module",
                                      name="/baz.pp")]:
            mock_get_name.return_value = el.get("name")
            self.assertFalse(modules.HandlesEntry(el, Mock()))
            mock_get_name.assert_called_with(el)

        for el in [lxml.etree.Element("SELinux", type="module",
                                      name="/foo.pp"),
                   lxml.etree.Element("SELinux", type="module",
                                      name="/bar.pp")]:
            mock_get_name.return_value = el.get("name")
            self.assertTrue(modules.HandlesEntry(el, Mock()),
                            msg="SEModules fails to handle %s" % el.get("name"))
            mock_get_name.assert_called_with(el)

        TestGroupSpool.test_HandlesEntry(self)
Exemple #8
0
 def get_obj(self, core=None):
     if core is None:
         core = Mock()
     return TestGroupSpool.get_obj(self, core=core)
Exemple #9
0
 def get_obj(self, core=None):
     if core is None:
         core = Mock()
     return TestGroupSpool.get_obj(self, core=core)
Exemple #10
0
 def setUp(self):
     TestGroupSpool.setUp(self)
     TestPullTarget.setUp(self)
     set_setup_default("cfg_handlers", [])
Exemple #11
0
 def setUp(self):
     TestGroupSpool.setUp(self)
     TestPullTarget.setUp(self)
     set_setup_default("cfg_handlers", [])