mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-05-07 13:53:23 +00:00
pytest tests: Enhanced assertion for check_* methods.
Checking if some output is present or absent from standard streams was done by simple string searching. Due to recent changes in FreeIPA, this search is not effective due to capitalization differences in boolean values output. Changing the string searching to regular expression searches fixes this behavior for current and previous versions of FreeIPA. This patch also adds more information on the assert tests in case of an error, so that it is easier to understand why the test failed.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
import os
|
||||
import pytest
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import testinfra
|
||||
@@ -314,6 +315,10 @@ class AnsibleFreeIPATestCase(TestCase):
|
||||
expected_msg in result.stderr.decode("utf8")
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def __is_text_on_data(text, data):
|
||||
return re.search(text, data) is not None
|
||||
|
||||
def check_details(self, expected_output, cmd, extra_cmds=None):
|
||||
cmd = "ipa " + cmd
|
||||
if extra_cmds:
|
||||
@@ -322,10 +327,16 @@ class AnsibleFreeIPATestCase(TestCase):
|
||||
res = self.master.run(cmd)
|
||||
if res.rc != 0:
|
||||
for output in expected_output:
|
||||
assert output in res.stderr
|
||||
assert self.__is_text_on_data(output, res.stderr), (
|
||||
f"\n{'='*40}\nExpected: {output}\n{'='*40}\n"
|
||||
+ f"Output:\n{res.stderr}{'='*40}\n"
|
||||
)
|
||||
else:
|
||||
for output in expected_output:
|
||||
assert output in res.stdout
|
||||
assert self.__is_text_on_data(output, res.stdout), (
|
||||
f"\n{'='*40}\nExpected: {output}\n{'='*40}\n"
|
||||
+ f"Output:\n{res.stdout}{'='*40}\n"
|
||||
)
|
||||
kdestroy(self.master)
|
||||
|
||||
def check_notexists(self, members, cmd, extra_cmds=None):
|
||||
@@ -335,7 +346,10 @@ class AnsibleFreeIPATestCase(TestCase):
|
||||
kinit_admin(self.master)
|
||||
res = self.master.run(cmd)
|
||||
for member in members:
|
||||
assert member not in res.stdout
|
||||
assert not self.__is_text_on_data(member, res.stdout), (
|
||||
f"\n{'='*40}\nExpected: {member}\n{'='*40}\n"
|
||||
+ f"Output:\n{res.stdout}{'='*40}\n"
|
||||
)
|
||||
kdestroy(self.master)
|
||||
|
||||
def mark_xfail_using_ansible_freeipa_version(self, version, reason):
|
||||
|
||||
Reference in New Issue
Block a user