def test_load_har_log_key_error(self):
     empty_json_file_path = TestUtils.create_har_file(
         file_name="empty_json", content={}
     )
     with self.assertRaises(SystemExit):
         utils.load_har_log_entries(empty_json_file_path)
     os.remove(empty_json_file_path)
Exemple #2
0
    def _prepare_teststeps(self):
        """ 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

            teststeps.append(self._prepare_teststep(entry_json))

        return teststeps
Exemple #3
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["body.IsSuccess"], True)
        self.assertEqual(validators_mapping["body.Code"], 200)
        self.assertEqual(validators_mapping["body.Message"], None)
 def test_load_har_log_entries(self):
     har_path = os.path.join(os.path.dirname(__file__), "data", "demo.har")
     log_entries = utils.load_har_log_entries(har_path)
     self.assertIsInstance(log_entries, list)
     self.assertIn("request", log_entries[0])
     self.assertIn("response", log_entries[0])