How to use the bzt.six.iteritems function in bzt

To help you get started, we’ve selected a few bzt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Blazemeter / taurus / bzt / modules / python / generators.py View on Github external
def _check_platform(self):
        inherited_capabilities = [{x: y} for x, y in iteritems(self.capabilities_from_outside)]
        mobile_browsers = ["Chrome", "Safari"]
        mobile_platforms = ["Android", "iOS"]
        remote_executor = self.scenario.get("remote", self.webdriver_address)

        browser = self.scenario.get("browser", None)

        browser_platform = None
        if browser:
            browser_split = browser.split("-")
            browser = browser_split[0]
            browsers = ["Firefox", "Chrome", "Ie", "Opera", "Remote"]
            if browser not in browsers:
                raise TaurusConfigError("Unsupported browser name: %s" % browser)
            if len(browser_split) > 1:
                browser_platform = browser_split[1]
github Blazemeter / taurus / bzt / swagger2yaml.py View on Github external
self.info = self.swagger.get("info", {})

        for name, schema in iteritems(self.swagger.get("definitions", {})):
            self.definitions[name] = Swagger.Definition(name=name, schema=schema)

        for name, response in iteritems(self.swagger.get("responses", {})):
            self.responses[name] = Swagger.Response(name=name, description=response.get("description"),
                                                    schema=response.get("schema"), headers=response.get("headers"))

        for name, param in iteritems(self.swagger.get("parameters", {})):
            parameter = Swagger.Parameter(name=name, location=param.get("in"), description=param.get("description"),
                                          required=param.get("required"), schema=param.get("schema"),
                                          type=param.get("type"), format=param.get("format"))
            self.parameters[name] = parameter

        for name, secdef in iteritems(self.swagger.get("securityDefinitions", {})):
            self.security_defs[name] = Swagger.SecurityDef(type=secdef.get('type'),
                                                           description=secdef.get('description'),
                                                           name=secdef.get('name'),
                                                           location=secdef.get('in'))
github Blazemeter / taurus / bzt / modules / chrome.py View on Github external
def calc_aggregates(self):
        tab_pid = self.tracing_tab_pid
        if tab_pid not in self.memory_per_process:
            return

        memory_per_ts = self.reaggregate_by_ts(self.memory_per_process)
        tab_memory = [process_stats[tab_pid] for ts, process_stats in iteritems(memory_per_ts)]
        yield self.AVERAGE_TAB_MEMORY, average(tab_memory)
        browser_memory = [sum(process_memory for _, process_memory in iteritems(process_stats))
                          for _, process_stats in iteritems(memory_per_ts)]
        yield self.AVERAGE_BROWSER_MEMORY, average(browser_memory)
github Blazemeter / taurus / bzt / swagger2yaml.py View on Github external
def _handle_parameters(self, parameters):
        query_params = OrderedDict()
        form_data = {}
        request_body = None
        headers = {}
        for _, param in iteritems(parameters):
            if not param.required:
                continue
            if param.location == "header":
                name = param.name
                value = self._interpolate_parameter(param)
                headers[name] = value
            elif param.location == "query":
                name = param.name
                value = self._interpolate_parameter(param)
                query_params[name] = value
            elif param.location == "formData":
                name = param.name
                value = self._interpolate_parameter(param)
                form_data[name] = value
            elif param.location == "body":
                request_body = self._interpolate_body(param)
github Blazemeter / taurus / bzt / modules / aggregator.py View on Github external
def __merge_kpis(self, src, dst, sid):
        """
        :param src: dict[str,KPISet]
        :param dst: dict[str,KPISet]
        :param sid: int
        :return:
        """
        for label, val in iteritems(src):
            dest = dst.setdefault(label, KPISet(self.perc_levels, val[KPISet.RESP_TIMES].high))
            if not isinstance(val, KPISet):
                val = KPISet.from_dict(val)
                val.perc_levels = self.perc_levels
            dest.merge_kpis(val, sid)
github Blazemeter / taurus / bzt / modules / python / generators.py View on Github external
headers = {}
        headers.update(self.scenario.get("headers"))
        headers.update(req.headers)

        if headers:
            named_args['headers'] = self.gen_expr(headers)

        merged_headers = dict([(key.lower(), value) for key, value in iteritems(headers)])
        content_type = merged_headers.get("content-type")

        if content_type == 'application/json' and isinstance(req.body, (dict, list)):  # json request body
            named_args['json'] = self.gen_expr(req.body)
        elif req.method.lower() == "get" and isinstance(req.body, dict):  # request URL params (?a=b&c=d)
            named_args['params'] = self.gen_expr(req.body)
        elif isinstance(req.body, dict):  # form data
            named_args['data'] = self.gen_expr(list(iteritems(req.body)))
        elif isinstance(req.body, string_types):
            named_args['data'] = self.gen_expr(req.body)
        elif req.body:
            msg = "Cannot handle 'body' option of type %s: %s"
            raise TaurusConfigError(msg % (type(req.body), req.body))

        return named_args
github Blazemeter / taurus / bzt / modules / chrome.py View on Github external
def reaggregate_by_ts(self, per_pid_stats, aggregate_func=average):
        # TODO: sub-second granularity
        per_ts = dict()  # ts -> (pid -> [measurement at ts])
        for pid in per_pid_stats:
            for offset, value in iteritems(per_pid_stats[pid]):
                base_ts = int(self.convert_ts(offset))
                if base_ts not in per_ts:
                    per_ts[base_ts] = {}
                if pid not in per_ts[base_ts]:
                    per_ts[base_ts][pid] = []
                per_ts[base_ts][pid].append(value)
        return {
            ts: {
                pid: aggregate_func(pid_measurements)
                for pid, pid_measurements in iteritems(stats_per_ts)
            }
            for ts, stats_per_ts in iteritems(per_ts)
        }
github Blazemeter / taurus / bzt / swagger2yaml.py View on Github external
def _extract_scenarios_from_paths(self, paths, default_address, global_security):
        base_path = self.swagger.get_base_path()
        scenarios = OrderedDict()
        global_vars = {
            "default-address": default_address
        }
        if base_path:
            global_vars["default-path"] = base_path

        for path, path_obj in iteritems(paths):
            self.log.info("Handling path %s", path)

            scenario_name = path
            scenario = {
                "default-address": "${default-address}",
                "variables": {},
            }

            if base_path:
                route = "${default-path}" + path
            else:
                route = path

            requests = []
            for method in Swagger.METHODS:
                operation = getattr(path_obj, method)
github Blazemeter / taurus / bzt / jmx / tools.py View on Github external
def compile_scenario(self, scenario):
        elements = []
        for _, protocol in iteritems(self.protocol_handlers):
            elements.extend(protocol.get_toplevel_elements(scenario))
        elements.extend(self.__gen_authorization(scenario))
        elements.extend(self.__gen_keystore_config(scenario))
        elements.extend(self.__gen_data_sources(scenario))
        elements.extend(self.__gen_requests(scenario))
        return elements