Skip to content

Commit

Permalink
Add and test utility function get_importers
Browse files Browse the repository at this point in the history
This new utility function replaces function `_get_importers` in module
`pulp_smash.tests.rpm.api_v2.test_sync_publish`.

Test suite results do not change when run against either Pulp 2.6 or 2.7, under
either Python 2 or 3.

Part of #40.
  • Loading branch information
Ichimonji10 committed Dec 6, 2015
1 parent ddca074 commit 76b4e04
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
11 changes: 2 additions & 9 deletions pulp_smash/tests/rpm/api_v2/test_sync_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from pulp_smash.utils import (
create_repository,
delete,
get_importers,
handle_response,
poll_spawned_tasks,
publish_repository,
Expand All @@ -65,14 +66,6 @@
_CONTENT_UPLOADS_PATH = '/pulp/api/v2/content/uploads/'


def _get_importers(server_config, href, responses=None):
"""Read a repository's importers."""
return handle_response(requests.get(
server_config.base_url + href + 'importers/',
**server_config.get_requests_kwargs()
), responses)


def _get_units(server_config, href, responses=None):
"""Search for a repository's units."""
return handle_response(requests.post(
Expand Down Expand Up @@ -221,7 +214,7 @@ def setUpClass(cls):
create_repository(cls.cfg, body) for body in cls.bodies
))
cls.importers_iter = tuple((
_get_importers(cls.cfg, attrs['_href']) for attrs in cls.attrs_iter
get_importers(cls.cfg, attrs['_href']) for attrs in cls.attrs_iter
))

def test_id_notes(self):
Expand Down
16 changes: 16 additions & 0 deletions pulp_smash/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ def delete(server_config, href, responses=None):
), responses)


def get_importers(server_config, href, responses=None):
"""Read a repository's importers.
:param server_config: A :class:`pulp_smash.config.ServerConfig` object.
:param href: A string. The path to a repository.
:param responses: Same as :meth:`handle_response`.
:returns: Same as :meth:`handle_response`.
:raises: Same as :meth:`handle_response`.
"""
return handle_response(requests.get(
server_config.base_url + href + 'importers/',
**server_config.get_requests_kwargs()
), responses)


def handle_response(response, responses=None):
"""Optionally record ``response``, verify its status code, and decode body.
Expand Down
17 changes: 17 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,23 @@ def setUpClass(cls):
cls.mocks = {'handle_response': hand_resp, 'request': request}


class GetImportersTestCase(CommonAssertionsMixin, TestCase):
"""Test :meth:`pulp_smash.utils.get_importers`."""

@classmethod
def setUpClass(cls):
"""Mock out dependencies and call the function under test."""
inputs = {
'server_config': ServerConfig('http://example.com'),
'href': utils.uuid4(),
'responses': None,
}
with mock.patch.object(utils, 'handle_response') as hand_resp:
with mock.patch.object(requests, 'get') as request:
cls.output = utils.get_importers(**inputs)
cls.mocks = {'handle_response': hand_resp, 'request': request}


class PublishRepositoryTestCase(CommonAssertionsMixin, TestCase):
"""Test :meth:`pulp_smash.utils.publish_repository`."""

Expand Down

0 comments on commit 76b4e04

Please sign in to comment.