[Kimchi-devel] [PATCH 1/5] Override only the updated "User" methods in "patch_auth"

Daniel H Barboza danielhb at linux.vnet.ibm.com
Mon Apr 14 18:31:01 UTC 2014


Reviewed-by: Daniel Barboza <danielhb at linux.vnet.ibm.com>

On 04/11/2014 05:57 PM, Aline Manera wrote:
> From: Crístian Viana <vianac at linux.vnet.ibm.com>
>
> The function "patch_auth" creates a fake class to override the existing
> kimchi.auth.User with a few updated methods. That attribution overrides
> the entire User class along with all its methods.
>
> In order to avoid side effects, override only the methods we need to
> change in the "User" class. Other methods not related to "patch_auth"
> will not be affected now.
> ---
>   tests/utils.py |   24 ++++++------------------
>   1 file changed, 6 insertions(+), 18 deletions(-)
>
> diff --git a/tests/utils.py b/tests/utils.py
> index 0a1a967..b373f34 100644
> --- a/tests/utils.py
> +++ b/tests/utils.py
> @@ -149,25 +149,12 @@ def patch_auth(sudo=True):
>       Override the authenticate function with a simple test against an
>       internal dict of users and passwords.
>       """
> -    USER_ID = 'userid'
> -    USER_GROUPS = 'groups'
> -    USER_SUDO = 'sudo'
>   
> -    class _User(object):
> -        def __init__(self, userid):
> -            self.user = {}
> -            self.user[USER_ID] = userid
> -            self.user[USER_GROUPS] = None
> -            self.user[USER_SUDO] = sudo
> +    def _get_groups(self):
> +        return None
>   
> -        def get_groups(self):
> -            return self.user[USER_GROUPS]
> -
> -        def has_sudo(self):
> -            return self.user[USER_SUDO]
> -
> -        def get_user(self):
> -            return self.user
> +    def _has_sudo(self):
> +        return sudo
>   
>       def _authenticate(username, password, service="passwd"):
>           try:
> @@ -178,7 +165,8 @@ def patch_auth(sudo=True):
>   
>       import kimchi.auth
>       kimchi.auth.authenticate = _authenticate
> -    kimchi.auth.User = _User
> +    kimchi.auth.User.get_groups = _get_groups
> +    kimchi.auth.User.has_sudo = _has_sudo
>   
>   
>   def normalize_xml(xml_str):




More information about the Kimchi-devel mailing list