Skip to content

Commit

Permalink
add client based testing
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Nov 19, 2024
1 parent 412c788 commit ef6a1ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/client_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def test_foreman_content_view(client_environment, activation_key, organization, foremanapi, client):
client.run('dnf install -y subscription-manager')
rcmd = foremanapi.create('registration_commands', {'organization_id': organization['id'], 'insecure': True, 'activation_keys': [activation_key['name']]})
client.run_test(rcmd['registration_command'])
client.run('subscription-manager repos --enable=*')
client.run_test('dnf install -y bear')
assert client.package('bear').is_installed
client.run('dnf remove -y bear')
client.run('subscription-manager unregister')
client.run('subscription-manager clean')
25 changes: 25 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def server():
yield testinfra.get_host('paramiko://quadlet', sudo=True, ssh_config='./.vagrant/ssh-config')


@pytest.fixture(scope="module")
def client():
yield testinfra.get_host('paramiko://client', sudo=True, ssh_config='./.vagrant/ssh-config')


@pytest.fixture(scope="module")
def ssh_config():
config = paramiko.SSHConfig.from_path('./.vagrant/ssh-config')
Expand Down Expand Up @@ -74,3 +79,23 @@ def activation_key(organization, foremanapi):
ak = foremanapi.create('activation_keys', {'name': str(uuid.uuid4()), 'organization_id': organization['id']})
yield ak
foremanapi.delete('activation_keys', ak)

@pytest.fixture
def client_environment(activation_key, content_view, lifecycle_environment, yum_repository, organization, foremanapi):
foremanapi.resource_action('repositories', 'sync', {'id': yum_repository['id']})
foremanapi.update('content_views', {'id': content_view['id'], 'repository_ids': [yum_repository['id']]})
foremanapi.resource_action('content_views', 'publish', {'id': content_view['id']})

library = foremanapi.list('lifecycle_environments', 'name=Library', {'organization_id': organization['id']})[0]
foremanapi.update('activation_keys', {'id': activation_key['id'], 'organization_id': organization['id'], 'environment_id': library['id'], 'content_view_id': content_view['id']})

yield activation_key

foremanapi.update('activation_keys', {'id': activation_key['id'], 'organization_id': organization['id'], 'environment_id': None, 'content_view_id': None})

versions = foremanapi.list('content_view_versions', params={'content_view_id': content_view['id']})
for version in versions:
current_environment_ids = {environment['id'] for environment in version['environments']}
for environment_id in current_environment_ids:
foremanapi.resource_action('content_views', 'remove_from_environment', params={'id': content_view['id'], 'environment_id': environment_id})
foremanapi.delete('content_view_versions', version)

0 comments on commit ef6a1ce

Please sign in to comment.