forked from pulp/pulp_ostree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes: pulp#324
- Loading branch information
Showing
3 changed files
with
170 additions
and
100 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Rewritten test_filter.py using pytest. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,48 @@ | ||
import unittest | ||
|
||
from urllib.parse import urlparse | ||
|
||
from pulp_smash import config | ||
from pulp_smash.pulp3.bindings import delete_orphans, monitor_task | ||
from pulp_smash.pulp3.utils import gen_repo | ||
|
||
from pulp_ostree.tests.functional.utils import ( | ||
gen_ostree_client, | ||
gen_ostree_remote, | ||
) | ||
from pulp_ostree.tests.functional.utils import set_up_module as setUpModule # noqa:F401 | ||
|
||
from pulpcore.client.pulp_ostree import ( | ||
ContentCommitsApi, | ||
ContentRefsApi, | ||
RepositoriesOstreeApi, | ||
RepositoriesOstreeVersionsApi, | ||
RepositorySyncURL, | ||
RemotesOstreeApi, | ||
) | ||
|
||
|
||
class ContentFilterTestCase(unittest.TestCase): | ||
"""A test case that verifies the content filtering.""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
"""Initialize class-wide variables.""" | ||
cfg = config.get_config() | ||
cls.registry_name = urlparse(cfg.get_base_url()).netloc | ||
|
||
client_api = gen_ostree_client() | ||
cls.repositories_api = RepositoriesOstreeApi(client_api) | ||
cls.versions_api = RepositoriesOstreeVersionsApi(client_api) | ||
cls.remotes_api = RemotesOstreeApi(client_api) | ||
|
||
cls.commits_api = ContentCommitsApi(client_api) | ||
cls.refs_api = ContentRefsApi(client_api) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
"""Clean orphaned content after finishing the tests.""" | ||
delete_orphans() | ||
|
||
def setUp(self): | ||
"""Clean orphaned content before each test.""" | ||
delete_orphans() | ||
|
||
self.repo = self.repositories_api.create(gen_repo()) | ||
self.addCleanup(self.repositories_api.delete, self.repo.pulp_href) | ||
|
||
body = gen_ostree_remote(depth=0, policy="immediate") | ||
remote = self.remotes_api.create(body) | ||
self.addCleanup(self.remotes_api.delete, remote.pulp_href) | ||
|
||
self.assertEqual(self.repo.latest_version_href, f"{self.repo.pulp_href}versions/0/") | ||
repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) | ||
response = self.repositories_api.sync(self.repo.pulp_href, repository_sync_data) | ||
repo_version = monitor_task(response.task).created_resources[0] | ||
|
||
self.repository_version = self.versions_api.read(repo_version) | ||
|
||
def test_filter_refs(self): | ||
"""Check if refs can be filtered by their names and related commits' checksums.""" | ||
refs_stable = self.refs_api.list( | ||
repository_version_added=self.repository_version.pulp_href, name="stable" | ||
).to_dict() | ||
|
||
self.assertEqual(refs_stable["count"], 1, refs_stable) | ||
self.assertEqual(refs_stable["results"][0]["name"], "stable", refs_stable) | ||
|
||
commit = self.commits_api.read(refs_stable["results"][0]["commit"]) | ||
|
||
refs_commit_checksum = self.refs_api.list( | ||
repository_version_added=self.repository_version.pulp_href, checksum=commit.checksum | ||
).to_dict() | ||
|
||
self.assertEqual(refs_commit_checksum["count"], 1, refs_commit_checksum) | ||
self.assertEqual( | ||
refs_commit_checksum["results"][0]["checksum"], commit.checksum, refs_commit_checksum | ||
) | ||
|
||
def test_filter_commits(self): | ||
"""Check if commits can be filtered by their checksums.""" | ||
refs_rawhide = self.refs_api.list( | ||
repository_version_added=self.repository_version.pulp_href, name="rawhide" | ||
).to_dict() | ||
ref_rawhide = refs_rawhide["results"][0] | ||
|
||
commits_rawhide = self.commits_api.list( | ||
repository_version_added=self.repository_version.pulp_href, | ||
checksum=ref_rawhide["checksum"], | ||
).to_dict() | ||
self.assertEqual(commits_rawhide["count"], 1, commits_rawhide) | ||
|
||
commit_rawhide = commits_rawhide["results"][0] | ||
self.assertEqual(commit_rawhide["checksum"], ref_rawhide["checksum"], commit_rawhide) | ||
self.assertEqual(commit_rawhide["pulp_href"], ref_rawhide["commit"], commit_rawhide) | ||
def test_filter_refs( | ||
repo, | ||
setup_filter, | ||
ostree_content_refs_api, | ||
ostree_content_commits_api, | ||
): | ||
"""Check if refs can be filtered by their names and related commits' checksums.""" | ||
assert repo.latest_version_href == f"{repo.pulp_href}versions/0/" | ||
repo_version = setup_filter | ||
refs_stable = ostree_content_refs_api.list( | ||
repository_version_added=repo_version.pulp_href, name="stable" | ||
).to_dict() | ||
|
||
assert refs_stable["count"] == 1, refs_stable | ||
assert refs_stable["results"][0]["name"] == "stable", refs_stable | ||
|
||
commit = ostree_content_commits_api.read(refs_stable["results"][0]["commit"]) | ||
refs_commit_checksum = ostree_content_refs_api.list( | ||
repository_version_added=repo_version.pulp_href, checksum=commit.checksum | ||
).to_dict() | ||
|
||
assert refs_commit_checksum["count"] == 1, refs_commit_checksum | ||
assert refs_commit_checksum["results"][0]["checksum"] == commit.checksum, refs_commit_checksum | ||
|
||
|
||
def test_filter_commits( | ||
repo, | ||
setup_filter, | ||
ostree_content_refs_api, | ||
ostree_content_commits_api, | ||
): | ||
"""Check if commits can be filtered by their checksums.""" | ||
assert repo.latest_version_href == f"{repo.pulp_href}versions/0/" | ||
repo_version = setup_filter | ||
refs_rawhide = ostree_content_refs_api.list( | ||
repository_version_added=repo_version.pulp_href, name="rawhide" | ||
).to_dict() | ||
ref_rawhide = refs_rawhide["results"][0] | ||
|
||
commits_rawhide = ostree_content_commits_api.list( | ||
repository_version_added=repo_version.pulp_href, | ||
checksum=ref_rawhide["checksum"], | ||
).to_dict() | ||
assert commits_rawhide["count"] == 1, commits_rawhide | ||
|
||
commit_rawhide = commits_rawhide["results"][0] | ||
assert commit_rawhide["checksum"] == ref_rawhide["checksum"], commit_rawhide | ||
assert commit_rawhide["pulp_href"] == ref_rawhide["commit"], commit_rawhide |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import pytest | ||
|
||
from pulp_smash.pulp3.bindings import delete_orphans, monitor_task | ||
from pulp_smash.pulp3.utils import gen_repo | ||
|
||
from pulp_ostree.tests.functional.utils import ( | ||
gen_ostree_remote, | ||
) | ||
|
||
from pulpcore.client.pulp_ostree import ( | ||
ApiClient, | ||
ContentCommitsApi, | ||
ContentRefsApi, | ||
RepositoriesOstreeApi, | ||
RepositoriesOstreeVersionsApi, | ||
RepositorySyncURL, | ||
RemotesOstreeApi, | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def ostree_client(_api_client_set, bindings_cfg): | ||
"""Fixture to provide a client to Pulp API""" | ||
api_client = ApiClient(bindings_cfg) | ||
_api_client_set.add(api_client) | ||
yield api_client | ||
_api_client_set.remove(api_client) | ||
|
||
|
||
@pytest.fixture() | ||
def ostree_content_refs_api(ostree_client): | ||
"""Fixture that returns an instance of ContentRefsApi""" | ||
return ContentRefsApi(ostree_client) | ||
|
||
|
||
@pytest.fixture() | ||
def ostree_repositories_api(ostree_client): | ||
"""Fixture that returns an instance of RepositoriesOstreeApi""" | ||
return RepositoriesOstreeApi(ostree_client) | ||
|
||
|
||
@pytest.fixture() | ||
def ostree_remotes_api(ostree_client): | ||
"""Fixture that returns an instance of RepositoriesOstreeApi""" | ||
return RemotesOstreeApi(ostree_client) | ||
|
||
|
||
@pytest.fixture() | ||
def ostree_repositories_versions_api(ostree_client): | ||
"""Fixture that returns an instance of RepositoriesOstreeVersionsApi""" | ||
return RepositoriesOstreeVersionsApi(ostree_client) | ||
|
||
|
||
@pytest.fixture() | ||
def ostree_repository_sync_url(ostree_client): | ||
"""Fixture that returns an instance of RepositorySyncURL""" | ||
return RepositorySyncURL(ostree_client) | ||
|
||
|
||
@pytest.fixture() | ||
def ostree_content_commits_api(ostree_client): | ||
"""Fixture that returns an instance of ContentCommitsApi""" | ||
return ContentCommitsApi(ostree_client) | ||
|
||
|
||
@pytest.fixture() | ||
def remote(ostree_remotes_api): | ||
"""Fixture that creates an ostree Remote and returns the object created""" | ||
body = gen_ostree_remote(depth=0, policy="immediate") | ||
return ostree_remotes_api.create(body) | ||
|
||
|
||
@pytest.fixture() | ||
def repo(ostree_repositories_api): | ||
"""Fixture that creates an ostree Repository""" | ||
return ostree_repositories_api.create(gen_repo()) | ||
|
||
|
||
@pytest.fixture() | ||
def ostree_repository_version( | ||
remote, repo, ostree_repositories_api, ostree_repositories_versions_api | ||
): | ||
""" | ||
Fixture that syncs a Remote ostree Repository, | ||
waits until the sync task completes and returns the | ||
created repository version object. | ||
""" | ||
repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) | ||
response = ostree_repositories_api.sync(repo.pulp_href, repository_sync_data) | ||
repo_version = monitor_task(response.task).created_resources[0] | ||
|
||
return ostree_repositories_versions_api.read(repo_version) | ||
|
||
|
||
@pytest.fixture() | ||
def ostree_repositories_delete(ostree_repositories_api, repo): | ||
"""Fixture that deletes an ostree Repository""" | ||
return ostree_repositories_api.delete(repo.pulp_href) | ||
|
||
|
||
@pytest.fixture() | ||
def ostree_remotes_delete(ostree_remotes_api, remote): | ||
"""Fixture that deletes an ostree Remote""" | ||
return ostree_remotes_api.delete(remote.pulp_href) | ||
|
||
|
||
@pytest.fixture() | ||
def setup_filter( | ||
repo, | ||
remote, | ||
ostree_repository_version, | ||
ostree_repositories_api, | ||
ostree_remotes_api, | ||
): | ||
"""Setup for ostree filter tests""" | ||
delete_orphans() | ||
|
||
yield ostree_repository_version | ||
ostree_repositories_api.delete(repo.pulp_href) | ||
ostree_remotes_api.delete(remote.pulp_href) | ||
delete_orphans() |