Skip to content

Commit

Permalink
Allow functional test configuration of URL and PASSWORD (#1026)
Browse files Browse the repository at this point in the history
Issue: AAH-1015
  • Loading branch information
rochacbruno authored Oct 15, 2021
1 parent ae13f9d commit ab38653
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES/1015.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make functional test URL and PASSWORD customizable
51 changes: 51 additions & 0 deletions galaxy_ng/tests/functional/cli/test_namespace.py
Original file line number Diff line number Diff line change
@@ -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
13 changes: 6 additions & 7 deletions galaxy_ng/tests/functional/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities for tests for the galaxy plugin."""
import os
from functools import partial
import requests
from unittest import SkipTest
Expand Down Expand Up @@ -28,7 +29,6 @@
from pulpcore.client.pulpcore import (
ApiClient as CoreApiClient,
ArtifactsApi,
Configuration,
TasksApi,
)
from pulpcore.client.galaxy_ng import (
Expand All @@ -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():
Expand Down Expand Up @@ -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."""
Expand All @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit ab38653

Please sign in to comment.