Skip to content

Commit

Permalink
client: add PrivateSubnet hosts to VALID_URLS (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume authored Mar 4, 2022
1 parent 1597dd9 commit 3ba3466
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mpcontribs-client/mpcontribs/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@
COMPONENTS = ["structures", "tables", "attachments"] # using list to maintain order
SUBDOMAINS = ["contribs", "lightsources", "ml", "workshop-contribs"]
PORTS = [5000, 5002, 5003, 5005, 10000, 10002, 10003, 10005]
VALID_URLS = {f"http://{h}:{p}" for p in PORTS for h in ["localhost", "contribs-apis"]}
HOSTS = ["localhost", "contribs-apis"]
HOSTS += [f"192.168.0.{i}" for i in range(36, 47)] # PrivateSubnetOne
HOSTS += [f"192.168.0.{i}" for i in range(52, 63)] # PrivateSubnetTwo
VALID_URLS = {f"http://{h}:{p}" for p in PORTS for h in HOSTS}
VALID_URLS |= {
f"https://{n}-api{m}.materialsproject.org"
for n in SUBDOMAINS for m in ["", "-preview"]
Expand Down
9 changes: 9 additions & 0 deletions mpcontribs-client/mpcontribs/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def test_mock():
assert spec.spec_dict["schemes"] == ["http"]
assert spec.user_defined_formats["email"] == email_format

host = "192.168.0.40:10000"
with Client(host=host) as client:
spec = client.swagger_spec
assert spec.http_client.headers == {"Content-Type": "application/json"}
assert spec.origin_url == f"http://{host}/apispec.json"
assert spec.spec_dict["host"] == host
assert spec.spec_dict["schemes"] == ["http"]
assert spec.user_defined_formats["email"] == email_format

with pytest.raises(ValueError):
with Client(host="not.valid.org") as client:
spec = client.swagger_spec
Expand Down

0 comments on commit 3ba3466

Please sign in to comment.