Exemple #1
0
    def setUp(self):
        # Params of the deactivate method for uds
        self.query = Query(source="etab1",
                           remote_ip="127.0.0.1",
                           signature="c08b3ff9dff7c5f08a1abdfabfbd24279e82dd10",
                           arguments={"login": "******", },
                           ressource="actions",
                           method="action1",
                           request_method="GET"
                           )

        self.query2 = Query(source="etab1",
                            remote_ip="127.0.0.1",
                            signature="c08b3ff9dff7c5f08a1abdfabfbd24279e82dd10",
                            arguments={"login": "******", },
                            ressource="actions",
                            method="action2",
                            request_method="GET"
                            )

        # Files
        self.plugin_runner = PluginsRunner(
            "./tests/data/acl.yml",
            "./tests/data/sources.yml",
            "./tests/data/ressources.yml",
            "tests.plugins")

        self.data_ok = {'Plugin1': 'p1ok1', 'Plugin2': 'p2ok1'}
        self.errors_raw = {'Plugin1': {
                            'error_message': 'error plugin 1 action 2 !',
                            'method': 'action2',
                            'source': 'etab1',
                            'arguments': {'login': '******'},
                            'error': 'Exception',
                            'ressource': 'actions',
                            'parameters_index': 0,
                            'project': None},
                           'Plugin2': {
                            'error_message': 'error plugin 2 action 2 !',
                            'method': 'action2',
                            'source': 'etab1',
                            'arguments': {'login': '******'},
                            'error': 'Exception', 'ressource':
                            'actions',
                            'parameters_index': 0,
                            'project': None},
                           }
Exemple #2
0
    def make_and_run_query(self, plugin_runner, etab=None):
        """
        make and run the query depending on etab
        """
        # create the query
        query = Query(
            source=etab if etab else self.source,
            remote_ip=self.remote_ip,
            arguments=self.arguments,
            ressource=self.ressource,
            method=self.method,
            request_method=self.request_method,
            project=self.project,
            signature=self.signature
        )

        newdata, errors = plugin_runner(query)

        return newdata, errors
Exemple #3
0
class PluginsTest(TestCase):

    def setUp(self):
        # Params of the deactivate method for uds
        self.query = Query(source="etab1",
                           remote_ip="127.0.0.1",
                           signature="c08b3ff9dff7c5f08a1abdfabfbd24279e82dd10",
                           arguments={"login": "******", },
                           ressource="actions",
                           method="action1",
                           request_method="GET"
                           )

        self.query2 = Query(source="etab1",
                            remote_ip="127.0.0.1",
                            signature="c08b3ff9dff7c5f08a1abdfabfbd24279e82dd10",
                            arguments={"login": "******", },
                            ressource="actions",
                            method="action2",
                            request_method="GET"
                            )

        # Files
        self.plugin_runner = PluginsRunner(
            "./tests/data/acl.yml",
            "./tests/data/sources.yml",
            "./tests/data/ressources.yml",
            "tests.plugins")

        self.data_ok = {'Plugin1': 'p1ok1', 'Plugin2': 'p2ok1'}
        self.errors_raw = {'Plugin1':
                           {'error_message': 'error plugin 1 action 2 !',
                            'method': 'action2',
                            'source': 'etab1',
                            'arguments': {'login': '******'},
                            'error': 'Exception',
                            'ressource': 'actions',
                            'parameters_index': 0},
                           'Plugin2':
                          {'error_message': 'error plugin 2 action 2 !',
                           'method': 'action2',
                           'source': 'etab1',
                           'arguments': {'login': '******'},
                           'error': 'Exception', 'ressource':
                           'actions',
                           'parameters_index': 0}
                           }

    def test_run(self):
        data, errors = self.plugin_runner.run(self.query)

        self.assertEqual(data, self.data_ok)
        self.assertEqual(errors, {})

    def test_run_error(self):
        plugin_runner = PluginsRunner(
            "./tests/data/acl.yml",
            "./tests/data/sources.yml",
            "./tests/data/ressources.yml",
            "tests.plugins")
        data, errors = plugin_runner.run(self.query2)

        self.assertEqual(errors, self.errors_raw)
        self.assertEqual(data, {})

    def test_keyerror_plugins(self):
        plugin_runner = PluginsRunner(
            "./tests/data/acl.yml",
            "./tests/data/sourcesnoplugins.yml",
            "./tests/data/ressources.yml",
            "tests.plugins")
        with self.assertRaises(PluginRunnerError):
            plugin_runner.plugins(self.query.source, self.query.project)

    def test_plugins_module(self):
        self.assertEqual(self.plugin_runner.plugins_module, "tests.plugins")

    def test_query(self):
        self.assertEqual(self.query.__str__(),
                         "project:None,source:etab1,remote_ip:127.0.0.1,\
signature:c08b3ff9dff7c5f08a1abdfabfbd24279e82dd10,arguments:{'login': '******'},\
ressource:actions,method:action1,request_method:GET")