MCPcopy Create free account
hub / github.com/Materials-Consortia/optimade-python-tools / inner

Function inner

tests/server/conftest.py:74–117  ·  view source on GitHub ↗
(
        request: str,
        server: str | OptimadeTestClient = "regular",
        return_json: bool = True,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

72 from .utils import OptimadeTestClient
73
74 def inner(
75 request: str,
76 server: str | OptimadeTestClient = "regular",
77 return_json: bool = True,
78 **kwargs,
79 ) -> dict | Response:
80 if isinstance(server, str):
81 if server == "regular":
82 used_client = client
83 elif server == "index":
84 used_client = index_client
85 else:
86 pytest.fail(
87 f"Wrong value for 'server': {server}. It must be either 'regular' or 'index'."
88 )
89 elif isinstance(server, OptimadeTestClient):
90 used_client = server
91 else:
92 pytest.fail("'server' must be either a string or an OptimadeTestClient.")
93 try:
94 response = used_client.get(request, **kwargs)
95 response_json = response.json()
96 assert response.status_code == 200, f"Request failed: {response_json}"
97 expected_mime_type = "application/vnd.api+json"
98 assert response.headers["content-type"] == expected_mime_type, (
99 f"Response should have MIME type {expected_mime_type!r}, not {response.headers['content-type']!r}."
100 )
101 except json.JSONDecodeError:
102 print(
103 f"Request attempted:\n{used_client.base_url}{used_client.version}"
104 f"{request}\n"
105 "Could not successfully decode response as JSON."
106 )
107 raise
108 except Exception as exc:
109 print(
110 f"Request attempted:\n{used_client.base_url}{used_client.version}"
111 f"{request}"
112 )
113 raise exc
114 else:
115 if return_json:
116 return response_json
117 return response
118
119 return inner
120

Callers

nothing calls this directly

Calls 3

get_good_responseFunction · 0.85
getMethod · 0.45
jsonMethod · 0.45

Tested by

no test coverage detected