diff --git a/CHANGES/1015.misc b/CHANGES/1015.misc new file mode 100644 index 0000000000..8ec99a6166 --- /dev/null +++ b/CHANGES/1015.misc @@ -0,0 +1 @@ +Make functional test URL and PASSWORD customizable diff --git a/galaxy_ng/tests/functional/cli/test_namespace.py b/galaxy_ng/tests/functional/cli/test_namespace.py new file mode 100644 index 0000000000..c758e55640 --- /dev/null +++ b/galaxy_ng/tests/functional/cli/test_namespace.py @@ -0,0 +1,51 @@ +import string +import random + +from pulpcore.client.galaxy_ng.exceptions import ApiException +from galaxy_ng.tests.functional.utils import TestCaseUsingBindings +from galaxy_ng.tests.functional.utils import set_up_module as setUpModule # noqa:F401 + + +class CreateNamespaceTestCase(TestCaseUsingBindings): + """Test whether a namespace can be created.""" + + def delete_namespace(self, namespace_name): + # delete namespace + # namespace_api does not support delete, so we can use the smash_client directly + response = self.smash_client.delete( + f"{self.galaxy_api_prefix}/v3/namespaces/{namespace_name}" + ) + self.assertEqual(response.status_code, 204) + + def test_create_and_delete_namespace(self): + # generate name formed by 10 random ascii lowercase letters + random_name = ''.join(random.choices(string.ascii_lowercase, k=10)) + namespace_data = {"name": random_name, "groups": []} + + # create namespace + namespace = self.namespace_api.create(namespace=namespace_data) + self.assertEqual(namespace.name, random_name) + + # ensure namespace is available + namespaces = self.namespace_api.list(limit=100) + self.assertIn(namespace.name, [item.name for item in namespaces.data]) + + # delete namespace + self.delete_namespace(namespace.name) + + # ensure namespace is NO MORE available + namespaces = self.namespace_api.list(limit=100) + self.assertNotIn(namespace.name, [item.name for item in namespaces.data]) + + def test_negative_create_namespace_with_invalid_name(self): + # generate name formed by 10 random ascii lowercase letters + random_name = ''.join(random.choices(string.ascii_lowercase, k=10)) + random_name = f"ABC-{random_name}-$@" + namespace_data = {"name": random_name, "groups": []} + + # expect the namespace is not created because of invalid name + with self.assertRaises(ApiException) as context: + self.namespace_api.create(namespace=namespace_data) + + # Bad request + assert context.exception.status == 400 diff --git a/galaxy_ng/tests/functional/utils.py b/galaxy_ng/tests/functional/utils.py index 7c80f166d8..ff9d319cd3 100644 --- a/galaxy_ng/tests/functional/utils.py +++ b/galaxy_ng/tests/functional/utils.py @@ -1,4 +1,5 @@ """Utilities for tests for the galaxy plugin.""" +import os from functools import partial import requests from unittest import SkipTest @@ -28,7 +29,6 @@ from pulpcore.client.pulpcore import ( ApiClient as CoreApiClient, ArtifactsApi, - Configuration, TasksApi, ) from pulpcore.client.galaxy_ng import ( @@ -40,10 +40,7 @@ ) -configuration = Configuration() -configuration.username = "admin" -configuration.password = "password" -configuration.safe_chars_for_path_param = "/" +configuration = config.get_config().get_bindings_config() def set_up_module(): @@ -173,6 +170,7 @@ def setUpClass(cls): cls.sync_config_api = ApiContentV3SyncConfigApi(cls.client) cls.sync_api = ApiContentV3SyncApi(cls.client) cls.get_ansible_cfg_before_test() + cls.galaxy_api_prefix = os.getenv("PULP_GALAXY_API_PATH_PREFIX", "/api/galaxy").rstrip("/") def tearDown(self): """Clean class-wide variable.""" @@ -183,7 +181,7 @@ def tearDown(self): @classmethod def get_token(cls): """Get a Galaxy NG token.""" - return cls.smash_client.post("/api/galaxy/v3/auth/token/")["token"] + return cls.smash_client.post(f"{cls.galaxy_api_prefix}/v3/auth/token/")["token"] @classmethod def get_ansible_cfg_before_test(cls): @@ -200,7 +198,8 @@ def update_ansible_cfg(self, base_path): "server_list = community_repo\n" "\n" "[galaxy_server.community_repo]\n" - f"url={ self.cfg.get_content_host_base_url()}/api/galaxy/content/{base_path}/\n" + f"url={self.cfg.get_content_host_base_url()}" + f"{self.galaxy_api_prefix}/content/{base_path}/\n" f"token={token}" ) with open("ansible.cfg", "w") as f: