Skip to content

Commit

Permalink
fixup! Translate tests to using bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Dellweg committed Feb 11, 2020
1 parent e0019ec commit 75ff8f9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 54 deletions.
31 changes: 17 additions & 14 deletions pulp_deb/tests/functional/api/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
DEB_PACKAGE_NAME,
)
from pulp_deb.tests.functional.utils import (
gen_deb_client,
gen_deb_remote,
monitor_task,
)
from pulp_deb.tests.functional.utils import set_up_module as setUpModule # noqa:F401
from pulp_deb.tests.functional.utils import (
deb_apt_publication_api,
deb_remote_api,
deb_repository_api,
deb_verbatim_publication_api,
)

from pulpcore.client.pulp_deb import (
PublicationsAptApi,
PublicationsVerbatimApi,
RepositoriesAptApi,
RepositorySyncURL,
RemotesAptApi,
DebDebPublication,
DebVerbatimPublication,
)
Expand All @@ -39,7 +39,7 @@ class PublishAnyRepoVersionSimpleTestCase(unittest.TestCase):
"""

class Meta:
PublicationsApi = PublicationsAptApi
publication_api = deb_apt_publication_api

@staticmethod
def Publication(*args, **kwargs):
Expand All @@ -60,10 +60,9 @@ def test_all(self):
repository versions to be published at same time.
"""
cfg = config.get_config()
client = gen_deb_client()
repo_api = RepositoriesAptApi(client)
remote_api = RemotesAptApi(client)
publication_api = self.PublicationsApi(client)
repo_api = deb_repository_api
remote_api = deb_remote_api
publication_api = self.Meta.publication_api

body = gen_deb_remote()
remote = remote_api.create(body)
Expand All @@ -86,7 +85,7 @@ def test_all(self):
non_latest = choice(version_hrefs[:-1])

# Step 2
publish_data = self.Publication(repository=repo.pulp_href)
publish_data = self.Meta.Publication(repository=repo.pulp_href)
publish_response = publication_api.create(publish_data)
created_resources = monitor_task(publish_response.task)
publication_href = created_resources[0]
Expand All @@ -97,7 +96,7 @@ def test_all(self):
self.assertEqual(publication.repository_version, version_hrefs[-1])

# Step 4
publish_data = self.Publication(repository_version=non_latest)
publish_data = self.Meta.Publication(repository_version=non_latest)
publish_response = publication_api.create(publish_data)
created_resources = monitor_task(publish_response.task)
publication_href = created_resources[0]
Expand All @@ -122,6 +121,8 @@ class PublishAnyRepoVersionStructuredTestCase(PublishAnyRepoVersionSimpleTestCas
"""

class Meta:
publication_api = deb_apt_publication_api

@staticmethod
def Publication(*args, **kwargs):
"""Delegate Publication constructor."""
Expand All @@ -138,6 +139,8 @@ class PublishAnyRepoVersionCombinedTestCase(PublishAnyRepoVersionSimpleTestCase)
"""

class Meta:
publication_api = deb_apt_publication_api

@staticmethod
def Publication(*args, **kwargs):
"""Delegate Publication constructor."""
Expand All @@ -154,5 +157,5 @@ class VerbatimPublishAnyRepoVersionTestCase(PublishAnyRepoVersionSimpleTestCase)
"""

class Meta:
PublicationsApi = PublicationsVerbatimApi
publication_api = deb_verbatim_publication_api
Publication = DebVerbatimPublication
30 changes: 11 additions & 19 deletions pulp_deb/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
DEB_INVALID_FIXTURE_URL,
)
from pulp_deb.tests.functional.utils import (
gen_deb_client,
gen_deb_remote,
monitor_task,
PulpTaskError,
)
from pulp_deb.tests.functional.utils import set_up_module as setUpModule # noqa:F401

from pulpcore.client.pulp_deb import (
RepositoriesAptApi,
RepositorySyncURL,
RemotesAptApi,
from pulp_deb.tests.functional.utils import (
deb_remote_api,
deb_repository_api,
)

from pulpcore.client.pulp_deb import RepositorySyncURL


class BasicSyncTestCase(unittest.TestCase):
"""Sync a repository with the deb plugin."""
Expand All @@ -33,7 +31,6 @@ class BasicSyncTestCase(unittest.TestCase):
def setUpClass(cls):
"""Create class-wide variables."""
cls.cfg = config.get_config()
cls.client = gen_deb_client()

def test_sync_small(self):
"""Test synching with deb content only."""
Expand Down Expand Up @@ -63,8 +60,8 @@ def do_sync(self, sync_udebs, fixture_summary):
8. Assert that the same number of content units are present and that no
units were added.
"""
repo_api = RepositoriesAptApi(self.client)
remote_api = RemotesAptApi(self.client)
repo_api = deb_repository_api
remote_api = deb_remote_api

repo = repo_api.create(gen_repo())
self.addCleanup(repo_api.delete, repo.pulp_href)
Expand Down Expand Up @@ -110,16 +107,16 @@ def test_file_decriptors(self):
4. Assert that issued command returns `0` opened files.
"""
cli_client = cli.Client(self.cfg, cli.echo_handler)
repo_api = deb_repository_api
remote_api = deb_remote_api

# check if 'lsof' is available
if cli_client.run(("which", "lsof")).returncode != 0:
raise unittest.SkipTest("lsof package is not present")

repo_api = RepositoriesAptApi(self.client)
repo = repo_api.create(gen_repo())
self.addCleanup(repo_api.delete, repo.pulp_href)

remote_api = RemotesAptApi(self.client)
remote = remote_api.create(gen_deb_remote())
self.addCleanup(remote_api.delete, remote.pulp_href)

Expand All @@ -135,11 +132,6 @@ def test_file_decriptors(self):
class SyncInvalidTestCase(unittest.TestCase):
"""Sync a repository with a given url on the remote."""

@classmethod
def setUpClass(cls):
"""Create class-wide variables."""
cls.client = gen_deb_client()

def test_invalid_url(self):
"""Sync a repository using a remote url that does not exist.
Expand All @@ -166,8 +158,8 @@ def test_invalid_deb_content(self):

def do_test(self, url):
"""Sync a repository given ``url`` on the remote."""
repo_api = RepositoriesAptApi(self.client)
remote_api = RemotesAptApi(self.client)
repo_api = deb_repository_api
remote_api = deb_remote_api

repo = repo_api.create(gen_repo())
self.addCleanup(repo_api.delete, repo.pulp_href)
Expand Down
36 changes: 23 additions & 13 deletions pulp_deb/tests/functional/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,36 @@
Configuration,
TasksApi,
)
from pulpcore.client.pulp_deb import ApiClient as DebApiClient
from pulpcore.client.pulp_deb import (
ApiClient as DebApiClient,
PublicationsAptApi,
PublicationsVerbatimApi,
RemotesAptApi,
RepositoriesAptApi,
)

