about summary refs log tree commit diff
path: root/test/python/test_openapi.py
blob: f4813c3ee231ba9ef9d981be973af00ba0c36f1b (plain)
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
31
32
33
34
35
"""Mirrors tests/openapi.rs."""

import http.client
import json
import unittest

from server_test_case import HOST, PORT, ServerTestCase


class OpenApiTest(ServerTestCase):
    def test_openapi_json_describes_all_endpoints(self):
        conn = http.client.HTTPConnection(HOST, int(PORT), timeout=5)
        try:
            conn.request("GET", "/openapi.json")
            response = conn.getresponse()
            body = response.read()
        finally:
            conn.close()
        self.assertEqual(response.status, 200)

        doc = json.loads(body)
        self.assertEqual(doc["info"]["title"], "GeneNetwork4 API")
        for path in (
            "/",
            "/version",
            "/species",
            "/species/{species}",
            "/groups",
            "/groups/{group}",
        ):
            self.assertIn(path, doc["paths"])


if __name__ == "__main__":
    unittest.main()