Beispiel #1
0
    def test_skip_if_no_requests(self):
        obj = SoapUIScriptConverter(ROOT_LOGGER)
        self.sniff_log(obj.log)

        obj.convert_script(RESOURCES_DIR + "soapui/project.xml")
        self.assertIn("No requests extracted for scenario TestSuite 1-EmptyTestCase, skipping it",
                      self.log_recorder.warn_buff.getvalue())
Beispiel #2
0
    def _extract_scenario_from_soapui(self, base_scenario, script_path):
        test_case = base_scenario.get("test-case", None)
        converter = SoapUIScriptConverter(self.log)
        conv_config = converter.convert_script(script_path)
        conv_scenarios = conv_config["scenarios"]
        scenario_name, conv_scenario = converter.find_soapui_test_case(
            test_case, conv_scenarios)

        new_name = scenario_name
        counter = 1
        while new_name in self.engine.config["scenarios"]:
            new_name = scenario_name + ("-%s" % counter)
            counter += 1

        if new_name != scenario_name:
            self.log.info(
                "Scenario name '%s' is already taken, renaming to '%s'",
                scenario_name, new_name)
            scenario_name = new_name

        merged_scenario = BetterDict.from_dict(conv_scenario)
        merged_scenario.merge(base_scenario.data)
        for field in [Scenario.SCRIPT, "test-case"]:
            if field in merged_scenario:
                merged_scenario.pop(field)

        return scenario_name, merged_scenario
Beispiel #3
0
    def test_minimal(self):
        obj = SoapUIScriptConverter(ROOT_LOGGER)
        config = obj.convert_script(RESOURCES_DIR + "soapui/project.xml")

        self.assertIn("execution", config)
        self.assertEqual(4, len(config["execution"]))
        execution = config["execution"][1]
        self.assertEqual("TestSuite 1-index", execution.get("scenario"))
        self.assertEqual(60, execution.get("hold-for"))
        self.assertEqual(10, execution.get("concurrency"))

        self.assertIn("scenarios", config)
        self.assertIn("TestSuite 1-index", config["scenarios"])

        scenario = config["scenarios"]["TestSuite 1-index"]
        self.assertIn("requests", scenario)
        self.assertEqual(3, len(scenario["requests"]))

        self.assertIn("variables", scenario)
        self.assertEqual("foo", scenario["variables"].get("something"))
        self.assertEqual("2", scenario["variables"].get("something_else"))
        self.assertEqual("json", scenario["variables"].get("route_part"))

        first_req = scenario["requests"][0]
        self.assertEqual("http://blazedemo.com/reserve.php", first_req["url"])
        self.assertEqual("test index", first_req["label"])
        self.assertIn("headers", first_req)
        self.assertEqual(first_req["headers"].get("X-Custom-Header"), "Value")
        self.assertIn("assert", first_req)
        self.assertEqual(2, len(first_req["assert"]))

        self.assertEqual("BlazeDemo", first_req["assert"][0]["contains"][0])
        self.assertFalse(first_req["assert"][0]["not"])
        self.assertFalse(first_req["assert"][0]["regexp"])

        self.assertEqual("BlazeDemou", first_req["assert"][1]["contains"][0])
        self.assertTrue(first_req["assert"][1]["not"])
        self.assertTrue(first_req["assert"][1]["regexp"])

        second_req = scenario["requests"][1]
        self.assertEqual("http://example.com/body", second_req["url"])
        self.assertEqual("posty", second_req["label"])
        self.assertEqual("POST", second_req["method"])
        self.assertIn("headers", second_req)
        self.assertEqual(second_req["headers"].get("X-Header"), "X-Value")
        self.assertEqual(second_req["headers"].get("X-Header-2"), "X-Value-2")
        self.assertIn("body", second_req)
        self.assertIn("answer", second_req["body"])
        self.assertEqual('42', second_req["body"]["answer"])
        self.assertIn("extract-xpath", second_req)
        self.assertIn("something_else", second_req["extract-xpath"])
        self.assertEqual("//head", second_req["extract-xpath"]["something_else"]["xpath"])

        third_req = scenario["requests"][2]
        self.assertEqual("http://localhost:9999/api/${route_part}", third_req["url"])
        self.assertEqual("/api/json", third_req["label"])
        self.assertIn("extract-jsonpath", third_req)
        self.assertIn("something", third_req["extract-jsonpath"])
        self.assertEqual("$.baz", third_req["extract-jsonpath"]["something"]["jsonpath"])
