From 77e7ac3592c0a708aa496275fa21e18bd6d01c1d Mon Sep 17 00:00:00 2001 From: Stanislav Levin Date: Aug 19 2021 06:44:26 +0000 Subject: ipatests: Add tests for `schema` Command - the base testing of this command is made by ipaclient `schema` remote plugin, but some specifics are not covered - allow testing of the plugin in `development` mode(locked API). Fixes: https://pagure.io/freeipa/issue/8955 Signed-off-by: Stanislav Levin Reviewed-By: Florence Blanc-Renaud Reviewed-By: Rob Crittenden --- diff --git a/ipaserver/plugins/schema.py b/ipaserver/plugins/schema.py index 64f0985..915defc 100644 --- a/ipaserver/plugins/schema.py +++ b/ipaserver/plugins/schema.py @@ -839,7 +839,7 @@ class schema(Command): langs = "".join(getattr(context, "languages", [])) if getattr(self.api, "_schema", None) is None: - setattr(self.api, "_schema", {}) + object.__setattr__(self.api, "_schema", {}) schema = self.api._schema.get(langs) if schema is None: diff --git a/ipatests/test_xmlrpc/test_schema_plugin.py b/ipatests/test_xmlrpc/test_schema_plugin.py index c35297e..8a55892 100644 --- a/ipatests/test_xmlrpc/test_schema_plugin.py +++ b/ipatests/test_xmlrpc/test_schema_plugin.py @@ -8,7 +8,7 @@ Test the `ipaserver/plugins/schema.py` module. import pytest -from ipalib import errors +from ipalib import api, errors from ipatests.test_xmlrpc.tracker.base import Tracker from ipatests.test_xmlrpc.xmlrpc_test import XMLRPC_test @@ -119,3 +119,43 @@ class TestOutputFindAndShowCommand(XMLRPC_test): # wrong command, wrong criteria with pytest.raises(errors.NotFound): self.tracker.run_command('output_show', u'fake', u'fake') + + +class TestSchemaCommand(XMLRPC_test): + """Test functionality of the ipa schema Command(no cli)""" + expected_keys = { + "classes", "commands", "fingerprint", "topics", "ttl", "version" + } + + def run_command(self, command, *args, **options): + cmd = api.Command[command] + cmd_result = cmd(*args, **options) + return cmd_result + + def test_schema_no_args(self): + """Test schema command without any args""" + cmd_result = self.run_command("schema") + result = cmd_result["result"] + assert result.keys() == self.expected_keys + + def test_schema_known_valid_fp(self): + """Test schema command with valid fingerprint""" + # first, fetch current FP to reuse it + cmd_result = self.run_command("schema") + result = cmd_result["result"] + fp_valid = result["fingerprint"] + + with pytest.raises(errors.SchemaUpToDate): + self.run_command("schema", known_fingerprints=(fp_valid,)) + + def test_schema_known_wrong_fp(self): + """Test schema command with wrong fingerprint""" + fp_wrong = "wrong FP" + cmd_result = self.run_command("schema", known_fingerprints=(fp_wrong,)) + result = cmd_result["result"] + assert result.keys() == self.expected_keys + + def test_schema_too_many_args(self): + """Test schema with too many args""" + with pytest.raises(errors.ZeroArgumentError): + self.run_command("schema", "arg1")