Skip to content

Commit

Permalink
Tests to filter artifacts by repository_version
Browse files Browse the repository at this point in the history
Add tests to filter artifacts by repository version.

closes:#4811
  • Loading branch information
koliveir authored and kersommoura committed May 21, 2019
1 parent e1696d3 commit d4f8bac
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
1 change: 0 additions & 1 deletion pulpcore/tests/functional/api/using_plugin/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
CONTENT_PATH
)


FILE_CONTENT_NAME = 'file.file'

FILE_CONTENT_PATH = urljoin(CONTENT_PATH, 'file/files/')
Expand Down
79 changes: 78 additions & 1 deletion pulpcore/tests/functional/api/using_plugin/test_repo_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from requests.exceptions import HTTPError

from pulp_smash import api, config, utils
from pulp_smash.pulp3.constants import REPO_PATH
from pulp_smash.pulp3.constants import ARTIFACTS_PATH, REPO_PATH
from pulp_smash.pulp3.utils import (
delete_orphans,
delete_version,
Expand All @@ -25,13 +25,15 @@
)

from pulpcore.tests.functional.api.using_plugin.constants import (
FILE2_FIXTURE_MANIFEST_URL,
FILE_CONTENT_NAME,
FILE_CONTENT_PATH,
FILE_FIXTURE_COUNT,
FILE_FIXTURE_MANIFEST_URL,
FILE_FIXTURE_SUMMARY,
FILE_LARGE_FIXTURE_MANIFEST_URL,
FILE_REMOTE_PATH,
FILE_MANY_FIXTURE_MANIFEST_URL,
)
from pulpcore.tests.functional.api.using_plugin.utils import (
gen_file_remote,
Expand Down Expand Up @@ -846,3 +848,78 @@ def assert_put(self, repo):
self.client.put(repo['_latest_version_href'], repo)
repo = self.client.get(repo['_href'])
self.assertEqual(previous_repo_name, repo['name'], repo)


class FilterArtifactsTestCase(unittest.TestCase):
"""Filter artifacts by repository version.
This test targets the following issue:
* `Pulp #4811 <https://pulp.plan.io/issues/4811>`_
"""

@classmethod
def setUpClass(cls):
"""Create class-wide variables.
Populate Pulp with artifacts to show how the filter is related to
repository version.
"""
cls.cfg = config.get_config()
populate_pulp(cls.cfg, url=FILE_MANY_FIXTURE_MANIFEST_URL)
cls.client = api.Client(cls.cfg)

def test_filter_last_repository_version(self):
"""Filter by last repository version.
For a repository with more than one version.
"""
repo = self.client.post(REPO_PATH, gen_repo())
self.addCleanup(self.client.delete, repo['_href'])

for url in [FILE2_FIXTURE_MANIFEST_URL, FILE_FIXTURE_MANIFEST_URL]:
remote = self.client.post(
FILE_REMOTE_PATH,
gen_file_remote(url=url)
)
self.addCleanup(self.client.delete, remote['_href'])
sync(self.cfg, remote, repo)
repo = self.client.get(repo['_href'])

artifacts = self.client.get(
ARTIFACTS_PATH,
params={'repository_version': repo['_latest_version_href']}
)
# Every sync add 3 content units to the repository. Last repository
# version has 6 content units.
self.assertEqual(len(artifacts), FILE_FIXTURE_COUNT*2, artifacts)

def test_filter_invalid_repo_version(self):
"""Filter by invalid repository version."""
repo = self.client.post(REPO_PATH, gen_repo())
self.addCleanup(self.client.delete, repo['_href'])
with self.assertRaises(HTTPError) as ctx:
self.client.using_handler(api.json_handler).get(
ARTIFACTS_PATH,
params={'repository_version': repo['_href']}
)
for key in ('uri', 'repositoryversion', 'not', 'found'):
self.assertIn(
key,
ctx.exception.response.json()[0].lower(),
ctx.exception.response
)

def test_filter_valid_repo_version(self):
"""Filter by valid repository version."""
remote = self.client.post(FILE_REMOTE_PATH, gen_file_remote())
self.addCleanup(self.client.delete, remote['_href'])
repo = self.client.post(REPO_PATH, gen_repo())
self.addCleanup(self.client.delete, repo['_href'])
sync(self.cfg, remote, repo)
repo = self.client.get(repo['_href'])
artifacts = self.client.get(
ARTIFACTS_PATH,
params={'repository_version': repo['_latest_version_href']}
)
self.assertEqual(len(artifacts), FILE_FIXTURE_COUNT, artifacts)

0 comments on commit d4f8bac

Please sign in to comment.