def test_display_home(self): Roles.set_roles([('Allow', 'CONSORTIUM_EDUCATION_ADMINISTRATOR_1', ('view', 'logout', 'display_home'))]) user = User() rel_chain = [RoleRelation('CONSORTIUM_EDUCATION_ADMINISTRATOR_1', 'CA', 'CA', '1', '2')] user.set_context(rel_chain) context = user.get_user_context() self.assertTrue(context['displayHome'])
def test_non_empty_user(self): user = User() data = { 'name': { 'fullName': 'Joe Doe', 'firstName': 'Joe', 'lastName': 'Doe' }, 'uid': 'joe.doe', 'roles': [], 'stateCode': [None], 'tenant': None, 'displayHome': False, 'guid': '123' } user.set_name(data['name']) user.set_uid(data['uid']) user.set_guid(data['guid']) name = user.get_name() self.assertEqual(name, {'name': data['name']}) uid = user.get_uid() self.assertEqual(uid, data['uid']) context = user.get_user_context() self.assertEqual(context['displayHome'], data['displayHome']) self.assertEqual(context['guid'], data['guid']) guid = user.get_guid() self.assertEqual(guid, data['guid'])
def test_empty_user(self): user = User() data = { 'name': { 'fullName': None, 'firstName': None, 'lastName': None }, 'uid': None, 'roles': [], 'stateCode': [], 'tenant': [], 'displayHome': False, 'guid': None } name = user.get_name() self.assertEqual(name, {'name': data['name']}) uid = user.get_uid() self.assertEqual(uid, data['uid']) context = user.get_user_context() self.assertEqual(context, data) roles = user.get_roles() self.assertEqual(roles, data['roles']) tenant = user.get_tenants() self.assertEqual(0, len(tenant)) guid = user.get_guid() self.assertIsNone(guid)
def test_set_user_info(self): user = User() data = {'name': {'fullName': 'Joe Doe', 'firstName': 'Joe', 'lastName': 'Doe'}, 'uid': 'joe.doe', 'junk': 'junk', 'roles': ['TEACHER'], 'stateCode': [], 'tenant': 'dog', 'displayHome': False, 'guid': '123'} user.set_user_info(data) context = user.get_user_context() self.assertEqual(len(context), 7) self.assertEqual(context['name'], data['name']) self.assertEqual(context['uid'], data['uid']) self.assertEqual(context['guid'], data['guid']) self.assertEqual(context['displayHome'], data['displayHome'])
def test_get_user_context(self): user = User() data = {'name': {'fullName': 'Joe Doe', 'firstName': 'Joe', 'lastName': 'Doe'}, 'uid': 'joe.doe', 'roles': ['TEACHER'], 'tenant': 'dog', 'guid': '123'} user.set_name(data['name']) user.set_uid(data['uid']) user.set_guid(data['guid']) context = user.get_user_context() self.assertEqual(context['uid'], data['uid']) self.assertEqual(context['name'], data['name']) self.assertEqual(context['guid'], data['guid'])
def test_display_home(self): Roles.set_roles([('Allow', 'CONSORTIUM_EDUCATION_ADMINISTRATOR_1', ('view', 'logout', 'display_home'))]) user = User() rel_chain = [ RoleRelation('CONSORTIUM_EDUCATION_ADMINISTRATOR_1', 'CA', 'CA', '1', '2') ] user.set_context(rel_chain) context = user.get_user_context() self.assertTrue(context['displayHome'])
def test_non_empty_user(self): user = User() data = {'name': {'fullName': 'Joe Doe', 'firstName': 'Joe', 'lastName': 'Doe'}, 'uid': 'joe.doe', 'roles': [], 'stateCode': [None], 'tenant': None, 'displayHome': False, 'guid': '123'} user.set_name(data['name']) user.set_uid(data['uid']) user.set_guid(data['guid']) name = user.get_name() self.assertEqual(name, {'name': data['name']}) uid = user.get_uid() self.assertEqual(uid, data['uid']) context = user.get_user_context() self.assertEqual(context['displayHome'], data['displayHome']) self.assertEqual(context['guid'], data['guid']) guid = user.get_guid() self.assertEqual(guid, data['guid'])
def test_empty_user(self): user = User() data = {'name': {'fullName': None, 'firstName': None, 'lastName': None}, 'uid': None, 'roles': [], 'stateCode': [], 'tenant': [], 'displayHome': False, 'guid': None} name = user.get_name() self.assertEqual(name, {'name': data['name']}) uid = user.get_uid() self.assertEqual(uid, data['uid']) context = user.get_user_context() self.assertEqual(context, data) roles = user.get_roles() self.assertEqual(roles, data['roles']) tenant = user.get_tenants() self.assertEqual(0, len(tenant)) guid = user.get_guid() self.assertIsNone(guid)
def test_get_user_context(self): user = User() data = { 'name': { 'fullName': 'Joe Doe', 'firstName': 'Joe', 'lastName': 'Doe' }, 'uid': 'joe.doe', 'roles': ['TEACHER'], 'tenant': 'dog', 'guid': '123' } user.set_name(data['name']) user.set_uid(data['uid']) user.set_guid(data['guid']) context = user.get_user_context() self.assertEqual(context['uid'], data['uid']) self.assertEqual(context['name'], data['name']) self.assertEqual(context['guid'], data['guid'])
def test_set_user_info(self): user = User() data = { 'name': { 'fullName': 'Joe Doe', 'firstName': 'Joe', 'lastName': 'Doe' }, 'uid': 'joe.doe', 'junk': 'junk', 'roles': ['TEACHER'], 'stateCode': [], 'tenant': 'dog', 'displayHome': False, 'guid': '123' } user.set_user_info(data) context = user.get_user_context() self.assertEqual(len(context), 7) self.assertEqual(context['name'], data['name']) self.assertEqual(context['uid'], data['uid']) self.assertEqual(context['guid'], data['guid']) self.assertEqual(context['displayHome'], data['displayHome'])
class Session: ''' Simple class that holds user session information, such as guid, user id, name, roles, and tenant ''' def __init__(self): self.__initialize_session() # leave datetime only this class, not save in session context self.__expiration = None self.__last_access = None # initialize all session values def __initialize_session(self): self.__session = {} self.__user = User() self.__session_id = None self.__session['idpSessionIndex'] = None self.__session['nameId'] = None # serialize to text def get_session_json_context(self): # Get User Info and combined the dictionary combined_context = self.__user.get_user_context() combined_context.update_session(self.__session) return json.dumps(combined_context) def get_session_id(self): return self.__session_id def get_uid(self): return self.__user.get_uid() def get_email(self): return self.__user.get_email() def get_roles(self): return self.__user.get_roles() def get_tenants(self): return self.__user.get_tenants() def get_guid(self): return self.__user.get_guid() def get_name(self): return self.__user.get_name() def get_idp_session_index(self): return self.__session['idpSessionIndex'] def get_name_id(self): return self.__session['nameId'] def get_last_access(self): return self.__last_access def get_expiration(self): return self.__expiration def get_user(self): return self.__user def set_session_id(self, session_id): ''' @param session_id: the session id ''' self.__session_id = session_id def set_uid(self, uid): ''' @param uid: the uid ''' self.__user.set_uid(uid) def set_email(self, email): ''' @param uid: the uid ''' self.__user.set_email(email) def set_user_context(self, context): self.__user.set_context(context) def set_guid(self, guid): ''' @param guid: the user guid to set ''' self.__user.set_guid(guid) def set_fullName(self, fullName): ''' @param fullName: the full name ''' self.__user.set_full_name(fullName) def set_lastName(self, lastName): ''' @param lastName: the last name ''' self.__user.set_last_name(lastName) def set_firstName(self, firstName): ''' @param firstName: the first name ''' self.__user.set_first_name(firstName) def set_idp_session_index(self, index): ''' @param index: the idp session index ''' self.__session['idpSessionIndex'] = index def set_name_id(self, name_id): ''' @param name_id: the name id ''' self.__session['nameId'] = name_id def set_session(self, session): self.__session = session self.__set_user(session) def set_expiration(self, datetime): self.__expiration = datetime def set_last_access(self, datetime): self.__last_access = datetime def __set_user(self, info): self.__user.set_user_info(info)