示例#1
0
文件: core.py 项目: Nooooooo1/apitest
    def _prepare_teststeps(self, fmt_version):
        """ make teststep list.
            teststeps list are parsed from HAR log entries list.

        """
        def is_exclude(url, exclude_str):
            exclude_str_list = exclude_str.split("|")
            for exclude_str in exclude_str_list:
                if exclude_str and exclude_str in url:
                    return True

            return False

        teststeps = []
        log_entries = utils.load_har_log_entries(self.har_file_path)
        for entry_json in log_entries:
            url = entry_json["request"].get("url")
            if self.filter_str and self.filter_str not in url:
                continue

            if is_exclude(url, self.exclude_str):
                continue

            if fmt_version == "v1":
                teststeps.append({"test": self._prepare_teststep(entry_json)})
            else:
                # v2
                teststeps.append(self._prepare_teststep(entry_json))

        return teststeps
示例#2
0
    def test_prepare_teststep(self):
        log_entries = load_har_log_entries(self.har_path)
        teststep_dict = self.har_parser._prepare_teststep(log_entries[0])
        self.assertIn("name", teststep_dict)
        self.assertIn("request", teststep_dict)
        self.assertIn("validate", teststep_dict)

        validators_mapping = {
            validator["eq"][0]: validator["eq"][1]
            for validator in teststep_dict["validate"]
        }
        self.assertEqual(validators_mapping["status_code"], 200)
        self.assertEqual(validators_mapping["content.IsSuccess"], True)
        self.assertEqual(validators_mapping["content.Code"], 200)
        self.assertEqual(validators_mapping["content.Message"], None)
示例#3
0
 def __init__(self, file_path, filter_str=None, exclude_str=None):
     self.log_entries = utils.load_har_log_entries(file_path)
     self.user_agent = None
     self.filter_str = filter_str
     self.exclude_str = exclude_str or ""
     self.ordered_dict = True
示例#4
0
 def __init__(self, file_path, filter_str=None, exclude_str=None):
     self.log_entries = utils.load_har_log_entries(file_path)
     self.user_agent = None
     self.filter_str = filter_str
     self.exclude_str = exclude_str
     self.testset = self.make_testset()
示例#5
0
 def test_load_har_log_empty_error(self):
     with self.assertRaises(SystemExit):
         utils.load_har_log_entries(self.empty_file_path)
示例#6
0
 def test_load_har_log_entries(self):
     log_entries = utils.load_har_log_entries(self.har_path)
     self.assertIsInstance(log_entries, list)
     self.assertIn("request", log_entries[0])
     self.assertIn("response", log_entries[0])