def test_sethandle_too_short(): login = auth.auth_register("*****@*****.**", "123456", "Hayden", "Jacobs") token = login['token'] with pytest.raises(InputError): user.user_profile_sethandle(token, "hj")
def test_handle_too_long(): clear() user = register_n_users(1) # set a long handle name with pytest.raises(InputError): user_profile_sethandle(user["token"], "Whymynamesolonghahahahhahahaha")
def test_handle_already_taken(): """ Tests with valid token and handle that is already in use. InputError will occur due to handle-already-in-use. """ server_data = Server_data() #Generate user 1 (Jessica) with automatically generated handle "jessicawu" user_1 = generate_user_1(server_data) user_1_token = user_1["token"] user_1_id = user_1["u_id"] handle_str = "jessicawu" #Generate user 2 (Patrick) for second call user_2 = generate_user_2(server_data) user_2_token = user_2["token"] user_2_id = user_2["u_id"] #Attempt to assign the same handle to a different user. #InputError will occur as the handle is already in use. with pytest.raises(InputError): user_profile_sethandle(server_data, user_2_token, handle_str) #Verify that neither user (User 1 and 2) were not affected by the previous #attempt to set an already-in-use handle to a different user. updated_user_1 = user_profile(server_data, user_1_token, user_1_id) assert updated_user_1["user"]["handle_str"] == "jessicawu" updated_user_2 = user_profile(server_data, user_2_token, user_2_id) assert updated_user_2["user"]["handle_str"] == "patrickmacalin"
def test_handle_too_short(): clear() user = register_n_users(1) # set a short handle name with pytest.raises(InputError): user_profile_sethandle(user["token"], "ha")
def test_invalid_handlestr_name_change(): """Passing an invalid handle change to user_profile_sethandle""" clear() new_user = auth_register("*****@*****.**", "password", "Clint", "Eastwood") with pytest.raises(InputError): user_profile_sethandle(new_user["token"], "ab")
def test_handle_is_in_use(): """Test case where handle is already in use""" clear() auth_register("*****@*****.**", "password", "Darth", "Vader") new_user2 = auth_register("*****@*****.**", "password", "Luke", "Skywalker") with pytest.raises(InputError): user_profile_sethandle(new_user2["token"], "darthva")
def test_handle_length_too_long(): """ test set handle with a handle string too long """ user = auth_register("*****@*****.**", "password", "Donald", "Trump") handle_str = "arealllyreallyreallyreallyreallyreallyreallyreallyreallylongname" with pytest.raises(InputError): user_profile_sethandle(user['token'], handle_str)
def test_user_sethandle_valid_handle(user1): """ Testing successful uses of user_profile_sethandle focusing on valid handles """ user.user_profile_sethandle(user1["token"], "newhandle") check_handle_changed(user1, "newhandle") other.clear()
def test_handle_length_too_short(): """ test set handle with handle string too short """ user = auth_register("*****@*****.**", "password", "Donald", "Trump") handle_str = "h" with pytest.raises(InputError): user_profile_sethandle(user['token'], handle_str)
def test_sethandle_ivt(): """ test set handle with invalid token """ auth_register("*****@*****.**", "password", "Donald", "Trump") handle_str = "Handle" with pytest.raises(AccessError): user_profile_sethandle('THISISNOTATOKEN', handle_str)
def test_sethandle_successful(): clear() user_a = register_n_users(1) # Set a new handle name as JOJOKING user_profile_sethandle(user_a["token"], "JOJOKING") user_a_profile = user_profile(user_a["token"], user_a["u_id"])["user"] assert user_a_profile["handle_str"] == "JOJOKING"
def test_sethandle_empty(): reset_data() login = auth.auth_register("*****@*****.**", "123456", "Hayden", "Jacobs") token = login['token'] with pytest.raises(InputError): user.user_profile_sethandle(token, "")
def test_valid_handle_change(): """Testing valid handle change""" clear() new_user = auth_register("*****@*****.**", "password", "Darth", "Vader") user_profile_sethandle(new_user["token"], "YourFather") assert user_profile(new_user["token"], new_user["u_id"] == \ {'user': {'email': '*****@*****.**', 'name_first': 'Darth', \ 'name_last': 'Vader', 'handle_str': 'YourFather'}})
def test_user_profile_sethandle_handle_str_short(): clear() user = auth_register('*****@*****.**', 'AO(Jmmnpassword', 'Korra', 'Sato') with pytest.raises(InputError): user_profile_sethandle(user['token'], 'A') with pytest.raises(InputError): user_profile_sethandle(user['token'], 'Ko')
def test_handle_str_invalid_token(): ''' Testing when the token is invalid. ''' clear() auth.auth_register("*****@*****.**", "password", "Firstname", "Lastname") with pytest.raises(error.AccessError): user.user_profile_sethandle("invalid", 'newhandel')
def test_user_profile_sethandle_invalid_input_too_long(): clear_data() #setup one user user_b = auth.auth_register('*****@*****.**', 'password123', 'Firstname', 'Lastname') #input with a too long handle with pytest.raises(InputError): user.user_profile_sethandle(user_b['token'], '123456789012345678901')
def test_user_profile_sethandle_handle_str_preexists(): clear() user1 = auth_register('*****@*****.**', 'AO(Jmmnpassword', 'Korra', 'Sato') user2 = auth_register('*****@*****.**', '23fhKndsi3', 'Assami', 'Sato') user_profile_sethandle(user1['token'], 'asato') with pytest.raises(InputError): user_profile_sethandle(user2['token'], 'asato')
def test_user_profile_sethandle_nonunique(get_users): jwang_token, jwang_u_id, kli_token = get_users[:3] user_profile_sethandle(jwang_token, "JoshuaWang") assert user_profile(jwang_token, jwang_u_id)["user"]["handle_str"] == "JoshuaWang" with pytest.raises(InputError): user_profile_sethandle(kli_token, "JoshuaWang")
def test_user_profile_sethandle_short_handle(): '''Test that checks if an exception is raised when the input handle is too short''' other.clear() test_user = auth.auth_register("*****@*****.**", "testpass", "Milhouse", "Houten") with pytest.raises(InputError): user.user_profile_sethandle(test_user['token'], "mi")
def user_profile_sethandle(): """ Function user profile sethandle route """ input_data = request.get_json() user.user_profile_sethandle(input_data['token'], input_data['handle_str']) return dumps({})
def test_sethandle_success(): login = auth.auth_register("*****@*****.**", "123456", "Hayden", "Jacobs") token = login['token'] user.user_profile_sethandle(token, "hjacobs") profile = user.user_profile(token, u_id) assert (profile['user']['handle_str'] == 'hjacobs')
def test_user_profile_sethandle_invalid_input_repeat(): clear_data() #setup one user user_c = auth.auth_register('*****@*****.**', 'password123', 'Firstname', 'Lastname') user.user_profile_sethandle(user_c['token'], 'handle123') #input with a used handle with pytest.raises(InputError): user.user_profile_sethandle(user_c['token'], 'handle123')
def test_handle_already_taken(): """ testing set handle if handle string is already taken """ user1 = auth_register("*****@*****.**", "password", "Donald", "Trump") user2 = auth_register("*****@*****.**", "password2", "Donald2", "Trump2") handle_str = "handle" user_profile_sethandle(user1['token'], handle_str) with pytest.raises(InputError): user_profile_sethandle(user2['token'], handle_str)
def test_handle_duplicate(): clear() # return two users with handle name below: user_a, user_b = register_n_users(2) # Get user_b's profile and we will use his handle as the duplicated handle user_b_profile = user_profile(user_b["token"], user_b["u_id"])["user"] with pytest.raises(InputError): user_profile_sethandle(user_a["token"], user_b_profile["handle_str"])
def test_user_sethandle_invalid_handle(user1): """ Testing unsuccessful uses of user_profile_sethandle focusing on invalid handles """ with pytest.raises(InputError): assert user.user_profile_sethandle(user1["token"], "abcdefghijklmnopqrstuvwxyz") assert user.user_profile_sethandle(user1["token"], "me") other.clear()
def test_user_profile_sethandle_working(): #create user details = auth_register("*****@*****.**", "password1", "Varun", "Kashyap") token = details['token'] uid = details['u_id'] assert (user_profile_sethandle(token, "handleOne") == {}) assert (user_profile_sethandle(token, "handleTwo") == {}) assert (user_profile(token, ["handle_str"] == "handleTwo"))
def test_sethandle_change(): reset_data() login = auth.auth_register("*****@*****.**", "123456", "Hayden", "Jacobs") token = login['token'] u_id = login['u_id'] user.user_profile_sethandle(token, "hjacobs") user.user_profile_sethandle(token, 'haydenj') profile = user.user_profile(token, u_id) assert profile['user']['handle_str'] == 'haydenj'
def test_profile_fail(): reset_data() login = auth.auth_register("*****@*****.**", "123456", "robbie", "caldwell") token = login['token'] u_id = login['u_id'] user.user_profile_sethandle(token, "Robbae01") with pytest.raises(InputError): user.user_profile(token, u_id + 1)
def test_valid_handle_length_20(): """ test edge case with handle string length of 20 """ user = auth_register("*****@*****.**", "password", "Donald", "Trump") handle_str = "ahandlewith20charsss" user_profile_sethandle(user['token'], handle_str) user_p = user_profile(user['token'], user['u_id']) assert user_p['user']['handle_str'] == "ahandlewith20charsss"
def test_valid_handle_length_3(): """ test edge case of handle string length of 3 """ user = auth_register("*****@*****.**", "password", "Donald", "Trump") handle_str = "one" # testing for 3 chars, function should work user_profile_sethandle(user['token'], handle_str) user_p = user_profile(user['token'], user['u_id']) assert user_p['user']['handle_str'] == "one"