Beispiel #4
0
 def test_rest_service_name_as_base_address(self):
     obj = SoapUIScriptConverter(ROOT_LOGGER)
     config = obj.convert_script(RESOURCES_DIR + "soapui/youtube-sample.xml")
     scenarios = config["scenarios"]
     scenario = scenarios["TestSuite-TestCase"]
     self.assertEqual(len(scenario["requests"]), 5)
     for request in scenario["requests"]:
         self.assertTrue(request["url"].startswith("http://gdata.youtube.com/"))
Beispiel #5
0
 def test_project_suite_case_level_properties(self):
     obj = SoapUIScriptConverter(ROOT_LOGGER)
     config = obj.convert_script(RESOURCES_DIR + "soapui/flickr-sample.xml")
     scenarios = config["scenarios"]
     scenario = scenarios["TestSuite-TestCase"]
     self.assertEqual(len(scenario["variables"]), 2)
     self.assertIn("#Project#ApiKey", scenario["variables"])
     self.assertIn("#TestCase#temp", scenario["variables"])
Beispiel #6
0
    def test_find_test_case(self):
        obj = SoapUIScriptConverter(ROOT_LOGGER)
        config = obj.convert_script(RESOURCES_DIR + "soapui/project.xml")

        scenarios = config["scenarios"]
        self.assertEqual(len(scenarios), 4)

        target_scenario = scenarios["TestSuite 1-index"]
        found_name, found_scenario = obj.find_soapui_test_case("index", scenarios)
        self.assertEqual(target_scenario, found_scenario)
Beispiel #7
0
 def test_rest_parameters(self):
     obj = SoapUIScriptConverter(ROOT_LOGGER)
     config = obj.convert_script(RESOURCES_DIR + "soapui/flickr-sample.xml")
     scenarios = config["scenarios"]
     scenario = scenarios["TestSuite-TestCase"]
     self.assertEqual(len(scenario["requests"]), 4)
     first = scenario["requests"][0]
     self.assertIn("body", first)
     self.assertEqual(len(first["body"]), 4)
     self.assertTrue(all(key in first["body"] for key in ["format", "method", "nojsoncallback", "api_key"]))
Beispiel #8
0
    def test_find_test_case_empty(self):
        obj = SoapUIScriptConverter(ROOT_LOGGER)
        self.sniff_log(obj.log)

        config = obj.convert_script(RESOURCES_DIR + "soapui/project.xml")

        scenarios = config["scenarios"]
        self.assertEqual(len(scenarios), 4)

        target_scenario = scenarios["BlazeDemo LoadTest"]
        found_name, found_scenario = obj.find_soapui_test_case(None, scenarios)
        self.assertEqual(target_scenario, found_scenario)
Beispiel #9
0
    def test_rest_templated_params_interpolation(self):
        obj = SoapUIScriptConverter(ROOT_LOGGER)
        config = obj.convert_script(RESOURCES_DIR + "soapui/gmaps-sample.xml")
        self.assertEqual(len(config["scenarios"]), 10)
        scenario = config["scenarios"]["Directions API TestSuite-Simple Tests"]

        for request in scenario["requests"]:
            self.assertNotIn("{format}", request["url"])

        self.assertEqual(scenario["requests"][0]["url"], "http://maps.googleapis.com/maps/api/directions/json")
        self.assertEqual(scenario["requests"][1]["url"], "http://maps.googleapis.com/maps/api/directions/json")
        self.assertEqual(scenario["requests"][2]["url"], "http://maps.googleapis.com/maps/api/directions/xml")
