-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes: #324
- Loading branch information
Showing
3 changed files
with
160 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,67 @@ | ||
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) | ||
import pytest | ||
|
||
from pulp_ostree.tests.functional.constants import OSTREE_FIXTURE_URL | ||
|
||
|
||
@pytest.fixture | ||
def synced_repo( | ||
ostree_repositories_api_client, ostree_repository_factory, ostree_remote_factory, monitor_task | ||
): | ||
""" | ||
Fixture that syncs a Remote ostree Repository, | ||
waits until the sync task completes and returns the | ||
created repository object. | ||
""" | ||
repo = ostree_repository_factory() | ||
remote = ostree_remote_factory(url=OSTREE_FIXTURE_URL, policy="immediate") | ||
result = ostree_repositories_api_client.sync(repo.pulp_href, {"remote": remote.pulp_href}) | ||
monitor_task(result.task) | ||
return ostree_repositories_api_client.read(repo.pulp_href) | ||
|
||
|
||
@pytest.mark.parallel | ||
def test_filter_refs( | ||
ostree_content_refs_api_client, | ||
ostree_content_commits_api_client, | ||
synced_repo, | ||
): | ||
"""Check if refs can be filtered by their names and related commits' checksums.""" | ||
# check by name | ||
refs_stable = ostree_content_refs_api_client.list( | ||
repository_version_added=synced_repo.latest_version_href, name="stable" | ||
).to_dict() | ||
|
||
assert refs_stable["count"] == 1, refs_stable | ||
assert refs_stable["results"][0]["name"] == "stable", refs_stable | ||
|
||
# check by commit | ||
commit = ostree_content_commits_api_client.read(refs_stable["results"][0]["commit"]) | ||
refs_commit_checksum = ostree_content_refs_api_client.list( | ||
repository_version_added=synced_repo.latest_version_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 | ||
|
||
|
||
@pytest.mark.parallel | ||
def test_filter_commits( | ||
ostree_content_refs_api_client, | ||
ostree_content_commits_api_client, | ||
synced_repo, | ||
): | ||
"""Check if commits can be filtered by their checksums.""" | ||
refs_rawhide = ostree_content_refs_api_client.list( | ||
repository_version_added=synced_repo.latest_version_href, name="rawhide" | ||
).to_dict() | ||
ref_rawhide = refs_rawhide["results"][0] | ||
|
||
commits_rawhide = ostree_content_commits_api_client.list( | ||
repository_version_added=synced_repo.latest_version_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,92 @@ | ||
import pytest | ||
import uuid | ||
|
||
from pulp_ostree.tests.functional.constants import OSTREE_FIXTURE_URL | ||
from pulpcore.client.pulp_ostree import ( | ||
ApiClient, | ||
ContentCommitsApi, | ||
ContentRefsApi, | ||
DistributionsOstreeApi, | ||
RepositoriesOstreeApi, | ||
RemotesOstreeApi, | ||
) | ||
|
||
# Api Bindings fixtures | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
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(scope="session") | ||
def ostree_content_refs_api_client(ostree_client): | ||
"""Fixture that returns an instance of ContentRefsApi""" | ||
return ContentRefsApi(ostree_client) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def ostree_content_commits_api_client(ostree_client): | ||
"""Fixture that returns an instance of ContentCommitsApi""" | ||
return ContentCommitsApi(ostree_client) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def ostree_repositories_api_client(ostree_client): | ||
"""Fixture that returns an instance of RepositoriesOstreeApi""" | ||
return RepositoriesOstreeApi(ostree_client) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def ostree_remotes_api_client(ostree_client): | ||
"""Fixture that returns an instance of RemotesOstreeApi""" | ||
return RemotesOstreeApi(ostree_client) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def ostree_distributions_api_client(ostree_client): | ||
"""Fixture that returns an instance of DistributionsOstreeApi""" | ||
return DistributionsOstreeApi(ostree_client) | ||
|
||
|
||
# Factory fixtures | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def ostree_repository_factory(ostree_repositories_api_client, gen_object_with_cleanup): | ||
"""A factory to generate an ostree Repository with auto-deletion after the test run.""" | ||
|
||
def _ostree_repository_factory(**kwargs): | ||
data = {"name": str(uuid.uuid4())} | ||
data.update(kwargs) | ||
return gen_object_with_cleanup(ostree_repositories_api_client, data) | ||
|
||
return _ostree_repository_factory | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def ostree_remote_factory(ostree_remotes_api_client, gen_object_with_cleanup): | ||
"""A factory to generate an ostree Remote with auto-deletion after the test run.""" | ||
|
||
def _ostree_remote_factory(*, url=OSTREE_FIXTURE_URL, policy="immediate", **kwargs): | ||
data = {"url": url, "policy": policy, "name": str(uuid.uuid4())} | ||
data.update(kwargs) | ||
return gen_object_with_cleanup(ostree_remotes_api_client, data) | ||
|
||
return _ostree_remote_factory | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def ostree_distribution_factory(ostree_distribution_factory, gen_object_with_cleanup): | ||
"""A factory to generate an ostree Distribution with auto-deletion after the test run.""" | ||
|
||
def _ostree_distribution_factory(**body): | ||
data = {"base_path": str(uuid.uuid4()), "name": str(uuid.uuid4())} | ||
data.update(body) | ||
return gen_object_with_cleanup(ostree_distribution_factory, data) | ||
|
||
return _ostree_distribution_factory |