Example #1
0
 def test_jmx_unicode_checkmark(self):
     obj = JMX()
     res = obj._get_http_request("url", "label", "method", 0,
                                 {"param": u"✓"}, True)
     prop = res.find(".//stringProp[@name='Argument.value']")
     self.assertNotEqual("BINARY", prop.text)
     self.assertEqual(u"✓", prop.text)
Example #2
0
 def test_source_ips_multiple(self):
     obj = JMX()
     res = obj._get_http_request("/",
                                 "label",
                                 "method",
                                 0, {},
                                 True,
                                 use_random_host_ip=True,
                                 host_ips=["192.168.1.1", "192.168.1.2"])
     self.assertEqual(
         "${__chooseRandom(192.168.1.1,192.168.1.2,randomAddr)}",
         res.find(".//stringProp[@name='HTTPSampler.ipSource']").text)
Example #3
0
 def test_param_url(self):
     obj = JMX()
     res = obj._get_http_request(
         url=
         "https://example_url.net/Xhtml;jsessionid=XXXX:XXXX?JacadaApplicationName=XXXX",
         label="label",
         method="method",
         timeout=0,
         body={},
         keepalive=True)
     self.assertEqual(
         "/Xhtml;jsessionid=XXXX:XXXX?JacadaApplicationName=XXXX",
         res.find(".//stringProp[@name='HTTPSampler.path']").text)
Example #4
0
 def test_no_port(self):
     obj = JMX()
     res = obj._get_http_request("http://hostname", "label", "method", 0,
                                 {}, True)
     self.assertEqual(
         "",
         res.find(".//stringProp[@name='HTTPSampler.path']").text)
     self.assertEqual(
         "hostname",
         res.find(".//stringProp[@name='HTTPSampler.domain']").text)
     self.assertEqual(
         "",
         res.find(".//stringProp[@name='HTTPSampler.port']").text)
Example #5
0
 def test_variable_hostname(self):
     obj = JMX()
     res = obj._get_http_request("http://${hostName}:${Port}/${Path}",
                                 "label", "method", 0, {}, True)
     self.assertEqual(
         "/${Path}",
         res.find(".//stringProp[@name='HTTPSampler.path']").text)
     self.assertEqual(
         "${hostName}",
         res.find(".//stringProp[@name='HTTPSampler.domain']").text)
     self.assertEqual(
         "${Port}",
         res.find(".//stringProp[@name='HTTPSampler.port']").text)
Example #6
0
    def compile_http_request(self, request):
        """

        :type request: HierarchicHTTPRequest
        :return:
        """
        timeout = request.priority_option('timeout')
        if timeout is not None:
            timeout = self.smart_time(timeout)

        content_type = self._get_merged_ci_headers(request, 'content-type')
        if content_type == 'application/json' and isinstance(
                request.body, (dict, list)):
            body = json.dumps(request.body)
        else:
            body = request.body

        use_random_host_ip = request.priority_option('random-source-ip',
                                                     default=False)
        host_ips = get_host_ips(
            filter_loopbacks=True) if use_random_host_ip else []
        http = JMX._get_http_request(
            request.url, request.label, request.method, timeout, body,
            request.priority_option('keepalive', default=True),
            request.upload_files, request.content_encoding,
            request.priority_option('follow-redirects', default=True),
            use_random_host_ip, host_ips)

        children = etree.Element("hashTree")

        if request.headers:
            children.append(JMX._get_header_mgr(request.headers))
            children.append(etree.Element("hashTree"))

        self.__add_think_time(children, request)

        self.__add_assertions(children, request)

        if timeout is not None:
            children.append(JMX._get_dur_assertion(timeout))
            children.append(etree.Element("hashTree"))

        self.__add_extractors(children, request)

        self.__add_jsr_elements(children, request)

        return [http, children]
Example #7
0
    def compile_http_request(self, request):
        """

        :type request: HierarchicHTTPRequest
        :return:
        """
        timeout = request.priority_option('timeout')
        if timeout is not None:
            timeout = self.smart_time(timeout)

        content_type = self._get_merged_ci_headers(request, 'content-type')
        if content_type == 'application/json' and isinstance(request.body, (dict, list)):
            body = json.dumps(request.body)
        else:
            body = request.body

        use_random_host_ip = request.priority_option('random-source-ip', default=False)
        host_ips = get_host_ips(filter_loopbacks=True) if use_random_host_ip else []
        http = JMX._get_http_request(request.url, request.label, request.method, timeout, body,
                                     request.priority_option('keepalive', default=True),
                                     request.upload_files, request.content_encoding,
                                     request.priority_option('follow-redirects', default=True),
                                     use_random_host_ip, host_ips)

        children = etree.Element("hashTree")

        if request.headers:
            children.append(JMX._get_header_mgr(request.headers))
            children.append(etree.Element("hashTree"))

        self.__add_think_time(children, request)

        self.__add_assertions(children, request)

        if timeout is not None:
            children.append(JMX._get_dur_assertion(timeout))
            children.append(etree.Element("hashTree"))

        self.__add_extractors(children, request)

        self.__add_jsr_elements(children, request)

        return [http, children]
 def test_no_port(self):
     obj = JMX()
     res = obj._get_http_request("http://hostname", "label", "method", 0, {}, True)
     self.assertEqual("", res.find(".//stringProp[@name='HTTPSampler.path']").text)
     self.assertEqual("hostname", res.find(".//stringProp[@name='HTTPSampler.domain']").text)
     self.assertEqual("", res.find(".//stringProp[@name='HTTPSampler.port']").text)
 def test_variable_hostname(self):
     obj = JMX()
     res = obj._get_http_request("http://${hostName}:${Port}/${Path}", "label", "method", 0, {}, True)
     self.assertEqual("/${Path}", res.find(".//stringProp[@name='HTTPSampler.path']").text)
     self.assertEqual("${hostName}", res.find(".//stringProp[@name='HTTPSampler.domain']").text)
     self.assertEqual("${Port}", res.find(".//stringProp[@name='HTTPSampler.port']").text)
Example #10
0
 def test_jmx_unicode_checkmark(self):
     obj = JMX()
     res = obj._get_http_request("url", "label", "method", 0, {"param": u"✓"}, True)
     prop = res.find(".//stringProp[@name='Argument.value']")
     self.assertNotEqual("BINARY", prop.text)
     self.assertEqual(u"✓", prop.text)
Example #11
0
 def test_source_ips_multiple(self):
     obj = JMX()
     res = obj._get_http_request("/", "label", "method", 0, {}, True,
                                 use_random_host_ip=True, host_ips=["192.168.1.1", "192.168.1.2"])
     self.assertEqual("${__chooseRandom(192.168.1.1,192.168.1.2,randomAddr)}",
                      res.find(".//stringProp[@name='HTTPSampler.ipSource']").text)