def testdictwrapper_init(): dw = DictWrapper({"testkey": "testvalue"}) # breaking : dictwrapper not iteratable #assert_true("testkey" in dw) # no attribute __getitem__ #assert_equal(dw["testkey"], "testvalue") assert_equal(dw.get("testkey", "notthere"), "testvalue")
class TestDictWrapper(object): """ Fixture allowing DictWrapper manipulations unit testing """ def setup(self): self.dictwrapper = DictWrapper({"testkey": "testvalue"}) pass def teardown(self): pass def test_get_testkey(self): assert_equal(self.dictwrapper.get("testkey", "notthere"), "testvalue")
def _load(self, data): self.data = DictWrapper(data) self.variables.update( data.get('globals', {}).get('variables', {}).items())
def setup(self): self.dictwrapper = DictWrapper({"testkey": "testvalue"}) pass
def _execute_test_step(self, http_client, test_step): failures = Failure([], None) try: r_options = { k: self.case.variables.expand(v) for k, v in dict( test_step.get('request_opts', DictWrapper( {})).items().items() + http_client.extra_request_opts.items()).items() } #http_client = HttpClient(**r_options) method = getattr(test_step, 'method', 'get') is_raw = getattr(test_step, 'raw', False) self.logger.info('\n=======> Executing TestStep : %s, method : %s', test_step.name, method) # process and set up headers headers = {} if hasattr(test_step, 'headers') and test_step.headers is not None: self.logger.debug('Found Headers') for key, value in test_step.headers.items().items(): headers[key] = self.case.variables.expand(value) # process and set up params params = self._build_param_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, r_options, is_raw) # expected_status = getattr(getattr(test_step, 'asserts'), 'status', 200) # if response_wrapper.status != expected_status: # failures.errors.append("status(%s) != expected status(%s)" % (response_wrapper.status, expected_status)) if hasattr(test_step, "asserts"): asserts = test_step.asserts if hasattr(asserts, "headers"): self._assert_element_list( 'Header', failures, test_step, response_wrapper.headers, test_step.asserts.headers.items().items()) if hasattr(asserts, "payload"): self.logger.debug('Evaluating Response Payload') self._assert_element_list( 'Payload', failures, test_step, response_wrapper.body, test_step.asserts.payload.items().items()) else: self.logger.warn( '\n=======> No "asserts" element found in TestStep %s', test_step.name) # execute all the assignment statements if hasattr(test_step, 'postAsserts') and test_step.postAsserts is not None: for key, value in test_step.postAsserts.items().items(): self._process_post_asserts(response_wrapper.body, key, value) except Exception as inst: failures.errors.append(traceback.format_exc()) self.logger.error( 'ERROR !!! TestStep %s Failed to execute !!! %s \ \n !!! Will ignore all assignment statements as part of TestStep', test_step.name, inst) self.logger.exception('Exception') if failures.errors: return failures return None