Skip to content
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

Introduce pulp_smash.api.Client #65

Merged
merged 7 commits into from
Jan 11, 2016
Merged

Introduce pulp_smash.api.Client #65

merged 7 commits into from
Jan 11, 2016

Conversation

Ichimonji10
Copy link
Contributor

Partially address #64. Introduce, document and partially unit test a new class, pulp_smash.api.Client. This series of commits reworks the following modules:

  • pulp_smash.tests.platform.api_v2.test_user
  • pulp_smash.tests.platform.api_v2.test_login
  • pulp_smash.tests.platform.api_v2.test_content_applicability
  • pulp_smash.tests.platform.api_v2.test_search

Also move functions for selecting and deselecting tests (such as @require) to pulp_smash.selectors.

Create module `pulp_smash.selectors`. This module contains "tools for selecting
and deselecting tests." Update the documentation, and update all references to
these functions from unit tests and functional tests. Test suite results do not
change:

    ============  =============================
    Pulp Version  Test Suite Results
    ============  =============================
    2.7           OK (skipped=14)
    dev (2.8)     FAILED (errors=2, skipped=13)
    ============  =============================
Add, document, and partially unit test a new module, `pulp_smash.api`. This
module includes an API client, `Client`, and several associated callback
functions that can be used by `Client` for handling server responses.

Why add this new API client? As an example, here is an example of how to use a
helper function from `pulp_smash.api.Client`:

```python
from pulp_smash import config, utils
user = utils.create_user(config.get_config(), {'login': utils.uuid4()})
```

This works, but it falls apart as soon as any measure of flexibility is needed.
One issue is that response handling is hard-coded. If you want to purposefully
make an invalid request to create a user (handy for testing!), this will raise
an exception. Your only recourse in this case is to call a Requests function
directly:

```python
import requests
from pulp_smash import config, constants, utils
cfg = config.get_config()
response = requests.post(
    cfg.base_url + constants.USER_PATH,  # urljoin() should be used
    {'llooggiinn': utils.uuid4()},
    **cfg.get_requests_kwargs()
)
```

Another issue is that capturing raw responses with the third function parameter
is kludgy:

```python
from pulp_smash import config, utils
responses = []
user = utils.create_user(
    config.get_config,
    {'login': utils.uuid4()},
    responses,
)

The new `pulp_smash.api.Client` class should help solve these issues. Here are
some examples of how to use it:

```python
from pulp_smash import api, config, constants, utils
client = api.Client(config.get_config(), response_handler=api.json_handler)
user = client.post(constants.USER_PATH, {'login': utils.uuid4()})
client.response_handler = api.echo_handler
response = client.post(constants.USER_PATH, {'llooggiinn': utils.uuid4()})
client.response_handler = api.safe_handler
response = client.post(constants.USER_PATH, {'login': utils.uuid4()})
```

See `pulp_smash.api.Client` for further documentation on the class. See commits
to be added in the near future for more examples of how to use the class.
Refactor module `pulp_smash.tests.platform.api_v2.test_user`. Make this module
use the new `pulp_smash.api.Client` API client. Doing this makes the test code
more readable and concise. Test results do not change (15 tests):

    ============  ==================
    Pulp Version  Test Suite Results
    ============  ==================
    2.7           OK
    dev (2.8)     OK
    ============  ==================

Results obtained with the following command:

    PULP_SMASH_CONFIG_FILE=$PS_CONFIG \
    python -m unittest2 pulp_smash.tests.platform.api_v2.test_user
Refactor module `pulp_smash.tests.platform.api_v2.test_login`. Make this module
use the new `pulp_smash.api.Client` API client. Doing this makes the test more
readable and concise. Test results do not change (4 tests):

    ============  ==================
    Pulp Version  Test Suite Results
    ============  ==================
    2.7           OK (skipped=1)
    dev (2.8)     OK (skipped=1)
    ============  ==================

Results obtained with the following command:

    PULP_SMASH_CONFIG_FILE=$PS_CONFIG \
    python -m unittest2 pulp_smash.tests.platform.api_v2.test_login
Refactor module `pulp_smash.tests.platform.api_v2.test_content_applicability`.
Make this module use the new `pulp_smash.api.Client` API client. Doing this
makes the module more readable and concise. Test results do not change:

    ============  ==================
    Pulp Version  Test Suite Results
    ============  ==================
    2.7           OK
    dev (2.8)     OK (skipped=1)
    ============  ==================

Results obtained with the following command:

    PULP_SMASH_CONFIG_FILE="$PS_CONFIG" \
    python -m unittest2 pulp_smash.tests.platform.api_v2.test_content_applicability
Refactor module `pulp_smash.tests.platform.api_v2.test_search`. Make this module
use the new `pulp_smash.api.Client` API client. Doing this makes the module more
readable and concise. Test results do not change (16 tests):

    ============  ==================
    Pulp Version  Test Suite Results
    ============  ==================
    2.7           OK (skipped=4)
    dev (2.8)     OK (skipped=4)
    ============  ==================

Results obtained with the following command:

    PULP_SMASH_CONFIG_FILE="$PS_CONFIG" \
    python -m unittest2 pulp_smash.tests.platform.api_v2.test_search
Drop function `pulp_smash.utils.create_user` and unit tests for it. This
function has been superceded by `pulp_smash.api.Client`. This change does not
affect test results:

    ============  =============================
    Pulp Version  Test Suite Results
    ============  =============================
    2.7           OK (skipped=14)
    dev (2.8)     FAILED (errors=2, skipped=13)
    ============  =============================
@Ichimonji10 Ichimonji10 merged commit 9b5d848 into pulp:master Jan 11, 2016
@Ichimonji10 Ichimonji10 deleted the utils3 branch January 11, 2016 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant