Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
zubenkoivan committed Dec 23, 2021
1 parent 7899195 commit 214e19e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
8 changes: 5 additions & 3 deletions neuro-sdk/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dataclasses import replace
from decimal import Decimal
from pathlib import Path
from typing import Callable, Dict, Optional
from typing import Any, Callable, Dict, Optional

import aiohttp
import aiohttp.pytest_plugin
Expand Down Expand Up @@ -102,8 +102,8 @@ def go(
trace_id: str = "bd7a977555f6b982",
clusters: Optional[Dict[str, Cluster]] = None,
token_url: Optional[URL] = None,
admin_url: Optional[URL] = None,
plugin_manager: Optional[PluginManager] = None,
**kwargs: Any,
) -> Client:
url = URL(url_str)
if clusters is None:
Expand Down Expand Up @@ -167,8 +167,10 @@ def go(
real_auth_config = replace(auth_config, token_url=token_url)
else:
real_auth_config = auth_config
if admin_url is None:
if "admin_url" not in kwargs:
admin_url = URL(url) / ".." / ".." / "apis" / "admin" / "v1"
else:
admin_url = kwargs["admin_url"]
if plugin_manager is None:
plugin_manager = PluginManager()
cluster_name = next(iter(clusters))
Expand Down
60 changes: 60 additions & 0 deletions neuro-sdk/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,66 @@ async def handler(request: web.Request) -> web.Response:
}


async def test_fetch_without_admin_url(
aiohttp_server: _TestServerFactory, make_client: _MakeClient
) -> None:
registry_url = "https://registry2-dev.neu.ro"
storage_url = "https://storage2-dev.neu.ro"
users_url = "https://users2-dev.neu.ro"
monitoring_url = "https://jobs2-dev.neu.ro"
secrets_url = "https://secrets2-dev.neu.ro"
disks_url = "https://disks2-dev.neu.ro"
buckets_url = "https://buckets2-dev.neu.ro"
auth_url = "https://dev-neuro.auth0.com/authorize"
token_url = "https://dev-neuro.auth0.com/oauth/token"
logout_url = "https://dev-neuro.auth0.com/v2/logout"
client_id = "this_is_client_id"
audience = "https://platform.dev.neu.ro."
headless_callback_url = "https://dev.neu.ro/oauth/show-code"
success_redirect_url = "https://platform.neu.ro"
JSON = {
"auth_url": auth_url,
"token_url": token_url,
"logout_url": logout_url,
"client_id": client_id,
"audience": audience,
"headless_callback_url": headless_callback_url,
"success_redirect_url": success_redirect_url,
"clusters": [
{
"name": "default",
"orgs": [None, "some-org"],
"registry_url": registry_url,
"storage_url": storage_url,
"users_url": users_url,
"monitoring_url": monitoring_url,
"secrets_url": secrets_url,
"disks_url": disks_url,
"buckets_url": buckets_url,
"resource_presets": [
{
"name": "cpu-small",
"credits_per_hour": "10",
"cpu": 2,
"memory_mb": 2 * 1024,
}
],
}
],
}

async def handler(request: web.Request) -> web.Response:
return web.json_response(JSON)

app = web.Application()
app.add_routes([web.get("/config", handler)])
srv = await aiohttp_server(app)

async with make_client(srv.make_url("/"), admin_url=None) as client:
await client.config.fetch()
assert client.config.admin_url is None


async def test_fetch_dropped_selected_cluster(
aiohttp_server: _TestServerFactory, make_client: _MakeClient
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion neuro-sdk/tests/test_config_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
__version__,
)
from neuro_sdk._config import _AuthConfig, _AuthToken, _ConfigData
from neuro_sdk._login import JWT_IDENTITY_CLAIM, JWT_STANDALONE_SECRET
from neuro_sdk._login import JWT_STANDALONE_SECRET

from tests import _TestServerFactory

Expand Down

0 comments on commit 214e19e

Please sign in to comment.