Skip to content

Commit

Permalink
added tests for wrong cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jstavel committed Dec 23, 2024
1 parent 6a111e8 commit afc6116
Showing 1 changed file with 86 additions and 16 deletions.
102 changes: 86 additions & 16 deletions integration-tests/test_register_with_activation_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""


@pytest.mark.parametrize("num_of_act_keys_to_use", [0, 1, 2])
@pytest.mark.parametrize("num_of_act_keys_to_use", [1, 2])
def test_register_with_activation_keys(external_candlepin, subman, test_config, num_of_act_keys_to_use):
"""
https://www.candlepinproject.org/docs/subscription-manager/dbus_objects.html#methods-6
Expand Down Expand Up @@ -102,32 +102,102 @@ def read_pair(line):
assert subman.is_registered


@pytest.mark.parametrize(
"wrong_case", ["wrong-act-key inside", "only wrong-act-key", "wrong-org", "wrong-act-key and wrong-org"]
)
def test_register_with_activation_keys_wrong_case(external_candlepin, subman, test_config, wrong_case):
@pytest.mark.skip
def test_register_with_activation_keys_with_empty_list(external_candlepin, subman, test_config):
"""
https://www.candlepinproject.org/docs/subscription-manager/dbus_objects.html#methods-6
"""
assert not subman.is_registered

candlepin_config = partial(test_config.get, "candlepin")
act_keynames = ("only" not in wrong_case) and candlepin_config("activation_keys") or []
if "wrong-act-key" in wrong_case:
act_keynames.append("wrong-act-key")
act_keys = []

proxy = RHSM.get_proxy(RHSM_REGISTER_SERVER)
with RHSMPrivateBus(proxy) as private_bus:
private_proxy = private_bus.get_proxy(RHSM.service_name, RHSM_REGISTER.object_path)
response = json.loads(
private_proxy.RegisterWithActivationKeys(candlepin_config("org"), act_keys, {}, {}, locale)
)
assert "No activation key specified" in response["message"]
assert response["activationKeys"] == []

assert subman.is_registered


def test_reqister_with_activation_keys_with_wrong_key_among_good_ones(any_candlepin, subman, test_config):
"""
https://www.candlepinproject.org/docs/subscription-manager/dbus_objects.html#methods-6
org_to_use = ("org" in wrong_case) and "wrong-org" or candlepin_config("org")
Given a DBus method RegisterWithActivationKeys is used to register a system
When an invalid activation key appears in a list of valid activation keys
Then an application registers a system using all valid activation keys
and the application returns a list of activation keys that was used for registration.
"""
valid_act_keys = test_config.get("candlepin", "activation_keys") or []
act_keys = valid_act_keys + ["wrong-act-key"]
org_to_use = test_config.get("candlepin", "org")

proxy = RHSM.get_proxy(RHSM_REGISTER_SERVER)
with RHSMPrivateBus(proxy) as private_bus:
private_proxy = private_bus.get_proxy(RHSM.service_name, RHSM_REGISTER.object_path)
response = json.loads(private_proxy.RegisterWithActivationKeys(org_to_use, act_keys, {}, {}, locale))
assert (
"activationKeys" in response
), "DBus method returns which activation keys were used to register a system"
assert sorted([ii["activationKeyName"] for ii in response["activationKeys"]]) == sorted(
valid_act_keys
), "Just valid activation keys should appear in response of the call"

assert subman.is_registered


def test_register_with_activation_keys_wrong_act_key(external_candlepin, subman, test_config):
"""
https://www.candlepinproject.org/docs/subscription-manager/dbus_objects.html#methods-6
"""
act_keys = ["wrong-act-key"]
org_to_use = test_config.get("candlepin", "org")

proxy = RHSM.get_proxy(RHSM_REGISTER_SERVER)
with RHSMPrivateBus(proxy) as private_bus:
private_proxy = private_bus.get_proxy(RHSM.service_name, RHSM_REGISTER.object_path)
with pytest.raises(DBusError) as excinfo:
json.loads(private_proxy.RegisterWithActivationKeys(org_to_use, act_keynames, {}, {}, locale))
if "wrong-org" in wrong_case: # two wrong cases together
assert "Organization wrong-org does not exist." in str(excinfo.value)
private_proxy.RegisterWithActivationKeys(org_to_use, act_keys, {}, {}, locale)
assert "None of the activation keys specified exist for this org" in str(excinfo.value)

assert not subman.is_registered

if "wrong-act-key inside" == wrong_case:
assert "some activation key specified does not exist for this org" in str(excinfo.value)

if "just one wrong-act-key" == wrong_case:
assert "None of the activation keys specified exist for this org" in str(excinfo.value)
def test_register_with_activation_keys_wrong_org(external_candlepin, subman, test_config):
"""
https://www.candlepinproject.org/docs/subscription-manager/dbus_objects.html#methods-6
"""
candlepin_config = partial(test_config.get, "candlepin")
act_keys = candlepin_config("activation_keys")
org_to_use = "wrong-org"

proxy = RHSM.get_proxy(RHSM_REGISTER_SERVER)
with RHSMPrivateBus(proxy) as private_bus:
private_proxy = private_bus.get_proxy(RHSM.service_name, RHSM_REGISTER.object_path)
with pytest.raises(DBusError) as excinfo:
json.loads(private_proxy.RegisterWithActivationKeys(org_to_use, act_keys, {}, {}, locale))
assert f"Organization {org_to_use} does not exist." in str(excinfo.value)

assert not subman.is_registered


def test_register_with_activation_keys_wrong_org_and_wrong_key(external_candlepin, subman, test_config):
"""
https://www.candlepinproject.org/docs/subscription-manager/dbus_objects.html#methods-6
"""
act_keys = ["wrong-act-key"]
org_to_use = "wrong-org"

proxy = RHSM.get_proxy(RHSM_REGISTER_SERVER)
with RHSMPrivateBus(proxy) as private_bus:
private_proxy = private_bus.get_proxy(RHSM.service_name, RHSM_REGISTER.object_path)
with pytest.raises(DBusError) as excinfo:
json.loads(private_proxy.RegisterWithActivationKeys(org_to_use, act_keys, {}, {}, locale))
assert f"Organization {org_to_use} does not exist." in str(excinfo.value)

assert not subman.is_registered

0 comments on commit afc6116

Please sign in to comment.