Imported Debian patch 4.0.5-6~numeezy
This commit is contained in:
committed by
Mario Fetka
parent
c44de33144
commit
10dfc9587b
@@ -20,14 +20,9 @@
|
||||
"""
|
||||
Base class for all XML-RPC tests
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import datetime
|
||||
|
||||
import nose
|
||||
import contextlib
|
||||
import six
|
||||
|
||||
from ipatests.util import assert_deepequal, Fuzzy
|
||||
from ipalib import api, request, errors
|
||||
from ipalib.x509 import valid_issuer
|
||||
@@ -37,7 +32,7 @@ from ipapython.version import API_VERSION
|
||||
# Matches a gidnumber like '1391016742'
|
||||
# FIXME: Does it make more sense to return gidnumber, uidnumber, etc. as `int`
|
||||
# or `long`? If not, we still need to return them as `unicode` instead of `str`.
|
||||
fuzzy_digits = Fuzzy('^\d+$', type=six.string_types)
|
||||
fuzzy_digits = Fuzzy('^\d+$', type=basestring)
|
||||
|
||||
uuid_re = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
|
||||
|
||||
@@ -77,23 +72,15 @@ fuzzy_sudocmddn = Fuzzy(
|
||||
'(?i)ipauniqueid=%s,cn=sudocmds,cn=sudo,%s' % (uuid_re, api.env.basedn)
|
||||
)
|
||||
|
||||
# Matches caacl dn
|
||||
fuzzy_caacldn = Fuzzy(
|
||||
'(?i)ipauniqueid=%s,cn=caacls,cn=ca,%s' % (uuid_re, api.env.basedn)
|
||||
)
|
||||
|
||||
# Matches fuzzy ipaUniqueID DN group (RDN)
|
||||
fuzzy_ipauniqueid = Fuzzy('(?i)ipauniqueid=%s' % uuid_re)
|
||||
|
||||
# Matches a hash signature, not enforcing length
|
||||
fuzzy_hash = Fuzzy('^([a-f0-9][a-f0-9]:)+[a-f0-9][a-f0-9]$', type=six.string_types)
|
||||
fuzzy_hash = Fuzzy('^([a-f0-9][a-f0-9]:)+[a-f0-9][a-f0-9]$', type=basestring)
|
||||
|
||||
# Matches a date, like Tue Apr 26 17:45:35 2016 UTC
|
||||
fuzzy_date = Fuzzy('^[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} UTC$')
|
||||
|
||||
fuzzy_issuer = Fuzzy(type=six.string_types, test=lambda issuer: valid_issuer(issuer))
|
||||
fuzzy_issuer = Fuzzy(type=basestring, test=lambda issuer: valid_issuer(issuer))
|
||||
|
||||
fuzzy_hex = Fuzzy('^0x[0-9a-fA-F]+$', type=six.string_types)
|
||||
fuzzy_hex = Fuzzy('^0x[0-9a-fA-F]+$', type=basestring)
|
||||
|
||||
# Matches password - password consists of all printable characters without whitespaces
|
||||
# The only exception is space, but space cannot be at the beggingin or end of the pwd
|
||||
@@ -103,7 +90,7 @@ fuzzy_password = Fuzzy('^\S([\S ]*\S)*$')
|
||||
fuzzy_dergeneralizedtime = Fuzzy(type=datetime.datetime)
|
||||
|
||||
# match any string
|
||||
fuzzy_string = Fuzzy(type=six.string_types)
|
||||
fuzzy_string = Fuzzy(type=basestring)
|
||||
|
||||
# case insensitive match of sets
|
||||
def fuzzy_set_ci(s):
|
||||
@@ -181,15 +168,19 @@ class XMLRPC_test(object):
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
def setUpClass(cls):
|
||||
if not server_available:
|
||||
raise nose.SkipTest('%r: Server not available: %r' %
|
||||
(cls.__module__, api.env.xmlrpc_uri))
|
||||
|
||||
def setUp(self):
|
||||
if not api.Backend.rpcclient.isconnected():
|
||||
api.Backend.rpcclient.connect(fallback=False)
|
||||
|
||||
@classmethod
|
||||
def teardown_class(cls):
|
||||
def tearDown(self):
|
||||
"""
|
||||
nose tear-down fixture.
|
||||
"""
|
||||
request.destroy_context()
|
||||
|
||||
def failsafe_add(self, obj, pk, **options):
|
||||
@@ -203,20 +194,11 @@ class XMLRPC_test(object):
|
||||
:param pk: The primary key of the entry to be created
|
||||
:param options: Kwargs to be passed to obj.add()
|
||||
"""
|
||||
self.failsafe_del(obj, pk)
|
||||
return obj.methods['add'](pk, **options)
|
||||
|
||||
@classmethod
|
||||
def failsafe_del(cls, obj, pk):
|
||||
"""
|
||||
Delete an entry if it exists
|
||||
:param obj: An Object like api.Object.user
|
||||
:param pk: The primary key of the entry to be deleted
|
||||
"""
|
||||
try:
|
||||
obj.methods['del'](pk)
|
||||
except errors.NotFound:
|
||||
pass
|
||||
return obj.methods['add'](pk, **options)
|
||||
|
||||
|
||||
IGNORE = """Command %r is missing attribute %r in output entry.
|
||||
@@ -247,9 +229,6 @@ KWARGS = """Command %r raised %s with wrong kwargs.
|
||||
class Declarative(XMLRPC_test):
|
||||
"""A declarative-style test suite
|
||||
|
||||
This class is DEPRECATED. Use RPCTest instead.
|
||||
See host plugin tests for an example.
|
||||
|
||||
A Declarative test suite is controlled by the ``tests`` and
|
||||
``cleanup_commands`` class variables.
|
||||
|
||||
@@ -277,41 +256,56 @@ class Declarative(XMLRPC_test):
|
||||
cleanup_commands = tuple()
|
||||
tests = tuple()
|
||||
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
super(Declarative, cls).setup_class()
|
||||
for command in cls.cleanup_commands:
|
||||
cls.cleanup(command)
|
||||
def cleanup_generate(self, stage):
|
||||
for (i, command) in enumerate(self.cleanup_commands):
|
||||
func = lambda: self.cleanup(command)
|
||||
func.description = '%s %s-cleanup[%d]: %r' % (
|
||||
self.__class__.__name__, stage, i, command
|
||||
)
|
||||
yield (func,)
|
||||
|
||||
@classmethod
|
||||
def teardown_class(cls):
|
||||
for command in cls.cleanup_commands:
|
||||
cls.cleanup(command)
|
||||
super(Declarative, cls).teardown_class()
|
||||
|
||||
@classmethod
|
||||
def cleanup(cls, command):
|
||||
def cleanup(self, command):
|
||||
(cmd, args, options) = command
|
||||
print('Cleanup:', cmd, args, options)
|
||||
if cmd not in api.Command:
|
||||
raise nose.SkipTest(
|
||||
'cleanup command %r not in api.Command' % cmd
|
||||
)
|
||||
try:
|
||||
api.Command[cmd](*args, **options)
|
||||
except (errors.NotFound, errors.EmptyModlist) as e:
|
||||
print(e)
|
||||
except (errors.NotFound, errors.EmptyModlist):
|
||||
pass
|
||||
|
||||
def test_command(self, index, declarative_test_definition):
|
||||
"""Run an individual test
|
||||
|
||||
The arguments are provided by the pytest plugin.
|
||||
def test_generator(self):
|
||||
"""
|
||||
if callable(declarative_test_definition):
|
||||
declarative_test_definition(self)
|
||||
else:
|
||||
self.check(**declarative_test_definition)
|
||||
Iterate through tests.
|
||||
|
||||
nose reports each one as a seperate test.
|
||||
"""
|
||||
|
||||
# Iterate through pre-cleanup:
|
||||
for tup in self.cleanup_generate('pre'):
|
||||
yield tup
|
||||
|
||||
# Iterate through the tests:
|
||||
name = self.__class__.__name__
|
||||
for (i, test) in enumerate(self.tests):
|
||||
if callable(test):
|
||||
func = lambda: test(self)
|
||||
nice = '%s[%d]: call %s: %s' % (
|
||||
name, i, test.__name__, test.__doc__
|
||||
)
|
||||
func.description = nice
|
||||
else:
|
||||
nice = '%s[%d]: %s: %s' % (
|
||||
name, i, test['command'][0], test.get('desc', '')
|
||||
)
|
||||
func = lambda: self.check(nice, **test)
|
||||
func.description = nice
|
||||
yield (func,)
|
||||
|
||||
# Iterate through post-cleanup:
|
||||
for tup in self.cleanup_generate('post'):
|
||||
yield tup
|
||||
|
||||
def check(self, nice, desc, command, expected, extra_check=None):
|
||||
(cmd, args, options) = command
|
||||
@@ -330,7 +324,7 @@ class Declarative(XMLRPC_test):
|
||||
name = klass.__name__
|
||||
try:
|
||||
output = api.Command[cmd](*args, **options)
|
||||
except Exception as e:
|
||||
except StandardError, e:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError(
|
||||
@@ -345,9 +339,7 @@ class Declarative(XMLRPC_test):
|
||||
# client side. However, if we switch to using JSON-RPC for the default
|
||||
# transport, the exception is a free-form data structure (dict).
|
||||
# For now just compare the strings
|
||||
# pylint: disable=no-member
|
||||
assert_deepequal(expected.strerror, e.strerror)
|
||||
# pylint: enable=no-member
|
||||
|
||||
def check_callable(self, nice, cmd, args, options, expected):
|
||||
name = expected.__class__.__name__
|
||||
@@ -355,12 +347,12 @@ class Declarative(XMLRPC_test):
|
||||
e = None
|
||||
try:
|
||||
output = api.Command[cmd](*args, **options)
|
||||
except Exception as e:
|
||||
except StandardError, e:
|
||||
pass
|
||||
if not expected(e, output):
|
||||
raise AssertionError(
|
||||
UNEXPECTED % (cmd, name, args, options,
|
||||
type(e).__name__, e)
|
||||
e.__class__.__name__, e)
|
||||
)
|
||||
|
||||
def check_output(self, nice, cmd, args, options, expected, extra_check):
|
||||
@@ -368,23 +360,3 @@ class Declarative(XMLRPC_test):
|
||||
assert_deepequal(expected, got, nice)
|
||||
if extra_check and not extra_check(got):
|
||||
raise AssertionError('Extra check %s failed' % extra_check)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def raises_exact(expected_exception):
|
||||
"""Check that a specific PublicError is raised
|
||||
|
||||
Both type and message of the error are checked.
|
||||
|
||||
>>> with raises_exact(errors.ValidationError(name='x', error='y')):
|
||||
... raise errors.ValidationError(name='x', error='y')
|
||||
"""
|
||||
try:
|
||||
yield
|
||||
except errors.PublicError as got_exception:
|
||||
assert type(expected_exception) is type(got_exception)
|
||||
# FIXME: We should return error information in a structured way.
|
||||
# For now just compare the strings
|
||||
assert expected_exception.strerror == got_exception.strerror
|
||||
else:
|
||||
raise AssertionError('did not raise!')
|
||||
|
||||
Reference in New Issue
Block a user