mirror of https://github.com/zulip/zulip.git
tests: Remove get-raw-message from curl test exclude_list.
This commit is contained in:
parent
722f3a6cfe
commit
8e9ccdf376
|
@ -3,6 +3,8 @@ import argparse
|
|||
import os
|
||||
import sys
|
||||
|
||||
os.environ["RUNNING_OPENAPI_CURL_TEST"] = "1"
|
||||
|
||||
# check for the venv
|
||||
from lib import sanity_check
|
||||
sanity_check.check_venv(__file__)
|
||||
|
|
|
@ -2,6 +2,8 @@ import re
|
|||
import json
|
||||
import inspect
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from markdown.extensions import Extension
|
||||
from markdown.preprocessors import Preprocessor
|
||||
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_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 = {}
|
||||
for param in openapi_params:
|
||||
if param["in"] != "path":
|
||||
|
|
|
@ -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")
|
||||
}
|
|
@ -8,12 +8,12 @@ import os
|
|||
from zulip import Client
|
||||
from zerver.lib.bugdown import api_code_examples
|
||||
from zerver.models import get_realm
|
||||
from zerver.openapi.curl_param_value_generators import REGISTERED_GENERATOR_FUNCTIONS, CALLED_GENERATOR_FUNCTIONS
|
||||
|
||||
exclude_list = [
|
||||
# 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
|
||||
# state of the DB. This results in the curl request to fail.
|
||||
'get-raw-message.md',
|
||||
'update-message.md',
|
||||
'delete-message.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,
|
||||
response=json.dumps(response, indent=4)))
|
||||
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))
|
||||
|
|
|
@ -100,6 +100,8 @@ TEST_SUITE = False
|
|||
TUTORIAL_ENABLED = True
|
||||
# This is overridden in test_settings.py for the test suites
|
||||
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
|
||||
# configured" to work with GCE's storage service. However, their
|
||||
|
|
|
@ -51,6 +51,9 @@ if "CASPER_TESTS" in os.environ:
|
|||
# Disable search pills prototype for production use
|
||||
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.
|
||||
# This allows CasperJS to proceed quickly to the next test step.
|
||||
POLL_TIMEOUT = 1000
|
||||
|
|
Loading…
Reference in New Issue