Skip to content

Commit

Permalink
Allow updating auth_url on CollectionRemote when token is already set
Browse files Browse the repository at this point in the history
https://pulp.plan.io/issues/7957
closes #7957

(cherry picked from commit 21b0777)
  • Loading branch information
fao89 committed Jan 15, 2021
1 parent f7a9bac commit 8f8fd43
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/7957.bugfix
@@ -0,0 +1 @@
Allow updating ``auth_url`` on CollectionRemote when ``token``is already set
3 changes: 2 additions & 1 deletion pulp_ansible/app/serializers.py
Expand Up @@ -151,7 +151,8 @@ def _validate_url(url):
if collection[2]:
_validate_url(collection[2])

if "auth_url" in data and "token" not in data:
has_token = "token" in data or getattr(self.instance, "token", False)
if data.get("auth_url") and not has_token:
raise serializers.ValidationError(
_("When specifying 'auth_url' you must also specify 'token'.")
)
Expand Down
17 changes: 17 additions & 0 deletions pulp_ansible/tests/functional/api/collection/test_remote.py
@@ -1,5 +1,6 @@
"""Tests related to CollectionRemote objects."""
from pulpcore.client.pulp_ansible.exceptions import ApiException
from pulp_smash.pulp3.bindings import monitor_task

from pulp_ansible.tests.functional.utils import gen_ansible_remote, TestCaseUsingBindings
from pulp_ansible.tests.functional.utils import set_up_module as setUpModule # noqa:F401
Expand All @@ -20,6 +21,22 @@ def test_token_only_is_allowed(self):
remote = self.remote_collection_api.create(body)
self.addCleanup(self.remote_collection_api.delete, remote.pulp_href)

def test_update_auth_url(self):
"""Assert that a `CollectionRemote` with `token` and no `auth_url` can be created."""
body = gen_ansible_remote(
url="https://example.com/",
token="this is a token string",
auth_url="https://example.com",
)
remote = self.remote_collection_api.create(body)
response = self.remote_collection_api.partial_update(remote.pulp_href, {"auth_url": None})
monitor_task(response.task)
response = self.remote_collection_api.partial_update(
remote.pulp_href, {"auth_url": "https://example.com"}
)
monitor_task(response.task)
self.addCleanup(self.remote_collection_api.delete, remote.pulp_href)

def test_auth_url_requires_token(self):
"""Assert that a `CollectionRemote` with `auth_url` and no `token` can't be created."""
body = gen_ansible_remote(url="https://example.com/", auth_url="https://example.com")
Expand Down

0 comments on commit 8f8fd43

Please sign in to comment.