From 214e19e6b6d330b830edf08a0e7538280ab6afc7 Mon Sep 17 00:00:00 2001 From: Ivan Zubenko Date: Thu, 23 Dec 2021 11:20:54 +0200 Subject: [PATCH] add test --- neuro-sdk/tests/conftest.py | 8 ++-- neuro-sdk/tests/test_config.py | 60 ++++++++++++++++++++++++++ neuro-sdk/tests/test_config_factory.py | 2 +- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/neuro-sdk/tests/conftest.py b/neuro-sdk/tests/conftest.py index 29806b054..4e60a485d 100644 --- a/neuro-sdk/tests/conftest.py +++ b/neuro-sdk/tests/conftest.py @@ -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 @@ -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: @@ -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)) diff --git a/neuro-sdk/tests/test_config.py b/neuro-sdk/tests/test_config.py index cd4e75176..4f0c90ef5 100644 --- a/neuro-sdk/tests/test_config.py +++ b/neuro-sdk/tests/test_config.py @@ -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: diff --git a/neuro-sdk/tests/test_config_factory.py b/neuro-sdk/tests/test_config_factory.py index 33ae35814..4b60dc0ee 100644 --- a/neuro-sdk/tests/test_config_factory.py +++ b/neuro-sdk/tests/test_config_factory.py @@ -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