Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
curl_examples: Fix curl testing for multiple configs.
Suyash Vardhan Mathure5221a8434ad
diff --git a/zerver/openapi/test_curl_examples.py b/zerver/openapi/test_curl_examples.pyindex 0c3506067a4..80225d789e7 100644--- a/zerver/openapi/test_curl_examples.py+++ b/zerver/openapi/test_curl_examples.py@@ -82,28 +82,28 @@ def test_generated_curl_examples_for_success(client: Client) -> None:unescaped_html = html.unescape(curl_command_html)curl_regex = re.compile(r"<code>curl\n(.*?)</code>", re.DOTALL)commands = re.findall(curl_regex, unescaped_html)- curl_command_text = unescaped_html[len("<p><code>curl\n") : -len("</code></p>")]- curl_command_text = curl_command_text.replace(- "BOT_EMAIL_ADDRESS:BOT_API_KEY", AUTHENTICATION_LINE[0]- )+ for curl_command_text in commands:+ curl_command_text = curl_command_text.replace(+ "BOT_EMAIL_ADDRESS:BOT_API_KEY", AUTHENTICATION_LINE[0]+ )- print("Testing {} ...".format(curl_command_text.split("\n")[0]))+ print("Testing {} ...".format(curl_command_text.split("\n")[0]))- # Turn the text into an arguments list.- generated_curl_command = [x for x in shlex.split(curl_command_text) if x != "\n"]+ # Turn the text into an arguments list.+ generated_curl_command = [x for x in shlex.split(curl_command_text) if x != "\n"]- response_json = None- response = None- try:- # We split this across two lines so if curl fails and- # returns non-JSON output, we'll still print it.- response_json = subprocess.check_output(- generated_curl_command, universal_newlines=True- )- response = json.loads(response_json)- assert response["result"] == "success"- except (AssertionError, Exception):- error_template = """+ response_json = None+ response = None+ try:+ # We split this across two lines so if curl fails and+ # returns non-JSON output, we'll still print it.+ response_json = subprocess.check_output(+ generated_curl_command, universal_newlines=True+ )+ response = json.loads(response_json)+ assert response["result"] == "success"+ except (AssertionError, Exception):+ error_template = """Error verifying the success of the API documentation curl example.File: {file_name}@@ -125,16 +125,16 @@ Common reasons for why this could occur:To learn more about the test itself, see zerver/openapi/test_curl_examples.py."""- print(- error_template.format(- file_name=file_name,- line=line,- curl_command=generated_curl_command,- response=response_json- if response is None- else json.dumps(response, indent=4),+ print(+ error_template.format(+ file_name=file_name,+ line=line,+ curl_command=generated_curl_command,+ response=response_json+ if response is None+ else json.dumps(response, indent=4),+ ))- )- raise+ raiseassert_all_helper_functions_called()