Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.14.z] - removing the import entities from nailgun and moving target_sat #13060

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 56 additions & 52 deletions tests/foreman/api/test_activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import http

from fauxfactory import gen_integer, gen_string
from nailgun import client, entities
from nailgun import client
import pytest
from requests.exceptions import HTTPError

Expand All @@ -46,7 +46,7 @@ def _bad_max_hosts():


@pytest.mark.tier1
def test_positive_create_unlimited_hosts():
def test_positive_create_unlimited_hosts(target_sat):
"""Create a plain vanilla activation key.
:id: 1d73b8cc-a754-4637-8bae-d9d2aaf89003
Expand All @@ -56,12 +56,12 @@ def test_positive_create_unlimited_hosts():
:CaseImportance: Critical
"""
assert entities.ActivationKey().create().unlimited_hosts is True
assert target_sat.api.ActivationKey().create().unlimited_hosts is True


@pytest.mark.tier1
@pytest.mark.parametrize('max_host', **parametrized(_good_max_hosts()))
def test_positive_create_limited_hosts(max_host):
def test_positive_create_limited_hosts(max_host, target_sat):
"""Create an activation key with limited hosts.
:id: 9bbba620-fd98-4139-a44b-af8ce330c7a4
Expand All @@ -73,14 +73,14 @@ def test_positive_create_limited_hosts(max_host):
:parametrized: yes
"""
act_key = entities.ActivationKey(max_hosts=max_host, unlimited_hosts=False).create()
act_key = target_sat.api.ActivationKey(max_hosts=max_host, unlimited_hosts=False).create()
assert act_key.max_hosts == max_host
assert act_key.unlimited_hosts is False


@pytest.mark.tier1
@pytest.mark.parametrize('key_name', **parametrized(valid_data_list()))
def test_positive_create_with_name(key_name):
def test_positive_create_with_name(key_name, target_sat):
"""Create an activation key providing the initial name.
:id: 749e0d28-640e-41e5-89d6-b92411ce73a3
Expand All @@ -91,13 +91,13 @@ def test_positive_create_with_name(key_name):
:parametrized: yes
"""
act_key = entities.ActivationKey(name=key_name).create()
act_key = target_sat.api.ActivationKey(name=key_name).create()
assert key_name == act_key.name


@pytest.mark.tier2
@pytest.mark.parametrize('desc', **parametrized(valid_data_list()))
def test_positive_create_with_description(desc):
def test_positive_create_with_description(desc, target_sat):
"""Create an activation key and provide a description.
:id: 64d93726-6f96-4a2e-ab29-eb5bfa2ff8ff
Expand All @@ -106,12 +106,12 @@ def test_positive_create_with_description(desc):
:parametrized: yes
"""
act_key = entities.ActivationKey(description=desc).create()
act_key = target_sat.api.ActivationKey(description=desc).create()
assert desc == act_key.description


@pytest.mark.tier2
def test_negative_create_with_no_host_limit():
def test_negative_create_with_no_host_limit(target_sat):
"""Create activation key without providing limitation for hosts number
:id: a9e756e1-886d-4f0d-b685-36ce4247517d
Expand All @@ -121,12 +121,12 @@ def test_negative_create_with_no_host_limit():
:CaseImportance: Critical
"""
with pytest.raises(HTTPError):
entities.ActivationKey(unlimited_hosts=False).create()
target_sat.api.ActivationKey(unlimited_hosts=False).create()


@pytest.mark.tier3
@pytest.mark.parametrize('max_host', **parametrized(_bad_max_hosts()))
def test_negative_create_with_invalid_host_limit(max_host):
def test_negative_create_with_invalid_host_limit(max_host, target_sat):
"""Create activation key with invalid limit values for hosts number.
:id: c018b177-2074-4f1a-a7e0-9f38d6c9a1a6
Expand All @@ -138,12 +138,12 @@ def test_negative_create_with_invalid_host_limit(max_host):
:parametrized: yes
"""
with pytest.raises(HTTPError):
entities.ActivationKey(max_hosts=max_host, unlimited_hosts=False).create()
target_sat.api.ActivationKey(max_hosts=max_host, unlimited_hosts=False).create()


@pytest.mark.tier3
@pytest.mark.parametrize('name', **parametrized(invalid_names_list()))
def test_negative_create_with_invalid_name(name):
def test_negative_create_with_invalid_name(name, target_sat):
"""Create activation key providing an invalid name.
:id: 5f7051be-0320-4d37-9085-6904025ad909
Expand All @@ -155,12 +155,12 @@ def test_negative_create_with_invalid_name(name):
:parametrized: yes
"""
with pytest.raises(HTTPError):
entities.ActivationKey(name=name).create()
target_sat.api.ActivationKey(name=name).create()


