def test_invalid_token(register_login): # Setting up invalid token to be passed into user_profile. user = register_login u_id = user["u_id"] # token is invalid since token can only have numerical values. # Since token is invalid, function should raise an InputError. with pytest.raises(AccessError): user_profile(token_hash(2), u_id)
def test_invalid_uid(register_login): # Setting up invalid u_id to be passed into user_profile. user = register_login token = user["token"] u_id = 'invalid_uid' # u_id is invalid since u_id can only have numerical values. # Since u_id is invalid, function should raise an InputError. with pytest.raises(InputError): user_profile(token, u_id)
def standup_send(token, channel_id, message): """ standup_send Args: token: authorises user channel_id: the target channel to buffer a message to the active standup message: the message to buffer into the active standup """ print(token) print(channel_id) print(message) u_id = token_validator(token)['u_id'] channel_validator(channel_id) # Verify that the standup is currently active if not standup_active(token, channel_id)['is_active']: raise InputError("There is already a standup currently active") # Verify that the is under 1000 characters if len(message) > 1000: raise InputError("Message is more than 1000 characters") # Verifies that the user is a member of the channel channel_details(token, channel_id) handle_str = user_profile(token, u_id)['user']['handle_str'] standup.add_standup_queue(message, handle_str) return {}
def test_successful_edit_2(register_login): user = register_login token = user["token"] new_email = "*****@*****.**" user_profile_setemail(token, new_email) profile = user_profile(token_hash(0), user['u_id'])['user']['email'] assert profile == new_email auth_register("*****@*****.**", "password2", "Richard2", "Shen2") token2 = auth_login("*****@*****.**", "password2") new_email2 = "*****@*****.**" user_profile_setemail(token2['token'], new_email2) profile2 = user_profile(token_hash(0), token2['u_id'])['user']['email'] assert profile2 == new_email2
def user_profile_flask(): token = request.args.get('token') u_id = int(request.args.get('u_id')) result = u.user_profile(token, u_id) result['user']['profile_img_url'] = 'http://' + str( request.host) + '/profile_pictures/' + str( result['user']['profile_img_url']) return dumps(result)
def test_successful_edit(register_login): user = register_login token = user["token"] new_email = "*****@*****.**" user_profile_setemail(token, new_email) profile = user_profile(token_hash(0), user['u_id'])['user']['email'] assert profile == new_email
def test_valid_handle_str(register_login): # Setting up valid token to be passed into user_profile_sethandle. user = register_login token = user["token"] u_id = user["u_id"] profile = user_profile(token, u_id)['user'] # Current handle should be default concatenation of first and last name. current_handle = profile['handle_str'] assert current_handle == 'angusdoe' # handle_str will be valid since unique and between 3 & 20 characters. handle_str = 'test_new_handle' user_profile_sethandle(token, handle_str) # Since all inputs are valid, the users handle should be updated as # 'test_new_handle' new_handle = user_profile(token, u_id)['user']['handle_str'] assert new_handle == handle_str
def test_standup_send_1000(channel_with_user, standup): assert standup['is_active'] sender = channel_with_user valid_message = "*" * 1000 standup_send(sender['token'], sender['c_id'], valid_message) until_standup_finishes = 2 # seconds sleep(until_standup_finishes) messages = channel_messages(sender['token'], sender['c_id'], 0)['messages'] handle_str = user_profile(sender['token'], sender['u_id'])['user']['handle_str'] assert messages[0]['message'] == f"{handle_str}: {valid_message}"
def test_invalid_short(register_login): # Setting up valid token to be passed into user_profile_sethandle. user = register_login token = user["token"] u_id = user["u_id"] profile = user_profile(token, u_id)['user'] # Current handle should be default concatenation of first and last name. current_handle = profile['handle_str'] assert current_handle == 'angusdoe' # handle_str will be invalid as it is less than 3 characters handle_str = 'xd' # Since handle_str is too short, it should raise an input error with pytest.raises(InputError): user_profile_sethandle(token, handle_str)
def test_same_handle(register_login): # Setting up valid token to be passed into user_profile_sethandle. user = register_login token = user["token"] u_id = user["u_id"] profile = user_profile(token, u_id)['user'] # Current handle should be default concatenation of first and last name. current_handle = profile['handle_str'] assert current_handle == 'angusdoe' # handle_str will be invalid as current user already using that handle handle_str = 'angusdoe' # Since handle_str is already used, it should raise an input error with pytest.raises(InputError): user_profile_sethandle(token, handle_str)
def test_standup_send_multiple(channel_with_user, standup): assert standup['is_active'] sender = channel_with_user standup_send(sender['token'], sender['c_id'], "Test Message 1") standup_send(sender['token'], sender['c_id'], "Test Message 2") until_standup_finishes = 2 # seconds sleep(until_standup_finishes) messages = channel_messages(sender['token'], sender['c_id'], 0)['messages'] handle_str = user_profile(sender['token'], sender['u_id'])['user']['handle_str'] standup_messages = f"{handle_str}: Test Message 1\n" + f"{handle_str}: Test Message 2" assert messages[0]['message'] == standup_messages
def test_valid_setname(register_login): # Create previous user to test right user is changed register_login auth_register("*****@*****.**", "password", "John", "Boo") user = auth_login("*****@*****.**", "password") user_profile_setname(user['token'], 'Second', 'Boe') changed_user_info = user_profile(user['token'], user['u_id']) # Check if user information has changed assert [ changed_user_info['user']['name_first'], changed_user_info['user']['name_last'] ] == ['Second', 'Boe']
def test_standup_send_member(channel_with_user, standup): assert standup['is_active'] owner = channel_with_user # Login and register another user who will send the message auth_register('*****@*****.**', 'password', 'name_first', 'name_last') member = auth_login('*****@*****.**', 'password') channel_join(member['token'], owner['c_id']) standup_send(member['token'], owner['c_id'], "Member Message") until_standup_finishes = 2 # seconds sleep(until_standup_finishes) messages = channel_messages(member['token'], owner['c_id'], 0)['messages'] handle_str = user_profile(member['token'], member['u_id'])['user']['handle_str'] assert messages[0]['message'] == f"{handle_str}: Member Message"
def test_valid_user(register_login): # Setting up valid token and u_id to be passed into user_profile. user = register_login token = user["token"] u_id = user["u_id"] result = user_profile(token, u_id) # Since all inputs are valid, should return the users data. assert result == { 'user': { 'u_id': 1, 'email': '*****@*****.**', 'name_first': 'Angus', 'name_last': 'Doe', 'handle_str': 'angusdoe', 'permission_id': 2, 'profile_img_url': 'default.jpg' }, }