def auth_logout(token): data = get_user_store() for user in data['users']: if user['token'] == token: user.pop('token') return True return False
def test_user_set_email(): # Call user set up get_user = set_up_user1_and_reset() get_user2 = set_up_user2() ############################################################ # Storing data test_token = get_user['token'] test_token2 = get_user2['token'] ######################################################### # Make a request to change the email of the users email_change_1 = requests.put(f"{BASE_URL}/user/profile/setemail", json={ 'token': test_token, 'email': '*****@*****.**', }) email_change_2 = requests.put(f"{BASE_URL}/user/profile/setemail", json={ 'token': test_token2, 'email': '*****@*****.**', }) # Call user database storage store = get_user_store() # Assert that for the correct user, the email has changed for user in store['users']: if user['token'] == test_token: assert user['email'] == '*****@*****.**' break for user in store['users']: if user['token'] == test_token2: assert user['email'] == '*****@*****.**'
def users_all(token): if not token_check(token): print('Token invalid') raise InputError user_store = get_user_store() user_dict = {'users': []} for indiv_user in user_store['users']: user_dict['users'].append({ 'u_id': indiv_user['u_id'], 'email': indiv_user['email'], 'name_first': indiv_user['name_first'], 'name_last': indiv_user['name_last'], 'handle_str': indiv_user['handle_str'], 'profile_img_url': indiv_user['profile_img_url'] }) return user_dict
def test_auth_login_valid(): result = False # Now we log him in token_holder = auth_login('*****@*****.**', 'worthwile') storage = get_user_store() for users in storage['users']: if users['token'] == token_holder['token']: result = True assert (result)
def test_auth(): requests.get(f"{BASE_URL}/reset") r = requests.post(f"{BASE_URL}/auth/register", json={ 'email': '*****@*****.**', 'password': '******', 'name_first' : 'hayden', 'name_last' : 'smith', }) payload = r.json() store = get_user_store() for x in store['users']: if x['email'] == '*****@*****.**': token = x['token'] id = x['id'] assert payload['u_id'] == id assert payload['token'] == token ############################################################ #storing data test_token = payload['token'] test_uid = payload['u_id'] ######################################################### r = requests.post(f"{BASE_URL}/auth/logout", json={ 'token': test_token }) payload = r.json() assert payload['is_success'] == True ########################################################################## r = requests.post(f"{BASE_URL}/auth/login", json={ 'email': '*****@*****.**', 'password': '******', }) payload = r.json() store = get_user_store() for x in store['users']: if x['email'] == '*****@*****.**': token = x['token'] assert payload['u_id'] == test_uid assert payload['token'] == token
def auth_register(email, password, name_first, name_last): if email_check(email) == False: raise InputError if email_dupe_check(email) == True: raise InputError if len(password) < 6: raise InputError if len(name_first) < 1 or len(name_first) > 50: raise InputError if len(name_last) < 1 or len(name_last) > 50: raise InputError user = add_user(email, password, name_first, name_last) token = login(user) data = get_user_store() for i in data['users']: if i['u_id'] == user['u_id']: i['token'] = token users = get_user_store() print(users) return {"u_id": user["u_id"], "token": token}
def auth_pw_reset(code, password): us = find_code(code) print('1') if us == False: print('in the if statement') raise InputError print('2') if len(password) < 6: raise InputError print('3') us['password'] = password print('4') del us['reset'] print(get_user_store()) print('5') return {}
def workspace_reset(): store = get_user_store() pemrission_store = get_permission_store() channel_store = get_channel_store() message_store = get_messages_store() store = { 'users': [] } channel_store = { 'Channels':[] } message_store = { 'Messages': [] } pemrission_store = {} return None
def auth_login(email, password): if not email_check(email): raise InputError if not email_dupe_check(email): raise InputError if not password_check(password): raise InputError user = find_email(email) token = login(user) data = get_user_store() for i in data['users']: if i['u_id'] == user['u_id']: i['token'] = token print("The person being logged in is") print(user) return {"u_id": user["u_id"], "token": token}
def test_user_set_name(): # Call user set up get_user = set_up_user1_and_reset() get_user2 = set_up_user2() ############################################################ # Storing data test_token = get_user['token'] test_token2 = get_user2['token'] ######################################################### # Make a request to change the name of the users name_change_1 = requests.put(f"{BASE_URL}/user/profile/setname", json={ 'token': test_token, 'name_first': 'Jonathan', 'name_last': 'Daniels', }) name_change_2 = requests.put(f"{BASE_URL}/user/profile/setname", json={ 'token': test_token2, 'name_first': 'Micheal', 'name_last': 'Hoffman', }) # Call user database storage store = get_user_store() # Assert that for the correct user, the name has changed for user in store['users']: if user['token'] == test_token: assert user['name_first'] == 'Jonathan' assert user['name_last'] == 'Daniels' break for user in store['users']: if user['token'] == test_token2: assert user['name_first'] == 'Micheal' assert user['name_last'] == 'Hoffman'
def test_user_set_handle(): # Call user set up get_user = set_up_user1_and_reset() get_user2 = set_up_user2() ############################################################ # Storing data test_token = get_user['token'] test_token2 = get_user2['token'] ######################################################### # Make a request to change the email of the users handle_change_1 = requests.put(f"{BASE_URL}/user/profile/sethandle", json={ 'token': test_token, 'handle_str': 'Covid', }) handle_change_2 = requests.put(f"{BASE_URL}/user/profile/sethandle", json={ 'token': test_token2, 'handle_str': 'Rickroll', }) # Call user database storage store = get_user_store() # Assert that for the correct user, the email has changed for user in store['users']: if user['token'] == test_token: assert user['handle_str'] == 'Covid' == handle_change_1[ 'handle_str'] break for user in store['users']: if user['token'] == test_token2: assert user['handle_str'] == 'Rickroll' == handle_change_2[ 'handle_str']