aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/test_http_api_doc.py
blob: 5568e635b37f4db9ce30797c8548ae64f044d82e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
docs/MESHBAY_HTTP_API.md is generated from the routes of the hub and of the
node's control API. A route added, removed or redescribed without running
`python docs/generate_http_api.py` fails here.
"""

import importlib.util
from pathlib import Path

GENERATOR = Path(__file__).resolve().parents[3] / "docs" / "generate_http_api.py"


def _generator():
    spec = importlib.util.spec_from_file_location("generate_http_api", GENERATOR)
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    return module


def test_the_api_listing_matches_the_routes():
    gen = _generator()
    assert gen.OUT.read_text(encoding="utf-8") == gen.render(), (
        "docs/MESHBAY_HTTP_API.md is out of date: run python docs/generate_http_api.py")


def test_every_route_says_what_it_does():
    gen = _generator()
    bare = [f"{gen.method(r)} {r.path}" for r in gen.hub_routes() + gen.node_routes()
            if not gen.summary(r)]
    assert not bare, f"give these routes a docstring, it is their line in the listing: {bare}"