-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update AWX collection to use basic authentication #15554
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
import os | ||
from unittest import mock | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In pytest, it's customary to use the built-in |
||
|
||
__metaclass__ = type | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a matrix of repeated things. It is possible to produce it using several stacked parametrize decorators. |
||
"collection_type, env_prefix, controller_host, app_key, endpoint, expected", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pro tip: this can be an interable of strings which typically reads better. |
||
[ | ||
# without CONTROLLER_OPTIONAL_API_URLPATTERN_PREFIX env variable | ||
["awx", None, "https://localhost:8043", None, "jobs", "https://localhost:8043/api/v2/jobs/"], | ||
["awx", None, "https://localhost:8043", None, "jobs/209", "https://localhost:8043/api/v2/jobs/209/"], | ||
["awx", None, "https://localhost:8043", None, "organizations", "https://localhost:8043/api/v2/organizations/"], | ||
["awx", None, "https://localhost", "controller", "jobs", "https://localhost/api/controller/v2/jobs/"], | ||
["awx", None, "https://localhost", "controller", "jobs/1", "https://localhost/api/controller/v2/jobs/1/"], | ||
["awx", None, "https://localhost", "gateway", "tokens", "https://localhost/api/gateway/v1/tokens/"], | ||
["awx", None, "https://localhost", "gateway", "tokens/199", "https://localhost/api/gateway/v1/tokens/199/"], | ||
["controller", None, "https://localhost", None, "jobs", "https://localhost/api/controller/v2/jobs/"], | ||
["controller", None, "https://localhost", None, "jobs/209", "https://localhost/api/controller/v2/jobs/209/"], | ||
["controller", None, "https://localhost", None, "organizations", "https://localhost/api/controller/v2/organizations/"], | ||
["controller", None, "https://localhost", "controller", "jobs", "https://localhost/api/controller/v2/jobs/"], | ||
["controller", None, "https://localhost", "controller", "jobs/1", "https://localhost/api/controller/v2/jobs/1/"], | ||
["controller", None, "https://localhost", "gateway", "tokens", "https://localhost/api/gateway/v1/tokens/"], | ||
["controller", None, "https://localhost", "gateway", "tokens/199", "https://localhost/api/gateway/v1/tokens/199/"], | ||
# with CONTROLLER_OPTIONAL_API_URLPATTERN_PREFIX env variable | ||
["awx", "api/controller", "https://localhost", None, "jobs", "https://localhost/api/controller/v2/jobs/"], | ||
["awx", "api/controller", "https://localhost", None, "jobs/209", "https://localhost/api/controller/v2/jobs/209/"], | ||
["awx", "api/controller", "https://localhost", None, "organizations", "https://localhost/api/controller/v2/organizations/"], | ||
["awx", "api/controller", "https://localhost", "controller", "jobs", "https://localhost/api/controller/v2/jobs/"], | ||
["awx", "api/controller", "https://localhost", "controller", "jobs/1", "https://localhost/api/controller/v2/jobs/1/"], | ||
["awx", "api/controller", "https://localhost", "gateway", "tokens", "https://localhost/api/gateway/v1/tokens/"], | ||
["awx", "api/controller", "https://localhost", "gateway", "tokens/199", "https://localhost/api/gateway/v1/tokens/199/"], | ||
["controller", "api/controller", "https://localhost", None, "jobs", "https://localhost/api/controller/v2/jobs/"], | ||
["controller", "api/controller", "https://localhost", None, "jobs/209", "https://localhost/api/controller/v2/jobs/209/"], | ||
["controller", "api/controller", "https://localhost", "controller", "jobs", "https://localhost/api/controller/v2/jobs/"], | ||
["controller", "api/controller", "https://localhost", "controller", "jobs/1", "https://localhost/api/controller/v2/jobs/1/"], | ||
["controller", "api/controller", "https://localhost", "gateway", "tokens", "https://localhost/api/gateway/v1/tokens/"], | ||
["controller", "api/controller", "https://localhost", "gateway", "tokens/199", "https://localhost/api/gateway/v1/tokens/199/"], | ||
] | ||
) | ||
def test_controller_api_build_url(collection_import, collection_type, env_prefix, controller_host, app_key, endpoint, expected): | ||
controller_api_class = collection_import('plugins.module_utils.controller_api').ControllerAPIModule | ||
controller_api = controller_api_class(argument_spec={}, direct_params=dict(controller_host=controller_host)) | ||
controller_api._COLLECTION_TYPE = collection_type | ||
if env_prefix: | ||
with mock.patch.dict(os.environ, {"CONTROLLER_OPTIONAL_API_URLPATTERN_PREFIX": env_prefix}): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For conditional CM, there's a |
||
request_url = controller_api.build_url(endpoint, app_key=app_key).geturl() | ||
else: | ||
request_url = controller_api.build_url(endpoint, app_key=app_key).geturl() | ||
|
||
assert request_url == expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this future import is only useful under python 2