diff --git a/rester/__init__.py b/rester/__init__.py index e69de29..59cd959 100644 --- a/rester/__init__.py +++ b/rester/__init__.py @@ -0,0 +1 @@ +from . import apirunner \ No newline at end of file diff --git a/rester/exc.py b/rester/exc.py index 5f3c7d7..f90d50d 100644 --- a/rester/exc.py +++ b/rester/exc.py @@ -65,6 +65,17 @@ def _build_param_dict(self, test_step): params[key] = self.case.variables.expand(value) return params + def _build_data_dict(self, test_step): + data = {} + if hasattr(test_step, 'payload') and test_step.payload is not None: + print "PAYLOAD %r", test_step.payload + print "PAYLOAD ITEMS %r", test_step.payload.items() + for key, value in test_step.payload.items(): + print "KEY %r", key + print "VALUE %r", value + data[key] = self.case.variables.expand(value) + return data + def _execute_test_step(self, test_step): http_client = HttpClient(**self.case.request_opts) failures = Failure([], None) @@ -83,9 +94,13 @@ def _execute_test_step(self, test_step): # process and set up params params = self._build_param_dict(test_step) + # process and set up data + data = self._build_data_dict(test_step) + url = self.case.variables.expand(test_step.apiUrl) self.logger.debug('Evaluated URL : %s', url) - response_wrapper = http_client.request(url, method, headers, params, is_raw) + self.logger.debug('Sending Data : %s', data) + response_wrapper = http_client.request(url, method, headers, params, data, is_raw) # expected_status = getattr(getattr(test_step, 'asserts'), 'status', 200) # if response_wrapper.status != expected_status: diff --git a/rester/http.py b/rester/http.py index 1c8888c..3a9da05 100644 --- a/rester/http.py +++ b/rester/http.py @@ -11,7 +11,7 @@ class HttpClient(object): def __init__(self, **kwargs): self.extra_request_opts = kwargs - def request(self, api_url, method, headers, params, is_raw): + def request(self, api_url, method, headers, params, data, is_raw): self.logger.info( '\n Invoking REST Call... api_url: %s, method: %s, headers %s : ', api_url, method, headers) @@ -20,7 +20,7 @@ def request(self, api_url, method, headers, params, is_raw): except AttributeError: self.logger.error('undefined HTTP method!!! %s', method) raise - response = func(api_url, headers=headers, params=params, **self.extra_request_opts) + response = func(api_url, headers=headers, params=params, json=data, **self.extra_request_opts) if is_raw or 'application/json' not in response.headers['content-type']: payload = {"__raw__": response.text}