Skip to content

Commit

Permalink
rpm sync test verifies unit counts on repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mhrivnak authored and Ichimonji10 committed Dec 18, 2015
1 parent 668f4b7 commit 543532f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
21 changes: 20 additions & 1 deletion 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,
get_importers,
handle_response,
poll_spawned_tasks,
Expand Down Expand Up @@ -257,14 +258,15 @@ def setUpClass(cls):
super(SyncValidFeedTestCase, cls).setUpClass()
body = _gen_rpm_repo_body()
body['importer_config']['feed'] = _VALID_FEED
cls.attrs_iter = (create_repository(cls.cfg, body),) # see parent cls
cls.attrs_iter = (create_repository(cls.cfg, body),)
cls.sync_repo = [] # raw responses
report = sync_repository(
cls.cfg,
cls.attrs_iter[0]['_href'],
cls.sync_repo,
)
cls.task_bodies = tuple(poll_spawned_tasks(cls.cfg, report))
cls.repo_after_sync = get(cls.cfg, cls.attrs_iter[0]['_href'])

def test_start_sync_code(self):
"""Assert the call to sync a repository returns an HTTP 202."""
Expand All @@ -291,6 +293,23 @@ def test_task_progress_report(self):
0
)

def test_unit_count_on_repo(self):
"""Verify that the sync added the correct number of units to the repo.
Looks at the content counts on the repo.
This also verifies that the counts themselves are getting set on the
repo.
I obtained these numbers by looking at the metadata in the remote
repository.
"""
counts = self.repo_after_sync.get('content_unit_counts', {})
self.assertEqual(counts.get('rpm'), 32)
self.assertEqual(counts.get('erratum'), 4)
self.assertEqual(counts.get('package_group'), 2)
self.assertEqual(counts.get('package_category'), 1)


class SyncInvalidFeedTestCase(_BaseTestCase):
"""If an invalid feed is given, the sync completes with reported errors."""
Expand Down
15 changes: 15 additions & 0 deletions pulp_smash/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ def get_importers(server_config, href, responses=None):
), responses)


def get(server_config, href, responses=None):
"""Get a document from an HTTP API.
:param server_config: A :class:`pulp_smash.config.ServerConfig` object.
:param href: A string. The path to a document.
: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,
**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 @@ -121,6 +121,23 @@ def setUpClass(cls):
cls.mocks = {'handle_response': hand_resp, 'request': request}


class GetTestCase(CommonAssertionsMixin, TestCase):
"""Test :meth:`pulp_smash.utils.get`."""

@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(**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 543532f

Please sign in to comment.