Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit b737522

Browse files
yugangw-msfttroydai
authored andcommitted
do not use preparer model for allowing large payload
1 parent f037bef commit b737522

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from setuptools import setup
1010

1111

12-
VERSION = "0.5.3"
12+
VERSION = "0.5.4"
1313

1414

1515
CLASSIFIERS = [

src/azure_devtools/scenario_tests/preparers.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,7 @@ def _preparer_wrapper(test_class_instance, **kwargs):
4848
if parameter_update:
4949
kwargs.update(parameter_update)
5050

51-
if not is_preparer_func(fn):
52-
# the next function is the actual test function. the kwargs need to be trimmed so
53-
# that parameters which are not required will not be passed to it.
54-
args, _, kw, _ = inspect.getargspec(fn) # pylint: disable=deprecated-method
55-
if kw is None:
56-
args = set(args)
57-
for key in [k for k in kwargs if k not in args]:
58-
del kwargs[key]
51+
_trim_kwargs_from_test_function(fn, kwargs)
5952

6053
fn(test_class_instance, **kwargs)
6154

@@ -129,21 +122,39 @@ def process_response(self, response):
129122
return response
130123

131124

132-
# Function wise, enabling large payload recording has nothing to do with resource preparers
133-
# We still base on it so that this decorator can chain with other preparers w/o too much hacks
134-
class AllowLargeResponse(AbstractPreparer):
125+
class AllowLargeResponse(object): # pylint: disable=too-few-public-methods
126+
135127
def __init__(self, size_kb=1024):
136128
self.size_kb = size_kb
137-
super(AllowLargeResponse, self).__init__('nanana', 20)
138129

139-
def create_resource(self, _, **kwargs):
140-
from azure_devtools.scenario_tests import LargeResponseBodyProcessor
141-
large_resp_body = next((r for r in self.test_class_instance.recording_processors
142-
if isinstance(r, LargeResponseBodyProcessor)), None)
143-
if large_resp_body:
144-
large_resp_body._max_response_body = self.size_kb # pylint: disable=protected-access
130+
def __call__(self, fn):
131+
def _preparer_wrapper(test_class_instance, **kwargs):
132+
from azure_devtools.scenario_tests import LargeResponseBodyProcessor
133+
large_resp_body = next((r for r in test_class_instance.recording_processors
134+
if isinstance(r, LargeResponseBodyProcessor)), None)
135+
if large_resp_body:
136+
large_resp_body._max_response_body = self.size_kb # pylint: disable=protected-access
137+
138+
_trim_kwargs_from_test_function(fn, kwargs)
139+
140+
fn(test_class_instance, **kwargs)
141+
142+
setattr(_preparer_wrapper, '__is_preparer', True)
143+
functools.update_wrapper(_preparer_wrapper, fn)
144+
return _preparer_wrapper
145145

146146
# Utility
147147

148+
def _trim_kwargs_from_test_function(fn, kwargs):
149+
# the next function is the actual test function. the kwargs need to be trimmed so
150+
# that parameters which are not required will not be passed to it.
151+
if not is_preparer_func(fn):
152+
args, _, kw, _ = inspect.getargspec(fn) # pylint: disable=deprecated-method
153+
if kw is None:
154+
args = set(args)
155+
for key in [k for k in kwargs if k not in args]:
156+
del kwargs[key]
157+
158+
148159
def is_preparer_func(fn):
149160
return getattr(fn, '__is_preparer', False)

0 commit comments

Comments
 (0)