Beispiel #10
0
class SoapUI2YAML(object):
    def __init__(self, options, file_name):
        self.log = logging.getLogger(self.__class__.__name__)
        self.options = options
        self.setup_logging()
        self.converter = None
        self.file_to_convert = file_name

    def setup_logging(self):
        CLI.setup_logging(self.options)
        if self.options.quiet:
            logging.disable(logging.WARNING)

    def process(self):
        output_format = Configuration.JSON if self.options.json else Configuration.YAML

        self.log.info('Loading SoapUI project %s', self.file_to_convert)
        self.file_to_convert = os.path.abspath(
            os.path.expanduser(self.file_to_convert))
        if not os.path.exists(self.file_to_convert):
            raise TaurusInternalException("File does not exist: %s" %
                                          self.file_to_convert)
        self.converter = SoapUIScriptConverter(self.log)
        try:
            converted_config = self.converter.convert_script(
                self.file_to_convert, self.options.test_case)
        except BaseException:
            self.log.error("Error while processing SoapUI project: %s",
                           self.file_to_convert)
            raise

        self._cleanup_config(converted_config)

        exporter = Configuration.from_dict(converted_config)

        if self.options.file_name:
            file_name = self.options.file_name
        else:
            file_name = self.file_to_convert + "." + output_format.lower()

        exporter.dump(file_name, output_format)

        self.log.info("Done processing, result saved in %s", file_name)

    @staticmethod
    def _cleanup_config(config):
        for _, scenario in iteritems(config.get("scenarios")):
            if "test-case" in scenario:
                scenario.pop("test-case")
            if "test-suite" in scenario:
                scenario.pop("test-suite")
Beispiel #11
0
    def test_find_test_case_empty(self):
        obj = SoapUIScriptConverter(ROOT_LOGGER)
        self.sniff_log(obj.log)

        config = obj.convert_script(RESOURCES_DIR + "soapui/project.xml")

        scenarios = config["scenarios"]
        self.assertEqual(len(scenarios), 3)

        target_scenario = scenarios["TestSuite 1-index"]
        found_name, found_scenario = obj.find_soapui_test_case(None, scenarios)
        self.assertEqual(target_scenario, found_scenario)

        self.assertIn("No `test-case` specified for SoapUI project, will use 'index'",
                      self.log_recorder.warn_buff.getvalue())
Beispiel #12
0
    def test_soap_conversion(self):
        obj = SoapUIScriptConverter(ROOT_LOGGER)
        config = obj.convert_script(RESOURCES_DIR + "soapui/globalweather.xml")
        self.assertEqual(len(config["scenarios"]), 4)
        merged = config["scenarios"]["GWSOAPMerged-Test"]
        split1 = config["scenarios"]["GWSOAPSplit-GetCities"]
        split2 = config["scenarios"]["GWSOAPSplit-GetWeather"]

        self.assertEqual(len(merged["requests"]), 2)
        self.assertEqual(merged["requests"][0]["url"], "http://www.webservicex.com/globalweather.asmx")
        self.assertEqual(merged["requests"][0]["method"], "POST")
        self.assertEqual(merged["requests"][0]["headers"]["Content-Type"], "text/xml; charset=utf-8")
        self.assertIn("body", merged["requests"][0])
        self.assertEqual(merged["requests"][1]["url"], "http://www.webservicex.com/globalweather.asmx")

        self.assertEqual(len(split1["requests"]), 1)
        self.assertEqual(split1["requests"][0]["url"], "http://www.webservicex.com/globalweather.asmx")

        self.assertEqual(len(split2["requests"]), 1)
        self.assertEqual(split2["requests"][0]["url"], "http://www.webservicex.com/globalweather.asmx")