Beispiel #1
0
    def __call__(self):
        # What was this?
        #skip_all_subsequent_tests = False

        http_client = HttpClient(**self.case.request_opts)

        for step in self.case.steps:
            self.logger.debug('Test Step Name : %s', step.name)
            if step.get('skip', False):
                self.logger.info('\n=======> Skipping test case : ' +
                                 step.name)
                self.skipped.append(step)
                continue

            @log_capture()
            def _run(l):
                failures = self._execute_test_step(http_client, step)
                return failures, l

            f, logs = _run()
            if f:
                self.failed.append(
                    (step, Failure(f.errors,
                                   "".join(self._format_logs(logs)))))
            else:
                self.passed.append(step)

        return self._result()
Beispiel #2
0
    def _execute_test_step(self, test_step):
        http_client = HttpClient(**self.case.request_opts)
        failures = Failure([], None)
        try:
            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, 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)

        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

        # 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)

        return None
Beispiel #3
0
 def setup(self):
     self.client = HttpClient()
     pass