From 0023ffb88181f86f2c155c16265c09bd56345237 Mon Sep 17 00:00:00 2001 From: Pavel Zuna Date: Wed, 13 Jan 2010 17:38:35 +0100 Subject: Fix backend.Executioner unit test. Before the patch that allows to create unshared instances of Connectible objects, all Connection object were deleted at once in destroy_context(). It made sense at the time, because there was always at most one Connection per Connectible subclass and Connectible.disconnect() was called only internally by the Executioner class. Now that we can make arbitrary connections, it makes more sense to delete the Connection object when Connectible.disconnect() is called. --- tests/test_ipalib/test_backend.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'tests/test_ipalib/test_backend.py') diff --git a/tests/test_ipalib/test_backend.py b/tests/test_ipalib/test_backend.py index 3c29ee35f..82cf17aac 100644 --- a/tests/test_ipalib/test_backend.py +++ b/tests/test_ipalib/test_backend.py @@ -45,9 +45,14 @@ class test_Backend(ClassChecker): class Disconnect(object): called = False + def __init__(self, id=None): + self.id = id + def __call__(self): assert self.called is False self.called = True + if self.id is not None: + delattr(context, self.id) class test_Connectible(ClassChecker): @@ -207,11 +212,13 @@ class test_Executioner(ClassChecker): o.finalize() # Test that CommandError is raised: - conn = Connection('The connection.', Disconnect()) + conn = Connection('The connection.', Disconnect('someconn')) context.someconn = conn + print str(context.__dict__.keys()) e = raises(errors.CommandError, o.execute, 'nope') assert e.name == 'nope' assert conn.disconnect.called is True # Make sure destroy_context() was called + print str(context.__dict__.keys()) assert context.__dict__.keys() == [] # Test with echo command: @@ -220,7 +227,7 @@ class test_Executioner(ClassChecker): args = (arg1,) + arg2 options = dict(option1=u'How are you?', option2=unicode_str) - conn = Connection('The connection.', Disconnect()) + conn = Connection('The connection.', Disconnect('someconn')) context.someconn = conn assert o.execute('echo', arg1, arg2, **options) == dict( result=(arg1, arg2, options) @@ -228,7 +235,7 @@ class test_Executioner(ClassChecker): assert conn.disconnect.called is True # Make sure destroy_context() was called assert context.__dict__.keys() == [] - conn = Connection('The connection.', Disconnect()) + conn = Connection('The connection.', Disconnect('someconn')) context.someconn = conn assert o.execute('echo', *args, **options) == dict( result=(arg1, arg2, options) @@ -237,7 +244,7 @@ class test_Executioner(ClassChecker): assert context.__dict__.keys() == [] # Test with good command: - conn = Connection('The connection.', Disconnect()) + conn = Connection('The connection.', Disconnect('someconn')) context.someconn = conn e = raises(errors.ValidationError, o.execute, 'good') assert e.name == 'nurse' @@ -246,13 +253,13 @@ class test_Executioner(ClassChecker): assert context.__dict__.keys() == [] # Test with bad command: - conn = Connection('The connection.', Disconnect()) + conn = Connection('The connection.', Disconnect('someconn')) context.someconn = conn e = raises(errors.InternalError, o.execute, 'bad') assert conn.disconnect.called is True # Make sure destroy_context() was called assert context.__dict__.keys() == [] # Test with option 'name': - conn = Connection('The connection.', Disconnect()) + conn = Connection('The connection.', Disconnect('someconn')) context.someconn = conn assert o.execute('with_name', name=u'test') == dict(result=u'TEST') -- cgit