[mocking-machinery] Add original method function
This commit adds opportunity to call original method in mock method. Corresponding test is attached. Targets blueprint mocking-machinery Change-Id: I889bb576e708d28a083c0a25f66c999a6492057f
This commit is contained in:
parent
5aeba4447a
commit
b9b2a9b881
@ -145,6 +145,8 @@ def inject_method_with_yaql_expr(context, target, target_method, expr):
|
||||
def payload_adapter(__super, __context, __sender, *args, **kwargs):
|
||||
new_context = context.create_child_context()
|
||||
new_context[constants.CTX_ORIGINAL_CONTEXT] = __context
|
||||
new_context.register_function(lambda: __super(*args, **kwargs),
|
||||
name='originalMethod')
|
||||
return expr(new_context, __sender, *args, **kwargs)
|
||||
|
||||
result_fd.payload = payload_adapter
|
||||
|
@ -127,3 +127,7 @@ class TestMockYaqlFunctions(test_case.DslTestCase):
|
||||
def test_with_original(self):
|
||||
self.runner.testWithoriginal()
|
||||
self.assertEqual(['DEFAULT'], self.traces)
|
||||
|
||||
def test_original_method(self):
|
||||
self.runner.testOriginalMethod()
|
||||
self.assertEqual(['method1'], self.traces)
|
||||
|
Loading…
Reference in New Issue
Block a user