@pytest.mark.tier2
@pytest.mark.parametrize('max_host', **parametrized(_good_max_hosts()))
def test_positive_update_limited_host(max_host):
def test_positive_update_limited_host(max_host, target_sat):
"""Create activation key then update it to limited hosts.
:id: 34ca8303-8135-4694-9cf7-b20f8b4b0a1e
Expand All @@ -170,7 +170,7 @@ def test_positive_update_limited_host(max_host):
:parametrized: yes
"""
# unlimited_hosts defaults to True.
act_key = entities.ActivationKey().create()
act_key = target_sat.api.ActivationKey().create()
want = {'max_hosts': max_host, 'unlimited_hosts': False}
for key, value in want.items():
setattr(act_key, key, value)
Expand All @@ -181,7 +181,7 @@ def test_positive_update_limited_host(max_host):

@pytest.mark.tier2
@pytest.mark.parametrize('new_name', **parametrized(valid_data_list()))
def test_positive_update_name(new_name):
def test_positive_update_name(new_name, target_sat):
"""Create activation key providing the initial name, then update
its name to another valid name.
Expand All @@ -192,14 +192,14 @@ def test_positive_update_name(new_name):
:parametrized: yes
"""
act_key = entities.ActivationKey().create()
updated = entities.ActivationKey(id=act_key.id, name=new_name).update(['name'])
act_key = target_sat.api.ActivationKey().create()
updated = target_sat.api.ActivationKey(id=act_key.id, name=new_name).update(['name'])
assert new_name == updated.name


@pytest.mark.tier3
@pytest.mark.parametrize('max_host', **parametrized(_bad_max_hosts()))
def test_negative_update_limit(max_host):
def test_negative_update_limit(max_host, target_sat):
"""Create activation key then update its limit to invalid value.
:id: 0f857d2f-81ed-4b8b-b26e-34b4f294edbc
Expand All @@ -214,7 +214,7 @@ def test_negative_update_limit(max_host):
:parametrized: yes
"""
act_key = entities.ActivationKey().create()
act_key = target_sat.api.ActivationKey().create()
want = {'max_hosts': act_key.max_hosts, 'unlimited_hosts': act_key.unlimited_hosts}
act_key.max_hosts = max_host
act_key.unlimited_hosts = False
Expand All @@ -227,7 +227,7 @@ def test_negative_update_limit(max_host):

@pytest.mark.tier3
@pytest.mark.parametrize('new_name', **parametrized(invalid_names_list()))
def test_negative_update_name(new_name):
def test_negative_update_name(new_name, target_sat):
"""Create activation key then update its name to an invalid name.
:id: da85a32c-942b-4ab8-a133-36b028208c4d
Expand All @@ -239,16 +239,16 @@ def test_negative_update_name(new_name):
:parametrized: yes
"""
act_key = entities.ActivationKey().create()
act_key = target_sat.api.ActivationKey().create()
with pytest.raises(HTTPError):
entities.ActivationKey(id=act_key.id, name=new_name).update(['name'])
new_key = entities.ActivationKey(id=act_key.id).read()
target_sat.api.ActivationKey(id=act_key.id, name=new_name).update(['name'])
new_key = target_sat.api.ActivationKey(id=act_key.id).read()
assert new_key.name != new_name
assert new_key.name == act_key.name


@pytest.mark.tier3
def test_negative_update_max_hosts():
def test_negative_update_max_hosts(target_sat):
"""Create an activation key with ``max_hosts == 1``, then update that
field with a string value.
Expand All @@ -258,14 +258,14 @@ def test_negative_update_max_hosts():
:CaseImportance: Low
"""
act_key = entities.ActivationKey(max_hosts=1).create()
act_key = target_sat.api.ActivationKey(max_hosts=1).create()
with pytest.raises(HTTPError):
entities.ActivationKey(id=act_key.id, max_hosts='foo').update(['max_hosts'])
target_sat.api.ActivationKey(id=act_key.id, max_hosts='foo').update(['max_hosts'])
assert act_key.read().max_hosts == 1


@pytest.mark.tier2
def test_positive_get_releases_status_code():
def test_positive_get_releases_status_code(target_sat):
"""Get an activation key's releases. Check response format.
:id: e1ea4797-8d92-4bec-ae6b-7a26599825ab
Expand All @@ -275,7 +275,7 @@ def test_positive_get_releases_status_code():
:CaseLevel: Integration
"""
act_key = entities.ActivationKey().create()
act_key = target_sat.api.ActivationKey().create()
path = act_key.path('releases')
response = client.get(path, auth=get_credentials(), verify=False)
status_code = http.client.OK
Expand All @@ -284,7 +284,7 @@ def test_positive_get_releases_status_code():


