Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not self._target.get("scheme"):
self._target["scheme"] = parsed_url.scheme
if not self._target.get("netloc"):
self._target["netloc"] = parsed_url.netloc
if parsed_url.scheme != self._target["scheme"] or parsed_url.netloc != self._target["netloc"]:
raise TaurusConfigError("Address port and host must be the same")
path = parsed_url.path
if parsed_url.query:
path += "?" + parsed_url.query
else:
if request.method == "GET" and isinstance(request.body, dict):
path += "?" + urlencode(request.body)
if not parsed_url.netloc:
parsed_url = parse.urlparse(scenario.get("default-address", ""))
self.hostname = parsed_url.netloc.split(':')[0] if ':' in parsed_url.netloc else parsed_url.netloc
self.use_ssl = parsed_url.scheme == 'https'
if parsed_url.port:
self.port = parsed_url.port
else:
self.port = 443 if self.use_ssl else 80
return path if len(path) else '/'
def _gen_http_request(self, req):
lines = []
think_time = dehumanize_time(req.get_think_time())
if req.url:
if self.test_mode == "selenium":
if req.timeout:
lines.append(self._gen_impl_wait(req.timeout))
default_address = self.scenario.get("default-address")
parsed_url = parse.urlparse(req.url)
if default_address and not parsed_url.netloc:
url = default_address + req.url
else:
url = req.url
lines.append(ast.Expr(
ast_call(
func=ast_attr("self.driver.get"),
args=[self._gen_expr(url)])))
else:
method = req.method.lower()
named_args = self._extract_named_args(req)
if self._access_method() == ApiritifScriptGenerator.ACCESS_TARGET:
requestor = ast_attr("self.target")
def is_url(url):
return parse.urlparse(url).scheme in ["https", "http"]
def _get_request_path(self, request, scenario):
parsed_url = parse.urlparse(request.url)
if not self._target.get("scheme"):
self._target["scheme"] = parsed_url.scheme
if not self._target.get("netloc"):
self._target["netloc"] = parsed_url.netloc
if parsed_url.scheme != self._target["scheme"] or parsed_url.netloc != self._target["netloc"]:
raise TaurusConfigError("Address port and host must be the same")
path = parsed_url.path
if parsed_url.query:
path += "?" + parsed_url.query
else:
if request.method == "GET" and isinstance(request.body, dict):
path += "?" + urlencode(request.body)
if not parsed_url.netloc:
:rtype: lxml.etree.Element
"""
proxy = etree.Element("HTTPSamplerProxy", guiclass="HttpTestSampleGui", testclass="HTTPSamplerProxy")
proxy.set("testname", label)
args = JMX._get_arguments_panel("HTTPsampler.Arguments")
if isinstance(body, string_types):
JMX.__add_body_from_string(args, body, proxy)
elif isinstance(body, dict):
JMX.__add_body_from_script(args, body, proxy)
elif body:
msg = "Cannot handle 'body' option of type %s: %s"
raise TaurusInternalException(msg % (type(body), body))
parsed_url = parse.urlparse(url)
JMX.__add_hostnameport_2sampler(parsed_url, proxy, url)
path = parsed_url.path
if parsed_url.params:
path += ";" + parsed_url.params
if parsed_url.query:
path += "?" + parsed_url.query
proxy.append(JMX._string_prop("HTTPSampler.path", path))
proxy.append(JMX._string_prop("HTTPSampler.method", method))
proxy.append(JMX._bool_prop("HTTPSampler.use_keepalive", keepalive))
proxy.append(JMX._bool_prop("HTTPSampler.follow_redirects", follow_redirects))
proxy.append(JMX._bool_prop("HTTPSampler.auto_redirects", False))
if timeout is not None:
proxy.append(JMX._string_prop("HTTPSampler.connect_timeout", timeout))
def _embed_query_in_path(self, path, query_dict):
self.log.debug("Query dict: %s", query_dict)
parts = parse.urlparse(path)
query = urlencode(query_dict)
replaced = parts._replace(query=query)
return parse.urlunparse(replaced)
def gen_request(self, req, indent=None):
default_address = self.scenario.get("default-address")
transaction_contents = []
if req.url is not None:
parsed_url = parse.urlparse(req.url)
if default_address and not parsed_url.netloc:
url = default_address + req.url
else:
url = req.url
transaction_contents.append(
self.gen_statement("self.driver.get(self.template(%r))" % url, indent=indent))
transaction_contents.append(self.gen_new_line())
return transaction_contents
def __gen_servers(self, scenario):
default_address = scenario.get("default-address")
if default_address:
base_addr = parse.urlparse(default_address)
else:
first_request = self.__first_http_request(scenario)
if not first_request:
raise TaurusConfigError("Tsung: you must specify requests in scenario")
base_addr = parse.urlparse(first_request.url)
self.log.debug("default-address was not specified, using %s instead", base_addr.hostname)
servers = etree.Element("servers")
port = base_addr.port if base_addr.port is not None else 80
server = etree.Element("server", host=base_addr.hostname, port=str(port), type="tcp")
servers.append(server)
return servers