Skip to content

Commit

Permalink
Modernize functional tests III
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
mdellweg committed Aug 26, 2023
1 parent da49388 commit 97d8a78
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 433 deletions.
1 change: 1 addition & 0 deletions pulp_ansible/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ class Meta:
"pulp_href",
"pulp_created",
"base_path",
"base_url",
"content_guard",
"name",
"repository",
Expand Down
Empty file.
1 change: 0 additions & 1 deletion pulp_ansible/tests/assets/func_test_settings.py

This file was deleted.

6 changes: 6 additions & 0 deletions pulp_ansible/tests/functional/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
"""Tests for ansible plugin."""

try:
from pulp_ansible.tests.functional.conftest import * # noqa

except ImportError:
pass
165 changes: 0 additions & 165 deletions pulp_ansible/tests/functional/api/role/test_crd_distribution.py

This file was deleted.

77 changes: 77 additions & 0 deletions pulp_ansible/tests/functional/api/role/test_crud_distribution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""CRUD tests for AnsibleDistribution."""

import pytest
from collections import namedtuple

from pulpcore.client.pulp_ansible import ApiException


FakeRepository = namedtuple("FakeRepository", "pulp_href")


@pytest.mark.parallel
def test_crud_distribution(
ansible_distro_api_client,
ansible_role_remote_factory,
ansible_sync_factory,
ansible_distribution_factory,
monitor_task,
has_pulp_plugin,
):
repository = ansible_sync_factory(remote=ansible_role_remote_factory().pulp_href)
distribution = ansible_distribution_factory(repository=repository)
assert distribution.repository == repository.pulp_href
assert distribution.repository_version is None

with pytest.raises(ApiException) as exc_info:
fake_repository = FakeRepository(
pulp_href=repository.pulp_href[:-37] + "00000000-0000-0000-0000-000000000000/"
)
ansible_distribution_factory(repository=fake_repository)
assert "Invalid hyperlink - Object does not exist." in exc_info.value.body

with pytest.raises(ApiException) as exc_info:
ansible_distro_api_client.partial_update(
distribution.pulp_href, {"repository": "this-is-invalid"}
)
assert "Invalid hyperlink - No URL match." in exc_info.value.body

ansible_distro_api_client.partial_update(distribution.pulp_href, {"repository": None})
monitor_task(
ansible_distro_api_client.partial_update(
distribution.pulp_href, {"repository_version": repository.latest_version_href}
).task
)
distribution = ansible_distro_api_client.read(distribution.pulp_href)
assert distribution.repository is None
assert distribution.repository_version == repository.latest_version_href

if has_pulp_plugin("pulpcore", min="3.30.1"):
# On older versions, this fails complaining repository and version cannot be used together.
body = {
"name": distribution.name,
"base_path": distribution.base_path,
"repository": repository.pulp_href,
}
monitor_task(ansible_distro_api_client.update(distribution.pulp_href, body).task)
distribution = ansible_distro_api_client.read(distribution.pulp_href)
assert distribution.repository == repository.pulp_href
assert distribution.repository_version is None

body = {
"name": distribution.name,
"base_path": distribution.base_path,
"repository": repository.pulp_href,
"repository_version": repository.latest_version_href,
}
with pytest.raises(ApiException) as exc_info:
ansible_distro_api_client.update(distribution.pulp_href, body)
assert (
"Only one of the attributes 'repository' and 'repository_version' "
"may be used simultaneously."
) in exc_info.value.body

monitor_task(ansible_distro_api_client.delete(distribution.pulp_href).task)
with pytest.raises(ApiException) as exc_info:
ansible_distro_api_client.delete(distribution.pulp_href)
assert "Not found." in exc_info.value.body
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pulpcore.client.pulp_ansible import ApiException


@pytest.mark.parallel
def test_crud_role_remote(
ansible_remote_role_api_client, ansible_role_remote_factory, monitor_task
):
Expand Down Expand Up @@ -48,6 +49,7 @@ def test_crud_role_remote(
monitor_task(ansible_remote_role_api_client.delete(remote.pulp_href).task)


@pytest.mark.parallel
def test_role_remote_no_url(ansible_role_remote_factory):
"""Verify whether is possible to create a remote without a URL."""
with pytest.raises(ApiException):
Expand Down
Loading

0 comments on commit 97d8a78

Please sign in to comment.