mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-11-03 04:40:31 -06:00
pytest: Migrate unittest/nose to Pytest fixtures
Even though Pytest supports xunit style setups, unittest and nose tests, this support is limited and may be dropped in the future releases. Worst of all is that the mixing of various test frameworks results in weird conflicts and of course, is not widely tested. This is a part of work to remove the mixing of test idioms in the IPA's test suite: 1) replace unittest.TestCase subclasses 2) replace unittest test controls (SkipTest, fail, etc.) 3) replace unittest assertions Related: https://pagure.io/freeipa/issue/7989 Signed-off-by: Stanislav Levin <slev@altlinux.org> Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
1 parent
292d686c0b
commit
fec66942d4
25 files changed
+887
-888
No files matched your search
@@ -36,7 +36,6 @@ from ipaserver.plugins.automember import REBUILD_TASK_CONTAINER
|
||||
import time
|
||||
import pytest
|
||||
import re
|
||||
import unittest
|
||||
from pkg_resources import parse_version
|
||||
|
||||
try:
|
||||
@@ -263,7 +262,7 @@ def set_automember_process_modify_ops(value):
|
||||
:param value: can be either on or off
|
||||
"""
|
||||
if not have_ldap2:
|
||||
raise unittest.SkipTest('server plugin not available')
|
||||
pytest.skip('server plugin not available')
|
||||
ldap = ldap2(api)
|
||||
ldap.connect()
|
||||
plugin_entry = ldap.get_entry(
|
||||
@@ -287,7 +286,7 @@ def wait_automember_rebuild():
|
||||
If no task is found assume that the task is already finished.
|
||||
"""
|
||||
if not have_ldap2:
|
||||
raise unittest.SkipTest('server plugin not available')
|
||||
pytest.skip('server plugin not available')
|
||||
ldap = ldap2(api)
|
||||
ldap.connect()
|
||||
|
||||
@@ -897,7 +896,7 @@ class TestAutomemberFindOrphans(XMLRPC_test):
|
||||
# rebuild fails if 389-ds is older than 1.4.0.22 where unmembering
|
||||
# feature was implemented: https://pagure.io/389-ds-base/issue/50077
|
||||
if not have_ldap2:
|
||||
raise unittest.SkipTest('server plugin not available')
|
||||
pytest.skip('server plugin not available')
|
||||
ldap = ldap2(api)
|
||||
ldap.connect()
|
||||
rootdse = ldap.get_entry(DN(''), ['vendorVersion'])
|
||||
|
||||
@@ -23,7 +23,6 @@ from __future__ import print_function, absolute_import
|
||||
|
||||
import base64
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
import six
|
||||
@@ -57,7 +56,7 @@ def is_db_configured():
|
||||
|
||||
if (api.env.xmlrpc_uri == u'http://localhost:8888/ipa/xml' and
|
||||
not os.path.isfile(aliasdir)):
|
||||
raise unittest.SkipTest('developer CA not configured in %s' % aliasdir)
|
||||
pytest.skip('developer CA not configured in %s' % aliasdir)
|
||||
|
||||
# Test setup
|
||||
#
|
||||
@@ -86,9 +85,9 @@ class BaseCert(XMLRPC_test):
|
||||
@pytest.fixture(autouse=True, scope="class")
|
||||
def basecert_setup(self, request, xmlrpc_setup):
|
||||
if 'cert_request' not in api.Command:
|
||||
raise unittest.SkipTest('cert_request not registered')
|
||||
pytest.skip('cert_request not registered')
|
||||
if 'cert_show' not in api.Command:
|
||||
raise unittest.SkipTest('cert_show not registered')
|
||||
pytest.skip('cert_show not registered')
|
||||
|
||||
is_db_configured()
|
||||
|
||||
@@ -275,10 +274,10 @@ class test_cert_find(XMLRPC_test):
|
||||
@pytest.fixture(autouse=True, scope="class")
|
||||
def certfind_setup(self, request, xmlrpc_setup):
|
||||
if 'cert_find' not in api.Command:
|
||||
raise unittest.SkipTest('cert_find not registered')
|
||||
pytest.skip('cert_find not registered')
|
||||
|
||||
if api.env.ra_plugin != 'dogtag':
|
||||
raise unittest.SkipTest('cert_find for dogtag CA only')
|
||||
pytest.skip('cert_find for dogtag CA only')
|
||||
|
||||
is_db_configured()
|
||||
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
Test the `ipaserver/plugins/dns.py` module.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
from ipalib import api, errors
|
||||
from ipalib.util import normalize_zone
|
||||
from ipapython.dnsutil import DNSName
|
||||
@@ -432,10 +430,10 @@ class test_dns(Declarative):
|
||||
api.Backend.rpcclient.connect()
|
||||
|
||||
if not have_ldap2:
|
||||
raise unittest.SkipTest('server plugin not available')
|
||||
pytest.skip('server plugin not available')
|
||||
|
||||
if get_nameservers_error is not None:
|
||||
raise unittest.SkipTest(
|
||||
pytest.skip(
|
||||
'unable to get list of nameservers (%s)' %
|
||||
get_nameservers_error
|
||||
)
|
||||
@@ -446,7 +444,7 @@ class test_dns(Declarative):
|
||||
)
|
||||
api.Command['dnszone_del'](zone1)
|
||||
except errors.NotFound:
|
||||
raise unittest.SkipTest('DNS is not configured')
|
||||
pytest.skip('DNS is not configured')
|
||||
except errors.DuplicateEntry:
|
||||
pass
|
||||
|
||||
@@ -3342,10 +3340,10 @@ class test_root_zone(Declarative):
|
||||
api.Backend.rpcclient.connect()
|
||||
|
||||
if not have_ldap2:
|
||||
raise unittest.SkipTest('server plugin not available')
|
||||
pytest.skip('server plugin not available')
|
||||
|
||||
if get_nameservers_error is not None:
|
||||
raise unittest.SkipTest(
|
||||
pytest.skip(
|
||||
'unable to get list of nameservers (%s)' %
|
||||
get_nameservers_error
|
||||
)
|
||||
@@ -3354,7 +3352,7 @@ class test_root_zone(Declarative):
|
||||
api.Command['dnszone_add'](zone1, idnssoarname=zone1_rname,)
|
||||
api.Command['dnszone_del'](zone1)
|
||||
except errors.NotFound:
|
||||
raise unittest.SkipTest('DNS is not configured')
|
||||
pytest.skip('DNS is not configured')
|
||||
except errors.DuplicateEntry:
|
||||
pass
|
||||
|
||||
@@ -3426,13 +3424,13 @@ class test_forward_zones(Declarative):
|
||||
api.Backend.rpcclient.connect()
|
||||
|
||||
if not have_ldap2:
|
||||
raise unittest.SkipTest('server plugin not available')
|
||||
pytest.skip('server plugin not available')
|
||||
|
||||
try:
|
||||
api.Command['dnszone_add'](zone1, idnssoarname=zone1_rname,)
|
||||
api.Command['dnszone_del'](zone1)
|
||||
except errors.NotFound:
|
||||
raise unittest.SkipTest('DNS is not configured')
|
||||
pytest.skip('DNS is not configured')
|
||||
except errors.DuplicateEntry:
|
||||
pass
|
||||
|
||||
@@ -4633,13 +4631,13 @@ class test_forward_master_zones_mutual_exlusion(Declarative):
|
||||
api.Backend.rpcclient.connect()
|
||||
|
||||
if not have_ldap2:
|
||||
raise unittest.SkipTest('server plugin not available')
|
||||
pytest.skip('server plugin not available')
|
||||
|
||||
try:
|
||||
api.Command['dnszone_add'](zone1, idnssoarname=zone1_rname,)
|
||||
api.Command['dnszone_del'](zone1)
|
||||
except errors.NotFound:
|
||||
raise unittest.SkipTest('DNS is not configured')
|
||||
pytest.skip('DNS is not configured')
|
||||
except errors.DuplicateEntry:
|
||||
pass
|
||||
|
||||
@@ -5011,13 +5009,13 @@ class test_forwardzone_delegation_warnings(Declarative):
|
||||
api.Backend.rpcclient.connect()
|
||||
|
||||
if not have_ldap2:
|
||||
raise unittest.SkipTest('server plugin not available')
|
||||
pytest.skip('server plugin not available')
|
||||
|
||||
try:
|
||||
api.Command['dnszone_add'](zone1, idnssoarname=zone1_rname,)
|
||||
api.Command['dnszone_del'](zone1)
|
||||
except errors.NotFound:
|
||||
raise unittest.SkipTest('DNS is not configured')
|
||||
pytest.skip('DNS is not configured')
|
||||
except errors.DuplicateEntry:
|
||||
pass
|
||||
|
||||
@@ -5520,17 +5518,17 @@ class test_dns_soa(Declarative):
|
||||
api.Backend.rpcclient.connect()
|
||||
|
||||
if not have_ldap2:
|
||||
raise unittest.SkipTest('server plugin not available')
|
||||
pytest.skip('server plugin not available')
|
||||
|
||||
if get_nameservers_error is not None:
|
||||
raise unittest.SkipTest('unable to get list of nameservers (%s)' %
|
||||
pytest.skip('unable to get list of nameservers (%s)' %
|
||||
get_nameservers_error)
|
||||
try:
|
||||
api.Command['dnszone_add'](zone1,
|
||||
idnssoarname=zone1_rname,)
|
||||
api.Command['dnszone_del'](zone1)
|
||||
except errors.NotFound:
|
||||
raise unittest.SkipTest('DNS is not configured')
|
||||
pytest.skip('DNS is not configured')
|
||||
except errors.DuplicateEntry:
|
||||
pass
|
||||
|
||||
|
||||
@@ -21,8 +21,6 @@ Test adding/removing external members (trusted domain objects) to IPA groups.
|
||||
These tests are skipped if trust is not established.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
from ipalib import api
|
||||
from ipapython.dn import DN
|
||||
from ipatests.test_xmlrpc import objectclasses
|
||||
@@ -53,7 +51,7 @@ class test_external_members(Declarative):
|
||||
|
||||
trusts = api.Command['trust_find']()
|
||||
if trusts['count'] == 0:
|
||||
raise unittest.SkipTest('Trust is not established')
|
||||
pytest.skip('Trust is not established')
|
||||
|
||||
cleanup_commands = [
|
||||
('group_del', [group_name], {}),
|
||||
|
||||
@@ -1400,7 +1400,7 @@ class test_netgroup(Declarative):
|
||||
# entries = conn.find_entries('cn=%s' % self.ng_cn,
|
||||
# base_dn='cn=ng,cn=compat,%s' % api.env.basedn)
|
||||
# except errors.NotFound:
|
||||
# raise unittest.SkipTest(
|
||||
# pytest.skip(
|
||||
# 'compat and nis are not enabled, skipping test'
|
||||
# )
|
||||
# finally:
|
||||
|
||||
@@ -24,7 +24,6 @@ Test the `ipaserver/plugins/permission.py` module.
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from ipalib import api, errors
|
||||
from ipatests.test_xmlrpc import objectclasses
|
||||
@@ -3445,7 +3444,7 @@ class test_managed_permissions(Declarative):
|
||||
@pytest.fixture(autouse=True, scope="class")
|
||||
def managed_perm_setup(self, declarative_setup):
|
||||
if not have_ldap2:
|
||||
raise unittest.SkipTest('server plugin not available')
|
||||
pytest.skip('server plugin not available')
|
||||
|
||||
def add_managed_permission(self):
|
||||
"""Add a managed permission and the corresponding ACI"""
|
||||
|
||||
@@ -9,7 +9,6 @@ Test the `ipaserver/plugins/stageuser.py` module.
|
||||
import pytest
|
||||
|
||||
import six
|
||||
import unittest
|
||||
|
||||
from collections import OrderedDict
|
||||
from ipalib import api, errors
|
||||
@@ -327,7 +326,7 @@ class TestStagedUser(XMLRPC_test):
|
||||
# Directly create the user using ldapmod
|
||||
# without the posixaccount objectclass
|
||||
if not have_ldap2:
|
||||
raise unittest.SkipTest('server plugin not available')
|
||||
pytest.skip('server plugin not available')
|
||||
ldap = ldap2(api)
|
||||
ldap.connect()
|
||||
ldap.create(
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
Test the `ipaserver/plugins/trust.py` module.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
import six
|
||||
|
||||
from ipalib import api, errors
|
||||
@@ -54,7 +52,7 @@ class test_trustconfig(Declarative):
|
||||
try:
|
||||
api.Command['trustconfig_show'](trust_type=u'ad')
|
||||
except errors.NotFound:
|
||||
raise unittest.SkipTest('Trusts are not configured')
|
||||
pytest.skip('Trusts are not configured')
|
||||
|
||||
cleanup_commands = [
|
||||
('group_del', [testgroup], {}),
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
Test the `ipaserver/plugins/vault.py` module.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
import six
|
||||
|
||||
@@ -140,7 +138,7 @@ class test_vault_plugin(Declarative):
|
||||
api.Backend.rpcclient.connect()
|
||||
|
||||
if not api.Command.kra_is_enabled()['result']:
|
||||
raise unittest.SkipTest('KRA service is not enabled')
|
||||
pytest.skip('KRA service is not enabled')
|
||||
|
||||
cleanup_commands = [
|
||||
('vault_del', [vault_name], {'continue': True}),
|
||||
|
||||
@@ -24,7 +24,6 @@ from __future__ import print_function
|
||||
|
||||
import datetime
|
||||
import inspect
|
||||
import unittest
|
||||
|
||||
import contextlib
|
||||
import pytest
|
||||
@@ -211,9 +210,9 @@ class XMLRPC_test:
|
||||
@pytest.fixture(autouse=True, scope="class")
|
||||
def xmlrpc_setup(self, request):
|
||||
if not server_available:
|
||||
raise unittest.SkipTest('%r: Server not available: %r' %
|
||||
(request.cls.__module__,
|
||||
api.env.xmlrpc_uri))
|
||||
pytest.skip('%r: Server not available: %r' %
|
||||
(request.cls.__module__,
|
||||
api.env.xmlrpc_uri))
|
||||
if not api.Backend.rpcclient.isconnected():
|
||||
api.Backend.rpcclient.connect()
|
||||
|
||||
@@ -320,7 +319,7 @@ class Declarative(XMLRPC_test):
|
||||
(cmd, args, options) = command
|
||||
print('Cleanup:', cmd, args, options)
|
||||
if cmd not in api.Command:
|
||||
raise unittest.SkipTest(
|
||||
pytest.skip(
|
||||
'cleanup command %r not in api.Command' % cmd
|
||||
)
|
||||
try:
|
||||
@@ -342,7 +341,7 @@ class Declarative(XMLRPC_test):
|
||||
(cmd, args, options) = command
|
||||
options.setdefault('version', self.default_version)
|
||||
if cmd not in api.Command:
|
||||
raise unittest.SkipTest('%r not in api.Command' % cmd)
|
||||
pytest.skip('%r not in api.Command' % cmd)
|
||||
if isinstance(expected, errors.PublicError):
|
||||
self.check_exception(nice, cmd, args, options, expected)
|
||||
elif hasattr(expected, '__call__'):
|
||||
|
||||
Reference in new issue
Block a user