def username_password_failure_test(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 register_username_password_with_task(self): """Register with username and password 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 username = self._subscription_request.account_username password = self._subscription_request.account_password.value register_server_proxy = self.rhsm_observer.get_proxy( RHSM_REGISTER_SERVER) task = RegisterWithUsernamePasswordTask( rhsm_register_server_proxy=register_server_proxy, username=username, password=password) return task