From d4a3ed9dd4313a8dd13e615b6d03622fcc4d2bbc Mon Sep 17 00:00:00 2001 From: Stanislav Levin Date: Fri, 13 Aug 2021 14:45:07 +0300 Subject: [PATCH] test_schema_plugin: Drop dependency on Tracker Tracker is the best for testing plugins dealing with LDAP. The tests in test_schema_plugin are not used LDAP at all. Fixes: https://pagure.io/freeipa/issue/8954 Signed-off-by: Stanislav Levin Reviewed-By: Florence Blanc-Renaud --- ipatests/test_xmlrpc/test_schema_plugin.py | 71 ++++++++++++++-------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/ipatests/test_xmlrpc/test_schema_plugin.py b/ipatests/test_xmlrpc/test_schema_plugin.py index 8a55892d8..4bfb2ad89 100644 --- a/ipatests/test_xmlrpc/test_schema_plugin.py +++ b/ipatests/test_xmlrpc/test_schema_plugin.py @@ -9,21 +9,22 @@ Test the `ipaserver/plugins/schema.py` module. import pytest from ipalib import api, errors -from ipatests.test_xmlrpc.tracker.base import Tracker from ipatests.test_xmlrpc.xmlrpc_test import XMLRPC_test @pytest.mark.tier1 class TestParamFindAndShowCommand(XMLRPC_test): """Test functionality of the ipa param-{find,show} command""" - - tracker = Tracker() + def run_command(self, command, *args, **options): + cmd = api.Command[command] + cmd_result = cmd(*args, **options) + return cmd_result def test_param_find(self): """Test param-find command""" - + cmd = "param_find" # right command without criteria - result = self.tracker.run_command('param_find', u'user-add') + result = self.run_command(cmd, "user-add") assert len(result['result']) != 0, result assert result['result'][0]['name'] == 'uid', result assert result['result'][0]['cli_name'] == 'login', result @@ -31,26 +32,30 @@ class TestParamFindAndShowCommand(XMLRPC_test): # right command, right criteria criteria = u'postalcode' - result = self.tracker.run_command('param_find', u'user-add', criteria) + result = self.run_command(cmd, "user-add", criteria) assert len(result['result']) != 0, result for item in result['result']: assert (criteria in item['name'].lower() or criteria in item['doc'].lower()), item # right command, wrong criteria - result = self.tracker.run_command('param_find', u'user-add', u'fake') + result = self.run_command(cmd, "user-add", "fake") assert len(result['result']) == 0, result # wrong command, wrong criteria - result = self.tracker.run_command('param_find', u'fake', u'fake') + result = self.run_command(cmd, "fake", "fake") assert len(result['result']) == 0, result + # too many args + with pytest.raises(errors.MaxArgumentError): + self.run_command(cmd, "arg1", "arg2", "arg3") + def test_param_show(self): """Test param-show command""" - # right command, right criteria - criteria = u'uid' - result = self.tracker.run_command('param_show', u'user-add', criteria) + criteria = "uid" + cmd = "param_show" + result = self.run_command(cmd, "user-add", criteria) assert result['result'] is not None, result assert result['result']['name'] == 'uid', result assert result['result']['cli_name'] == 'login', result @@ -58,26 +63,33 @@ class TestParamFindAndShowCommand(XMLRPC_test): # right command without criteria with pytest.raises(errors.RequirementError): - self.tracker.run_command('param_show', u'user-add') + self.run_command(cmd, "user-add") # right command, wrong criteria with pytest.raises(errors.NotFound): - self.tracker.run_command('param_show', u'user-add', u'fake') + self.run_command(cmd, "user-add", "fake") # wrong command, wrong criteria with pytest.raises(errors.NotFound): - self.tracker.run_command('param_show', u'fake', u'fake') + self.run_command(cmd, "fake", "fake") + + # too many args + with pytest.raises(errors.MaxArgumentError): + self.run_command(cmd, "arg1", "arg2", "arg3") class TestOutputFindAndShowCommand(XMLRPC_test): """Test functionality of the ipa output-{find,show} command""" - tracker = Tracker() + def run_command(self, command, *args, **options): + cmd = api.Command[command] + cmd_result = cmd(*args, **options) + return cmd_result def test_output_find(self): """Test output-find command""" - + cmd = "output_find" # right command without criteria - result = self.tracker.run_command('output_find', u'user-add') + result = self.run_command(cmd, "user-add") assert len(result['result']) != 0, result assert result['result'][0]['name'] == 'summary', result assert result['result'][0]['doc'] == \ @@ -85,24 +97,29 @@ class TestOutputFindAndShowCommand(XMLRPC_test): # right command, right criteria criteria = u'result' - result = self.tracker.run_command('output_find', u'user-add', criteria) + result = self.run_command(cmd, "user-add", criteria) assert len(result['result']) == 1, result assert criteria in result['result'][0]['name'].lower(), result # right command, wrong criteria - result = self.tracker.run_command('output_find', u'user-add', u'fake') + result = self.run_command(cmd, "user-add", "fake") assert len(result['result']) == 0, result # wrong command, wrong criteria - result = self.tracker.run_command('output_find', u'fake', u'fake') + result = self.run_command(cmd, "fake", "fake") assert len(result['result']) == 0, result + # too many args + with pytest.raises(errors.MaxArgumentError): + self.run_command(cmd, "arg1", "arg2", "arg3") + def test_output_show(self): """Test output-show command""" # right command, right criteria - criteria = u'value' - result = self.tracker.run_command('output_show', u'user-add', criteria) + criteria = "value" + cmd = "output_show" + result = self.run_command(cmd, "user-add", criteria) assert len(result['result']) != 0, result assert criteria in result['result']['name'].lower(), result assert result['result']['doc'] == \ @@ -110,15 +127,19 @@ class TestOutputFindAndShowCommand(XMLRPC_test): # right command without criteria with pytest.raises(errors.RequirementError): - self.tracker.run_command('output_show', u'user-add') + self.run_command(cmd, "user-add") # right command, wrong criteria with pytest.raises(errors.NotFound): - self.tracker.run_command('output_show', u'user-add', u'fake') + self.run_command(cmd, "user-add", "fake") # wrong command, wrong criteria with pytest.raises(errors.NotFound): - self.tracker.run_command('output_show', u'fake', u'fake') + self.run_command(cmd, "fake", "fake") + + # too many args + with pytest.raises(errors.MaxArgumentError): + self.run_command(cmd, "arg1", "arg2", "arg3") class TestSchemaCommand(XMLRPC_test):