Skip to content

Commit

Permalink
Removed oAuth methods from collection docs. (ansible#15606)
Browse files Browse the repository at this point in the history
* Removed oAuth methods from collection docs.
  • Loading branch information
tvo318 authored Nov 7, 2024
1 parent f4cbb9f commit aa162c6
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 106 deletions.
53 changes: 0 additions & 53 deletions awx_collection/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,6 @@ When trying to fix a bug, it is best to replicate its behavior within a test wit

The unit tests are stored in the `test/awx` directory and, where possible, test interactions between the collections modules and the AWX database. This is achieved by using a Python testing suite and having a mocked layer which emulates interactions with the API. You do not need a server to run these unit tests. The depth of testing is not fixed and can change from module to module.

Let's take a closer look at the `test_token.py` file (which tests the `token` module):

```
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import pytest
from awx.main.models import OAuth2AccessToken
@pytest.mark.django_db
def test_create_token(run_module, admin_user):
module_args = {
'description': 'barfoo',
'state': 'present',
'scope': 'read',
'controller_host': None,
'controller_username': None,
'controller_password': None,
'validate_certs': None,
'controller_oauthtoken': None,
'controller_config_file': None,
}
result = run_module('token', module_args, admin_user)
assert result.get('changed'), result
tokens = OAuth2AccessToken.objects.filter(description='barfoo')
assert len(tokens) == 1, 'Tokens with description of barfoo != 0: {0}'.format(len(tokens))
assert tokens[0].scope == 'read', 'Token was not given read access'
```

This test has a single test called `test_create_token`. It creates a `module_args` section which is what will be passed into our module. We then call `run_module`, asking it to run the `token` module with the `module_args` we created and give us back the results. After that, we run an assertion to validate that our module did in fact report a change to the system. We will then use Python objects to look up the token that has a description of `barfoo` (which was in our arguments to the module). We want to validate that we only got back one token (the one we created) and that the scope of the token we created was read.


### Completion Test

Expand Down Expand Up @@ -93,22 +56,6 @@ While not strictly followed, the general flow of a test should be:
cred_name1: "AWX-Collection-tests-instance_group-cred1-{{ test_id }}"
```

- **Non-creating tests (i.e. test for specific error conditions, etc), with assertion**

```
- name: Try to use a token as a dict which is missing the token parameter
job_list:
controller_oauthtoken:
not_token: "This has no token entry"
register: results
ignore_errors: true
- assert:
that:
- results is failed
- '"The provided dict in controller_oauthtoken did not properly contain the token entry" == results.msg'
```

- **`Block:`**
- Run test which creates/modifies/deletes object(s)
```
Expand Down
30 changes: 0 additions & 30 deletions awx_collection/test/awx/test_token.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,8 @@ Non-deprecated modules in this collection have no Python requirements, but
may require the AWX CLI
in the future. The `DOCUMENTATION` for each module will report this.

You can specify authentication by a combination of either:
You can specify authentication by host, username, and password.

- host, username, password
- host, OAuth2 token

The OAuth2 token is the preferred method. You can obtain a token via the
``login`` command with the AWX CLI.

These can be specified via (from highest to lowest precedence):

- direct module parameters
- environment variables (most useful when running against localhost)
- a config file path specified by the `tower_config_file` parameter
- a config file at `~/.tower_cli.cfg`
- a config file at `/etc/tower/tower_cli.cfg`

Config file syntax looks like this:

```
[general]
host = https://localhost:8043
verify_ssl = true
oauth_token = LEdCpKVKc4znzffcpQL5vLG8oyeku6
```

## Release and Upgrade Notes

Expand Down

0 comments on commit aa162c6

Please sign in to comment.