def test_org_key_success(self, private_bus, environ_get): """Test the RegisterWithOrganizationKeyTask - success.""" # 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 private_register_proxy.Register.return_value = True, "" # instantiate the task and run it task = RegisterWithOrganizationKeyTask( rhsm_register_server_proxy=register_server_proxy, organization="123456789", activation_keys=["foo", "bar", "baz"]) 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_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 register_organization_key_with_task(self): """Register with organization and activation key(s) based on current subscription request. :return: a DBus path of an installation task """ # NOTE: we access self._subscription_request directly # to avoid the sensitive data clearing happening # in the subscription_request property getter organization = self._subscription_request.organization activation_keys = self._subscription_request.activation_keys.value register_server_proxy = self.rhsm_observer.get_proxy( RHSM_REGISTER_SERVER) task = RegisterWithOrganizationKeyTask( rhsm_register_server_proxy=register_server_proxy, organization=organization, activation_keys=activation_keys) return task