""" User. A user in the analytics service is a simple namedtuple that contains an id and the account type. Since those information are coming from trusted sources ( grass, no need to validate them.) """ from collections import namedtuple from oto import response as oto_response User = namedtuple( 'User', ['user_id', 'user_type']) LOCAL_USER_TYPES = dict( subaccount='S', vendor='L') def create_user(user_id, user_type): """Create a user. Args: id (int): the user id. type (str): the user type (subaccount or label). Returns: User: the user. """ user_type = user_type.lower() if user_type not in LOCAL_USER_TYPES.keys(): return oto_response.Response( errors={'user_type': 'The account type is not recognized.'}) return oto_response.Response( message=User(user_id=int(user_id), user_type=LOCAL_USER_TYPES.get(user_type)))