skip_if = partial(selectors.skip_if, exc=SkipTest) # pylint:disable=invalid-name
"""The ``@skip_if`` decorator, customized for unittest.
:func:`pulp_smash.selectors.skip_if` is test runner agnostic. This function is
identical, except that ``exc`` has been set to ``unittest.SkipTest``.
"""

configuration = Configuration()
configuration.username = "admin"
configuration.password = "password"
configuration.safe_chars_for_path_param = "/"

core_client = CoreApiClient(configuration)
artifact_api = ArtifactsApi(core_client)
task_api = TasksApi(core_client)

deb_client = DebApiClient(configuration)
deb_remote_api = RemotesAptApi(deb_client)
deb_repository_api = RepositoriesAptApi(deb_client)
deb_apt_publication_api = PublicationsAptApi(deb_client)
deb_verbatim_publication_api = PublicationsVerbatimApi(deb_client)


def set_up_module():
"""Skip tests Pulp 3 isn't under test or if pulp_deb isn't installed."""
Expand Down Expand Up @@ -243,18 +265,6 @@ def create_verbatim_publication(cfg, repo, version_href=None):
return client.get(tasks[-1]["created_resources"][0])


skip_if = partial(selectors.skip_if, exc=SkipTest) # pylint:disable=invalid-name
"""The ``@skip_if`` decorator, customized for unittest.
:func:`pulp_smash.selectors.skip_if` is test runner agnostic. This function is
identical, except that ``exc`` has been set to ``unittest.SkipTest``.
"""

core_client = CoreApiClient(configuration)
artifact_api = ArtifactsApi(core_client)
task_api = TasksApi(core_client)


def gen_artifact(url):
"""Creates an artifact."""
response = utils.http_get(url)
Expand Down
16 changes: 8 additions & 8 deletions pulp_deb/tests/unit/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
# Provide sufficient parameters to create the DebContent object
# Depending on the base class of the serializer, provide either "_artifact" or "_artifacts"
@unittest.skip("FIXME: plugin writer action required")
class TestDebContentSerializer(TestCase):
"""Test DebContentSerializer."""
class TestGenericContentSerializer(TestCase):
"""Test GenericContentSerializer."""

def setUp(self):
"""Set up the DebContentSerializer tests."""
"""Set up the GenericContentSerializer tests."""
self.artifact = Artifact.objects.create(
md5="ec0df26316b1deb465d2d18af7b600f5",
sha1="cf6121b0425c2f2e3a2fcfe6f402d59730eb5661",
Expand All @@ -27,14 +27,14 @@ def setUp(self):
)

def test_valid_data(self):
"""Test that the DebContentSerializer accepts valid data."""
"""Test that the GenericContentSerializer accepts valid data."""
data = {"_artifact": "/pulp/api/v3/artifacts/{}/".format(self.artifact.pk)}
serializer = DebContentSerializer(data=data)
serializer = GenericContentSerializer(data=data)
self.assertTrue(serializer.is_valid())

def test_duplicate_data(self):
"""Test that the DebContentSerializer does not accept data."""
DebContent.objects.create(artifact=self.artifact)
"""Test that the GenericContentSerializer does not accept data."""
GenericContent.objects.create(artifact=self.artifact)
data = {"_artifact": "/pulp/api/v3/artifacts/{}/".format(self.artifact.pk)}
serializer = DebContentSerializer(data=data)
serializer = GenericContentSerializer(data=data)
self.assertFalse(serializer.is_valid())

0 comments on commit 75ff8f9

Please sign in to comment.