def test_attach_subscription_task_failure(self, environ_get): """Test the AttachSubscriptionTask - failure.""" rhsm_attach_proxy = Mock() # raise DBusError with error message in JSON json_error = '{"message": "Failed to attach subscription."}' rhsm_attach_proxy.AutoAttach.side_effect = DBusError(json_error) task = AttachSubscriptionTask(rhsm_attach_proxy=rhsm_attach_proxy, sla="foo_sla") with self.assertRaises(SubscriptionError): task.run() rhsm_attach_proxy.AutoAttach.assert_called_once_with( "foo_sla", {}, "en_US.UTF-8")
def test_unregister_failure(self, environ_get): """Test the UnregisterTask - failure.""" # register server proxy rhsm_unregister_proxy = Mock() # raise DBusError with error message in JSON json_error = '{"message": "Unregistration failed."}' rhsm_unregister_proxy.Unregister.side_effect = DBusError(json_error) # instantiate the task and run it task = UnregisterTask(rhsm_unregister_proxy=rhsm_unregister_proxy) with self.assertRaises(DBusError): task.run() # check the unregister proxy Unregister method was called correctly rhsm_unregister_proxy.Unregister.assert_called_once_with({}, "en_US.UTF-8")
def test_username_password_failure(self, private_bus, environ_get): """Test the RegisterWithUsernamePasswordTask - failure.""" # register server proxy register_server_proxy = Mock() # private register proxy get_proxy = private_bus.return_value.__enter__.return_value.get_proxy private_register_proxy = get_proxy.return_value # raise DBusError with error message in JSON json_error = '{"message": "Registration failed."}' private_register_proxy.Register.side_effect = DBusError(json_error) # instantiate the task and run it task = RegisterWithUsernamePasswordTask( rhsm_register_server_proxy=register_server_proxy, username="******", password="******") with self.assertRaises(RegistrationError): task.run() # check private register proxy Register method was called correctly private_register_proxy.Register.assert_called_with( "", "foo_user", "bar_password", {}, {}, "en_US.UTF-8")
def test_org_key_failure(self, private_bus, environ_get): """Test the RegisterWithOrganizationKeyTask - failure.""" # register server proxy register_server_proxy = Mock() # private register proxy get_proxy = private_bus.return_value.__enter__.return_value.get_proxy private_register_proxy = get_proxy.return_value # raise DBusError with error message in JSON json_error = '{"message": "Registration failed."}' private_register_proxy.RegisterWithActivationKeys.side_effect = DBusError( json_error) # instantiate the task and run it task = RegisterWithOrganizationKeyTask( rhsm_register_server_proxy=register_server_proxy, organization="123456789", activation_keys=["foo", "bar", "baz"]) with self.assertRaises(RegistrationError): task.run() # check private register proxy RegisterWithActivationKeys method was called correctly private_register_proxy.RegisterWithActivationKeys.assert_called_with( "123456789", ["foo", "bar", "baz"], {}, {}, 'en_US.UTF-8')
def test_set_system_pourpose_failure(self): """Test that exception raised by SetSyspurpose DBus call is handled correctly.""" with tempfile.TemporaryDirectory() as sysroot: # create fake RHSM Syspurpose DBus proxy syspurpose_proxy = Mock() # raise DBusError with error message in JSON syspurpose_proxy.SetSyspurpose.side_effect = DBusError("syspurpose error") # set system purpose & False is returned due to the exception assert not give_the_system_purpose(sysroot=sysroot, rhsm_syspurpose_proxy=syspurpose_proxy, role="foo", sla="bar", usage="baz", addons=["a", "b", "c"]) # check the fake DBus method still was called correctly syspurpose_proxy.SetSyspurpose.assert_called_once_with( { "role": get_variant(Str, "foo"), "service_level_agreement": get_variant(Str, "bar"), "usage": get_variant(Str, "baz"), "addons": get_variant(List[Str], ["a", "b", "c"]) }, 'en_US.UTF-8' )
def call(): raise DBusError("Fake error!")