|
| 1 | +from flask_parameter_validation.docs_blueprint import get_route_docs |
| 2 | + |
| 3 | +def test_http_ok(client): |
| 4 | + r = client.get("/docs/") |
| 5 | + assert r.status_code == 200 |
| 6 | + r = client.get("/docs/json") |
| 7 | + assert r.status_code == 200 |
| 8 | + |
| 9 | +def test_routes_added(app): |
| 10 | + routes = [] |
| 11 | + for rule in app.url_map.iter_rules(): |
| 12 | + routes.append(str(rule)) |
| 13 | + for doc in get_route_docs(): |
| 14 | + assert doc["rule"] in routes |
| 15 | + |
| 16 | +def test_doc_types_of_default(app): |
| 17 | + locs = { |
| 18 | + "form": "Form", |
| 19 | + "json": "Json", |
| 20 | + "query": "Query", |
| 21 | + "route": "Route" |
| 22 | + } |
| 23 | + types = { |
| 24 | + "bool": {"opt": "Optional[bool, NoneType]", "n_opt": "bool"}, |
| 25 | + "date": {"opt": "Optional[date, NoneType]", "n_opt": "date"}, |
| 26 | + "datetime": {"opt": "Optional[datetime, NoneType]", "n_opt": "datetime"}, |
| 27 | + "dict": {"opt": "Optional[dict, NoneType]", "n_opt": "dict"}, |
| 28 | + "float": {"opt": "Optional[float, NoneType]", "n_opt": "float"}, |
| 29 | + "int": {"opt": "Optional[int, NoneType]", "n_opt": "int"}, |
| 30 | + "int_enum": {"opt": "Optional[Binary, NoneType]", "n_opt": "Binary"}, |
| 31 | + "list": {"opt": "Optional[List[int], NoneType]", "n_opt": "List[str]"}, |
| 32 | + "str": {"opt": "Optional[str, NoneType]", "n_opt": "str"}, |
| 33 | + "str_enum": {"opt": "Optional[Fruits, NoneType]", "n_opt": "Fruits"}, |
| 34 | + "time": {"opt": "Optional[time, NoneType]", "n_opt": "time"}, |
| 35 | + "union": {"opt": "Union[bool, int, NoneType]", "n_opt": "Union[bool, int]"} |
| 36 | + } |
| 37 | + route_unsupported_types = ["dict", "list"] |
| 38 | + route_docs = get_route_docs() |
| 39 | + for loc in locs.keys(): |
| 40 | + for arg_type in types.keys(): |
| 41 | + if loc == "route" and arg_type in route_unsupported_types: |
| 42 | + continue |
| 43 | + route_to_check = f"/{loc}/{arg_type}/default" |
| 44 | + for doc in route_docs: |
| 45 | + if doc["rule"] == route_to_check: |
| 46 | + args = doc["args"][locs[loc]] |
| 47 | + if args[0]["name"] == "n_opt": |
| 48 | + n_opt = args[0] |
| 49 | + opt = args[1] |
| 50 | + else: |
| 51 | + opt = args[0] |
| 52 | + n_opt = args[1] |
| 53 | + assert n_opt["type"] == types[arg_type]["n_opt"] |
| 54 | + assert opt["type"] == types[arg_type]["opt"] |
0 commit comments