@pytest.mark.tier2
def test_positive_get_releases_content():
def test_positive_get_releases_content(target_sat):
"""Get an activation key's releases. Check response contents.
:id: 2fec3d71-33e9-40e5-b934-90b03afc26a1
Expand All @@ -293,14 +293,14 @@ def test_positive_get_releases_content():
:CaseLevel: Integration
"""
act_key = entities.ActivationKey().create()
act_key = target_sat.api.ActivationKey().create()
response = client.get(act_key.path('releases'), auth=get_credentials(), verify=False).json()
assert 'results' in response.keys()
assert type(response['results']) == list


@pytest.mark.tier2
def test_positive_add_host_collections(module_org):
def test_positive_add_host_collections(module_org, module_target_sat):
"""Associate an activation key with several host collections.
:id: 1538808c-621e-4cf9-9b9b-840c5dd54644
Expand All @@ -318,23 +318,27 @@ def test_positive_add_host_collections(module_org):
:CaseImportance: Critical
"""
# An activation key has no host collections by default.
act_key = entities.ActivationKey(organization=module_org).create()
act_key = module_target_sat.api.ActivationKey(organization=module_org).create()
assert len(act_key.host_collection) == 0

# Give activation key one host collection.
act_key.host_collection.append(entities.HostCollection(organization=module_org).create())
act_key.host_collection.append(
module_target_sat.api.HostCollection(organization=module_org).create()
)
act_key = act_key.update(['host_collection'])
assert len(act_key.host_collection) == 1

# Give activation key second host collection.
act_key.host_collection.append(entities.HostCollection(organization=module_org).create())
act_key.host_collection.append(
module_target_sat.api.HostCollection(organization=module_org).create()
)
act_key = act_key.update(['host_collection'])
assert len(act_key.host_collection) == 2


@pytest.mark.tier2
@pytest.mark.upgrade
def test_positive_remove_host_collection(module_org):
def test_positive_remove_host_collection(module_org, module_target_sat):
"""Disassociate host collection from the activation key
:id: 31992ac4-fe55-45bb-bd17-a191928ec2ab
Expand All @@ -353,10 +357,10 @@ def test_positive_remove_host_collection(module_org):
:CaseImportance: Critical
"""
# An activation key has no host collections by default.
act_key = entities.ActivationKey(organization=module_org).create()
act_key = module_target_sat.api.ActivationKey(organization=module_org).create()
assert len(act_key.host_collection) == 0

host_collection = entities.HostCollection(organization=module_org).create()
host_collection = module_target_sat.api.HostCollection(organization=module_org).create()

# Associate host collection with activation key.
act_key.add_host_collection(data={'host_collection_ids': [host_collection.id]})
Expand All @@ -368,7 +372,7 @@ def test_positive_remove_host_collection(module_org):


@pytest.mark.tier1
def test_positive_update_auto_attach():
def test_positive_update_auto_attach(target_sat):
"""Create an activation key, then update the auto_attach
field with the inverse boolean value.
Expand All @@ -378,17 +382,17 @@ def test_positive_update_auto_attach():
:CaseImportance: Critical
"""
act_key = entities.ActivationKey().create()
act_key_2 = entities.ActivationKey(id=act_key.id, auto_attach=(not act_key.auto_attach)).update(
['auto_attach']
)
act_key = target_sat.api.ActivationKey().create()
act_key_2 = target_sat.api.ActivationKey(
id=act_key.id, auto_attach=(not act_key.auto_attach)
).update(['auto_attach'])
assert act_key.auto_attach != act_key_2.auto_attach


@pytest.mark.tier1
@pytest.mark.upgrade
@pytest.mark.parametrize('name', **parametrized(valid_data_list()))
def test_positive_delete(name):
def test_positive_delete(name, target_sat):
"""Create activation key and then delete it.
:id: aa28d8fb-e07d-45fa-b43a-fc90c706d633
Expand All @@ -399,10 +403,10 @@ def test_positive_delete(name):
:parametrized: yes
"""
act_key = entities.ActivationKey(name=name).create()
act_key = target_sat.api.ActivationKey(name=name).create()
act_key.delete()
with pytest.raises(HTTPError):
entities.ActivationKey(id=act_key.id).read()
target_sat.api.ActivationKey(id=act_key.id).read()


@pytest.mark.tier2
Expand Down Expand Up @@ -503,7 +507,7 @@ def test_positive_add_future_subscription():


@pytest.mark.tier1
def test_positive_search_by_org():
def test_positive_search_by_org(target_sat):
"""Search for all activation keys in an organization.
:id: aedba598-2e47-44a8-826c-4dc304ba00be
Expand All @@ -513,8 +517,8 @@ def test_positive_search_by_org():
:CaseImportance: Critical
"""
org = entities.Organization().create()
act_key = entities.ActivationKey(organization=org).create()
keys = entities.ActivationKey(organization=org).search()
org = target_sat.api.Organization().create()
act_key = target_sat.api.ActivationKey(organization=org).create()
keys = target_sat.api.ActivationKey(organization=org).search()
assert len(keys) == 1
assert act_key.id == keys[0].id
Loading
Loading