diff --git a/scaleway-async/tests/test_registry_v1.py b/scaleway-async/tests/test_registry_v1.py deleted file mode 100644 index 1562ca0c5..000000000 --- a/scaleway-async/tests/test_registry_v1.py +++ /dev/null @@ -1,128 +0,0 @@ -import unittest -from contextlib import AsyncExitStack - -import utils - -from scaleway_async import Client -from scaleway_async.registry.v1 import NamespaceStatus, RegistryV1API -from scaleway_core.utils.waiter import WaitForOptions - - -class TestRegistryV1(unittest.IsolatedAsyncioTestCase): - def setUp(self) -> None: - client = Client.from_config_file_and_env() - self.api = RegistryV1API(client) - - async def test_create_namespace(self) -> None: - name = utils.random_name() - - async with AsyncExitStack() as stack: - namespace = await self.api.create_namespace( - name=name, - description="test", - is_public=False, - ) - stack.push_async_callback( - self.api.delete_namespace, namespace_id=namespace.id - ) - - await self.api.wait_for_namespace( - namespace_id=namespace.id, - options=WaitForOptions( - stop=lambda x: x.status == NamespaceStatus.READY - ), - ) - - self.assertEqual(namespace.name, name) - - async def test_list_namespaces(self) -> None: - namespaces = await self.api.list_namespaces() - self.assertTrue(type(namespaces.namespaces) is list) - - async def test_list_namespaces_all(self) -> None: - namespaces = await self.api.list_namespaces_all() - self.assertTrue(type(namespaces) is list) - - async def test_get_namespace(self) -> None: - name = utils.random_name() - - async with AsyncExitStack() as stack: - namespace = await self.api.create_namespace( - name=name, - description="test", - is_public=False, - ) - stack.push_async_callback( - self.api.delete_namespace, namespace_id=namespace.id - ) - - await self.api.wait_for_namespace( - namespace_id=namespace.id, - options=WaitForOptions( - stop=lambda x: x.status == NamespaceStatus.READY - ), - ) - - namespace2 = await self.api.get_namespace(namespace_id=namespace.id) - self.assertEqual(namespace.id, namespace2.id) - - async def test_update_namespace(self) -> None: - name = utils.random_name() - - async with AsyncExitStack() as stack: - namespace = await self.api.create_namespace( - name=name, - description="test", - is_public=False, - ) - stack.push_async_callback( - self.api.delete_namespace, namespace_id=namespace.id - ) - - await self.api.wait_for_namespace( - namespace_id=namespace.id, - options=WaitForOptions( - stop=lambda x: x.status == NamespaceStatus.READY - ), - ) - - namespace2 = await self.api.update_namespace( - namespace_id=namespace.id, - description="test2", - is_public=True, - ) - - self.assertEqual(namespace.id, namespace2.id) - self.assertEqual(namespace2.description, "test2") - self.assertEqual(namespace2.is_public, True) - - async def test_delete_namespace(self) -> None: - name = utils.random_name() - - async with AsyncExitStack() as stack: - namespace = await self.api.create_namespace( - name=name, - description="test", - is_public=False, - ) - stack.push_async_callback( - self.api.delete_namespace, namespace_id=namespace.id - ) - - await self.api.wait_for_namespace( - namespace_id=namespace.id, - options=WaitForOptions( - stop=lambda x: x.status == NamespaceStatus.READY - ), - ) - - try: - await self.api.wait_for_namespace( - namespace_id=namespace.id, - options=WaitForOptions( - stop=lambda x: x.status == NamespaceStatus.DELETING - ), - ) - except Exception as e: - self.assertNotIsInstance(e, TimeoutError) - pass diff --git a/scaleway-async/tests/test_test_v1.py b/scaleway-async/tests/test_test_v1.py new file mode 100644 index 000000000..f86c28248 --- /dev/null +++ b/scaleway-async/tests/test_test_v1.py @@ -0,0 +1,147 @@ +import unittest +from contextlib import AsyncExitStack +from typing import Optional + +import utils + +from scaleway_async import Client, WaitForOptions +from scaleway_async.test.v1 import EyeColors, Human, HumanStatus, TestV1API + + +class TestTestV1(unittest.IsolatedAsyncioTestCase): + async def asyncSetUp(self) -> None: + client = Client.from_config_file_and_env() + self.api = TestV1API(client, bypass_validation=True) + + res = await self.api.register(username="scaleway-sdk-python") + client.access_key = res.access_key + client.secret_key = res.secret_key + + async def test_create_human(self) -> None: + name = utils.random_name() + + async with AsyncExitStack() as stack: + human = await self.api.create_human( + height=1.0, + shoe_size=1.0, + altitude_in_meter=1, + altitude_in_millimeter=1, + fingers_count=1, + hair_count=1, + is_happy=True, + eyes_color=EyeColors.BROWN, + name=name, + ) + stack.push_async_callback(self.api.delete_human, human_id=human.id) + + self.assertEqual(human.name, name) + + async def test_list_humans(self) -> None: + humans = await self.api.list_humans() + self.assertTrue(type(humans.humans) is list) + + async def test_list_humans_all(self) -> None: + humans = await self.api.list_humans_all() + self.assertTrue(type(humans) is list) + + async def test_get_human(self) -> None: + name = utils.random_name() + + async with AsyncExitStack() as stack: + human = await self.api.create_human( + height=1.0, + shoe_size=1.0, + altitude_in_meter=1, + altitude_in_millimeter=1, + fingers_count=1, + hair_count=1, + is_happy=True, + eyes_color=EyeColors.BROWN, + name=name, + ) + stack.push_async_callback(self.api.delete_human, human_id=human.id) + + human2 = await self.api.get_human(human_id=human.id) + self.assertEqual(human.id, human2.id) + + async def test_update_human(self) -> None: + name = utils.random_name() + + async with AsyncExitStack() as stack: + human = await self.api.create_human( + height=1.0, + shoe_size=1.0, + altitude_in_meter=1, + altitude_in_millimeter=1, + fingers_count=1, + hair_count=1, + is_happy=True, + eyes_color=EyeColors.BROWN, + name=name, + ) + stack.push_async_callback(self.api.delete_human, human_id=human.id) + + human2 = await self.api.update_human( + human_id=human.id, + height=2.0, + eyes_color=EyeColors.BLUE, + ) + + self.assertEqual(human.id, human2.id) + self.assertEqual(human2.height, 2.0) + self.assertEqual(human2.eyes_color, EyeColors.BLUE) + + async def test_delete_human(self) -> None: + name = utils.random_name() + + human: Optional[Human] = None + + async with AsyncExitStack() as stack: + human = await self.api.create_human( + height=1.0, + shoe_size=1.0, + altitude_in_meter=1, + altitude_in_millimeter=1, + fingers_count=1, + hair_count=1, + is_happy=True, + eyes_color=EyeColors.BROWN, + name=name, + ) + stack.push_async_callback(self.api.delete_human, human_id=human.id) + + if human is None: + raise Exception("human is None") + + try: + await self.api.wait_for_human(human_id=human.id) + except Exception as e: + self.assertNotIsInstance(e, TimeoutError) + pass + + async def test_run_human(self): + name = utils.random_name() + + async with AsyncExitStack() as stack: + human = await self.api.create_human( + height=1.0, + shoe_size=1.0, + altitude_in_meter=1, + altitude_in_millimeter=1, + fingers_count=1, + hair_count=1, + is_happy=True, + eyes_color=EyeColors.BROWN, + name=name, + ) + stack.push_async_callback(self.api.delete_human, human_id=human.id) + + await self.api.run_human(human_id=human.id) + human = await self.api.wait_for_human( + human_id=human.id, + options=WaitForOptions( + stop=lambda human: human.status == HumanStatus.RUNNING + ), + ) + + self.assertEqual(human.status, HumanStatus.RUNNING) diff --git a/scaleway-core/scaleway_core/api.py b/scaleway-core/scaleway_core/api.py index 4091b1c1b..06704ae19 100644 --- a/scaleway-core/scaleway_core/api.py +++ b/scaleway-core/scaleway_core/api.py @@ -103,8 +103,10 @@ class ValidationError(ScalewayException): class API: - def __init__(self, client: Client): - client.validate() + def __init__(self, client: Client, *, bypass_validation: bool = False): + if not bypass_validation: + client.validate() + self.client = client self._log = logging.getLogger(__name__) diff --git a/scaleway/tests/test_registry_v1.py b/scaleway/tests/test_registry_v1.py deleted file mode 100644 index 244466828..000000000 --- a/scaleway/tests/test_registry_v1.py +++ /dev/null @@ -1,123 +0,0 @@ -import unittest -from contextlib import ExitStack -from typing import Optional - -import utils - -from scaleway import Client -from scaleway_core.utils.waiter import WaitForOptions -from scaleway.registry.v1 import Namespace, NamespaceStatus, RegistryV1API - - -class TestRegistryV1(unittest.TestCase): - def setUp(self) -> None: - client = Client.from_config_file_and_env() - self.api = RegistryV1API(client) - - def test_create_namespace(self) -> None: - name = utils.random_name() - - with ExitStack() as stack: - namespace = self.api.create_namespace( - name=name, - description="test", - is_public=False, - ) - stack.callback(self.api.delete_namespace, namespace_id=namespace.id) - - self.api.wait_for_namespace( - namespace_id=namespace.id, - options=WaitForOptions( - stop=lambda x: x.status == NamespaceStatus.READY - ), - ) - - self.assertEqual(namespace.name, name) - - def test_list_namespaces(self) -> None: - namespaces = self.api.list_namespaces() - self.assertTrue(type(namespaces.namespaces) is list) - - def test_list_namespaces_all(self) -> None: - namespaces = self.api.list_namespaces_all() - self.assertTrue(type(namespaces) is list) - - def test_get_namespace(self) -> None: - name = utils.random_name() - - with ExitStack() as stack: - namespace = self.api.create_namespace( - name=name, - description="test", - is_public=False, - ) - stack.callback(self.api.delete_namespace, namespace_id=namespace.id) - - self.api.wait_for_namespace( - namespace_id=namespace.id, - options=WaitForOptions( - stop=lambda x: x.status == NamespaceStatus.READY - ), - ) - - namespace2 = self.api.get_namespace(namespace_id=namespace.id) - self.assertEqual(namespace.id, namespace2.id) - - def test_update_namespace(self) -> None: - name = utils.random_name() - - with ExitStack() as stack: - namespace = self.api.create_namespace( - name=name, - description="test", - is_public=False, - ) - stack.callback(self.api.delete_namespace, namespace_id=namespace.id) - - self.api.wait_for_namespace( - namespace_id=namespace.id, - options=WaitForOptions( - stop=lambda x: x.status == NamespaceStatus.READY - ), - ) - - namespace2 = self.api.update_namespace( - namespace_id=namespace.id, - description="test2", - is_public=True, - ) - - self.assertEqual(namespace.id, namespace2.id) - self.assertEqual(namespace2.description, "test2") - self.assertEqual(namespace2.is_public, True) - - def test_delete_namespace(self) -> None: - name = utils.random_name() - - namespace: Optional[Namespace] = None - - with ExitStack() as stack: - namespace = self.api.create_namespace( - name=name, - description="test", - is_public=False, - ) - stack.callback(self.api.delete_namespace, namespace_id=namespace.id) - - self.api.wait_for_namespace( - namespace_id=namespace.id, - options=WaitForOptions( - stop=lambda x: x.status == NamespaceStatus.READY - ), - ) - - try: - self.api.wait_for_namespace( - namespace_id=namespace.id, - options=WaitForOptions( - stop=lambda x: x.status == NamespaceStatus.DELETING - ), - ) - except Exception as e: - self.assertNotIsInstance(e, TimeoutError) - pass diff --git a/scaleway/tests/test_test_v1.py b/scaleway/tests/test_test_v1.py new file mode 100644 index 000000000..531e6aa0f --- /dev/null +++ b/scaleway/tests/test_test_v1.py @@ -0,0 +1,147 @@ +import unittest +from contextlib import ExitStack +from typing import Optional + +import utils + +from scaleway import Client, WaitForOptions +from scaleway.test.v1 import EyeColors, Human, HumanStatus, TestV1API + + +class TestTestV1(unittest.TestCase): + def setUp(self) -> None: + client = Client.from_config_file_and_env() + self.api = TestV1API(client, bypass_validation=True) + + res = self.api.register(username="scaleway-sdk-python") + client.access_key = res.access_key + client.secret_key = res.secret_key + + def test_create_human(self) -> None: + name = utils.random_name() + + with ExitStack() as stack: + human = self.api.create_human( + height=1.0, + shoe_size=1.0, + altitude_in_meter=1, + altitude_in_millimeter=1, + fingers_count=1, + hair_count=1, + is_happy=True, + eyes_color=EyeColors.BROWN, + name=name, + ) + stack.callback(self.api.delete_human, human_id=human.id) + + self.assertEqual(human.name, name) + + def test_list_humans(self) -> None: + humans = self.api.list_humans() + self.assertTrue(type(humans.humans) is list) + + def test_list_humans_all(self) -> None: + humans = self.api.list_humans_all() + self.assertTrue(type(humans) is list) + + def test_get_human(self) -> None: + name = utils.random_name() + + with ExitStack() as stack: + human = self.api.create_human( + height=1.0, + shoe_size=1.0, + altitude_in_meter=1, + altitude_in_millimeter=1, + fingers_count=1, + hair_count=1, + is_happy=True, + eyes_color=EyeColors.BROWN, + name=name, + ) + stack.callback(self.api.delete_human, human_id=human.id) + + human2 = self.api.get_human(human_id=human.id) + self.assertEqual(human.id, human2.id) + + def test_update_human(self) -> None: + name = utils.random_name() + + with ExitStack() as stack: + human = self.api.create_human( + height=1.0, + shoe_size=1.0, + altitude_in_meter=1, + altitude_in_millimeter=1, + fingers_count=1, + hair_count=1, + is_happy=True, + eyes_color=EyeColors.BROWN, + name=name, + ) + stack.callback(self.api.delete_human, human_id=human.id) + + human2 = self.api.update_human( + human_id=human.id, + height=2.0, + eyes_color=EyeColors.BLUE, + ) + + self.assertEqual(human.id, human2.id) + self.assertEqual(human2.height, 2.0) + self.assertEqual(human2.eyes_color, EyeColors.BLUE) + + def test_delete_human(self) -> None: + name = utils.random_name() + + human: Optional[Human] = None + + with ExitStack() as stack: + human = self.api.create_human( + height=1.0, + shoe_size=1.0, + altitude_in_meter=1, + altitude_in_millimeter=1, + fingers_count=1, + hair_count=1, + is_happy=True, + eyes_color=EyeColors.BROWN, + name=name, + ) + stack.callback(self.api.delete_human, human_id=human.id) + + if human is None: + raise Exception("human is None") + + try: + self.api.wait_for_human(human_id=human.id) + except Exception as e: + self.assertNotIsInstance(e, TimeoutError) + pass + + def test_run_human(self): + name = utils.random_name() + + with ExitStack() as stack: + human = self.api.create_human( + height=1.0, + shoe_size=1.0, + altitude_in_meter=1, + altitude_in_millimeter=1, + fingers_count=1, + hair_count=1, + is_happy=True, + eyes_color=EyeColors.BROWN, + name=name, + ) + stack.callback(self.api.delete_human, human_id=human.id) + + self.api.run_human(human_id=human.id) + human = self.api.wait_for_human( + human_id=human.id, + options=WaitForOptions( + stop=lambda human: human.status == HumanStatus.RUNNING + ), + ) + + self.assertEqual(human.status, HumanStatus.RUNNING)