tests: Remove get-raw-message from curl test exclude_list.

This commit is contained in:
Vishnu KS 2019-10-21 16:13:00 +05:30 committed by Tim Abbott
parent 722f3a6cfe
commit 8e9ccdf376
6 changed files with 67 additions and 1 deletions

View File

@ -3,6 +3,8 @@ import argparse
import os import os
import sys import sys
os.environ["RUNNING_OPENAPI_CURL_TEST"] = "1"
# check for the venv # check for the venv
from lib import sanity_check from lib import sanity_check
sanity_check.check_venv(__file__) sanity_check.check_venv(__file__)

View File

@ -2,6 +2,8 @@ import re
import json import json
import inspect import inspect
from django.conf import settings
from markdown.extensions import Extension from markdown.extensions import Extension
from markdown.preprocessors import Preprocessor from markdown.preprocessors import Preprocessor
from typing import Any, Dict, Optional, List, Tuple from typing import Any, Dict, Optional, List, Tuple
@ -159,6 +161,10 @@ def generate_curl_example(endpoint: str, method: str,
openapi_entry = openapi_spec.spec()['paths'][endpoint][method.lower()] openapi_entry = openapi_spec.spec()['paths'][endpoint][method.lower()]
openapi_params = openapi_entry.get("parameters", []) openapi_params = openapi_entry.get("parameters", [])
if settings.RUNNING_OPENAPI_CURL_TEST: # nocoverage
from zerver.openapi.curl_param_value_generators import patch_openapi_params
openapi_params = patch_openapi_params(endpoint + ":" + method.lower(), openapi_params)
format_dict = {} format_dict = {}
for param in openapi_params: for param in openapi_params:
if param["in"] != "path": if param["in"] != "path":

View File

@ -0,0 +1,49 @@
from typing import Dict, Any, Callable, Set, List
from functools import wraps
from zerver.lib.test_classes import ZulipTestCase
GENERATOR_FUNCTIONS = dict() # type: Dict[str, Callable[..., Dict[Any, Any]]]
REGISTERED_GENERATOR_FUNCTIONS = set() # type: Set[str]
CALLED_GENERATOR_FUNCTIONS = set() # type: Set[str]
helpers = ZulipTestCase()
def openapi_param_value_generator(endpoints: List[str]) -> Callable[[Callable[..., Any]],
Callable[..., Any]]:
"""This decorator is used to register openapi param value genarator functions
with endpoints. Example usage:
@openapi_param_value_generator(["/messages/render:post"])
def ...
"""
def wrapper(generator_func: Callable[..., Dict[Any, Any]]) -> Callable[..., Dict[Any, Any]]:
@wraps(generator_func)
def _record_calls_wrapper(*args: Any, **kwargs: Any) -> Dict[Any, Any]:
CALLED_GENERATOR_FUNCTIONS.add(generator_func.__name__)
return generator_func(*args, **kwargs)
REGISTERED_GENERATOR_FUNCTIONS.add(generator_func.__name__)
for endpoint in endpoints:
GENERATOR_FUNCTIONS[endpoint] = _record_calls_wrapper
return _record_calls_wrapper
return wrapper
def patch_openapi_params(openapi_entry: str, openapi_params: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
if openapi_entry not in GENERATOR_FUNCTIONS:
return openapi_params
func = GENERATOR_FUNCTIONS[openapi_entry]
realm_param_values = func() # type: Dict[str, Any]
for param in openapi_params:
param_name = param["name"]
if param_name in realm_param_values:
param["example"] = realm_param_values[param_name]
return openapi_params
@openapi_param_value_generator(["/messages/{message_id}:get"])
def iago_message_id() -> Dict[str, int]:
return {
"message_id": helpers.send_stream_message(helpers.example_email("iago"), "Denmark")
}

View File

@ -8,12 +8,12 @@ import os
from zulip import Client from zulip import Client
from zerver.lib.bugdown import api_code_examples from zerver.lib.bugdown import api_code_examples
from zerver.models import get_realm from zerver.models import get_realm
from zerver.openapi.curl_param_value_generators import REGISTERED_GENERATOR_FUNCTIONS, CALLED_GENERATOR_FUNCTIONS
exclude_list = [ exclude_list = [
# The endpoint in these docs expect one or more param values that reflects the DB state. # The endpoint in these docs expect one or more param values that reflects the DB state.
# We currently get the example values from openapi specs and they don't refelect the # We currently get the example values from openapi specs and they don't refelect the
# state of the DB. This results in the curl request to fail. # state of the DB. This results in the curl request to fail.
'get-raw-message.md',
'update-message.md', 'update-message.md',
'delete-message.md', 'delete-message.md',
'get-message-history.md', 'get-message-history.md',
@ -111,3 +111,7 @@ To learn more about the test itself, see zerver/openapi/test_curl_examples.py.
curl_command=generated_curl_command, curl_command=generated_curl_command,
response=json.dumps(response, indent=4))) response=json.dumps(response, indent=4)))
raise raise
if REGISTERED_GENERATOR_FUNCTIONS != CALLED_GENERATOR_FUNCTIONS:
raise Exception("Some registered generator functions were not called:\n"
" " + str(REGISTERED_GENERATOR_FUNCTIONS - CALLED_GENERATOR_FUNCTIONS))

View File

@ -100,6 +100,8 @@ TEST_SUITE = False
TUTORIAL_ENABLED = True TUTORIAL_ENABLED = True
# This is overridden in test_settings.py for the test suites # This is overridden in test_settings.py for the test suites
CASPER_TESTS = False CASPER_TESTS = False
# This is overridden in test_settings.py for the test suites
RUNNING_OPENAPI_CURL_TEST = False
# Google Compute Engine has an /etc/boto.cfg that is "nicely # Google Compute Engine has an /etc/boto.cfg that is "nicely
# configured" to work with GCE's storage service. However, their # configured" to work with GCE's storage service. However, their

View File

@ -51,6 +51,9 @@ if "CASPER_TESTS" in os.environ:
# Disable search pills prototype for production use # Disable search pills prototype for production use
SEARCH_PILLS_ENABLED = False SEARCH_PILLS_ENABLED = False
if "RUNNING_OPENAPI_CURL_TEST" in os.environ:
RUNNING_OPENAPI_CURL_TEST = True
# Decrease the get_updates timeout to 1 second. # Decrease the get_updates timeout to 1 second.
# This allows CasperJS to proceed quickly to the next test step. # This allows CasperJS to proceed quickly to the next test step.
POLL_TIMEOUT = 1000 POLL_TIMEOUT = 1000