-
Notifications
You must be signed in to change notification settings - Fork 44
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) ============ =============================
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
) topulp_smash.selectors
.