def test_user_name_lastInvalid_50(): clear_data() user4_token = 'tokenw' user4_last = '123456778812345677881234567788123456778812345677881234567788' user4_first = 'ccceu' with pytest.raises(InputError): user.user_profile_setname(user4_token, user4_first, user4_last)
def test_user_name_lastInvalid(): clear_data() user2_token = 'tokenw' user2_first = 'dfdfiui' user2_last = '' with pytest.raises(InputError): user.user_profile_setname(user2_token, user2_first, user2_last)
def test_user_name_firstInvalid(): clear_data() user1_token = 'tokenw' user1_first = '' user1_last = 'ccceu' with pytest.raises(InputError): user.user_profile_setname(user1_token, user1_first, user1_last)
def test_setname_invalid_token(initial_users): ''' test the token does not refer to any valid user ''' with pytest.raises(AccessError): user_profile_setname('invalid_token', 'new_first_name', 'new_last_name')
def test_user_profile_setname_updated_on_channel(): ''' Test that user's details get updated on the channel ''' other.clear() owner = auth.auth_register("*****@*****.**", "testpass", "First", "User") test_user = auth.auth_register("*****@*****.**", "password", "Notedited", "Alsonotedited") channel_1 = channels.channels_create(owner['token'], "Test Channel", True) channels.channels_create(owner['token'], "Test Channel 2", True) channel_3 = channels.channels_create(test_user['token'], "Test Channel 2", True) channel.channel_join(test_user['token'], channel_1['channel_id']) channel.channel_join(owner['token'], channel_3['channel_id']) details = channel.channel_details(test_user['token'], channel_1['channel_id']) owner_dict = { 'u_id': owner['u_id'], 'name_first': "First", 'name_last': "User", 'profile_img_url': "" } test_user_dict = { 'u_id': test_user['u_id'], 'name_first': "Notedited", 'name_last': "Alsonotedited", 'profile_img_url': "" } assert details == { 'name': 'Test Channel', 'owner_members': [owner_dict], 'all_members': [owner_dict, test_user_dict] } user.user_profile_setname(test_user['token'], "Newname", "Nowedited") user.user_profile_setname(owner['token'], "Firstedited", "Nowedited") details = channel.channel_details(test_user['token'], channel_1['channel_id']) owner_dict = { 'u_id': owner['u_id'], 'name_first': "Firstedited", 'name_last': "Nowedited", 'profile_img_url': "" } test_user_dict = { 'u_id': test_user['u_id'], 'name_first': "Newname", 'name_last': "Nowedited", 'profile_img_url': "" } assert details == { 'name': 'Test Channel', 'owner_members': [owner_dict], 'all_members': [owner_dict, test_user_dict] }
def test_invalid_token(): """ Attempts to set the name to a name that is valid with an invalid token. AccessError should occur. Verifies that the user details were not updated. """ server_data = Server_data() user_1 = generate_user_1(server_data) user_1_id = user_1["u_id"] #Set an invalid token. token = 0 name_first = "testfirstname" name_last = "testlastname" #InputError will occur because the token is not valid. with pytest.raises(AccessError): user_profile_setname(server_data, token, name_first, name_last) #Set token to valid token token = user_1["token"] #Verify that the name was not updated. updated_user = user_profile(server_data, token, user_1_id) assert updated_user["user"]["name_first"] == "Jessica" assert updated_user["user"]["name_last"] == "Wu"
def profile_setname(): data = request.get_json() token = str(data["token"]) name_first = str(data["name_first"]) name_last = str(data["name_last"]) user_profile_setname(token, name_first, name_last) return dumps({})
def test_valid_profile_setname(): # Test for some valid names # User 1: user1 = auth_register('*****@*****.**', 'haydEn123', 'Hayden', 'Smith') token = user1['token'] assert user_profile_setname(token, 'Hayden', 'Jacobs') == {} # User 2: user2 = auth_register('*****@*****.**', 'Abdullah1', 'Abdul', 'Ahmed') token = user2['token'] assert user_profile_setname(token, 'Abdullah', 'Mukhtar Ahmed') == {} # User 3: user3 = auth_register('*****@*****.**', 'Invalid1', 'Invalid' * 50, 'Dude') token = user3['token'] assert user_profile_setname(token, 'Valid', 'Dude') == {} # User 4: user4 = auth_register('*****@*****.**', 'JoePhysics1', 'Joe', 'Wolfe') token = user4['token'] assert user_profile_setname(token, 'JOE', 'WOOF') == {}
def test_too_long(): """ Attempts to set the names to a name that is too long InputError should occur. Verifies that the user details were not updated. """ server_data = Server_data() user_1 = generate_user_1(server_data) user_1_token = user_1["token"] user_1_id = user_1["u_id"] name_first = "ThisIsAnInvalidFirstNameThatIsTooLongForTestPurposesItShouldNotWork" #67 chars name_last = "ThisIsAnInvalidLastNameThatIsTooLongForTestPurposesItShouldNotWork" #66 chars #InputError will occur because # name_first is not between 1-50 chars in length (67 chars - too many) # name_last is not between 1-50 chars in length (66 chars - too many) with pytest.raises(InputError): user_profile_setname(server_data, user_1_token, name_first, name_last) #Verify that the name was not updated. updated_user = user_profile(server_data, user_1_token, user_1_id) assert updated_user["user"]["name_first"] == "Jessica" assert updated_user["user"]["name_last"] == "Wu"
def test_profile_setname_invalid_token(): clear() create_one_test_user() with pytest.raises(AccessError): user_profile_setname('invalid_token', "Jayden", "Haycob")
def test_user_profile_setname_change_firstname(): boyu_dict, _, _ = initialise_data() user_profile_setname(boyu_dict['token'], 'Boyu', 'He') # user user_profile to compare profile_dict = user_profile(boyu_dict['token'], boyu_dict['u_id']) assert profile_dict['user']['name_first'] == 'Boyu' assert profile_dict['user']['name_last'] == 'He'
def test_setname_empty(): ''' Testing when first and last name is empty. ''' clear() with pytest.raises(error.AccessError): user.user_profile_setname("user_token", "", "")
def test_user_profile_setname_name_last_short(): details = auth_register("*****@*****.**", "password1", "Varun", "Kashyap") token = details['token'] valid_first = "THISISAVALIDFIRSTNAME" with pytest.raises(InputError): user_profile_setname(token, "", valid_first)
def test_missing_last(): """ Attempts to set the last name to a name that is empty. InputError should occur. Verifies that the user details were not updated. """ server_data = Server_data() user_1 = generate_user_1(server_data) user_1_token = user_1["token"] user_1_id = user_1["u_id"] name_first = "testfirstname" name_last = "" #InputError will occur because # name_last is not between 1-50 chars in length (0 chars) with pytest.raises(InputError): user_profile_setname(server_data, user_1_token, name_first, name_last) #Verify that the name was not updated. updated_user = user_profile(server_data, user_1_token, user_1_id) assert updated_user["user"][ "name_first"] == "Jessica" #The name was set in the fixture. assert updated_user["user"][ "name_last"] == "Wu" #The name was set in the fixture.
def test_user_profile_setname_length_border(): workspace_reset() details = reg_user1() token = details['token'] string_50 = "a" * 50 string_1 = "a" payload1 = { 'token': details['token'], 'name_first': "ValidString", 'name_last': string_50 } payload2 = { 'token': details['token'], 'name_first': "ValidString", 'name_last': string_1 } payload3 = { 'token': details['token'], 'name_first': string_50, 'name_last': "ValidString" } payload4 = { 'token': details['token'], 'name_first': string_1, 'name_last': string_50 } assert (user_profile_setname(payload1) == {}) assert (user_profile_setname(payload2) == {}) assert (user_profile_setname(payload3) == {}) assert (user_profile_setname(payload4) == {})
def test_profile_setname_fname_short(): clear() test_user0 = create_one_test_user() # Invalid first name input - input is space with pytest.raises(InputError): user_profile_setname(test_user0['token'], " ", "valid_new_lname")
def test_setname_symbols(get_users): kli_token, kli_u_id = get_users[2:] user_profile_setname(kli_token, "Sue-Anne", "Stein-Holmes") kli_profile = user_profile(kli_token, kli_u_id)["user"] assert kli_profile["name_first"] == "Sue-Anne" assert kli_profile["name_last"] == "Stein-Holmes"
def test_setname_whitespaces(get_users): jwang_token, jwang_u_id = get_users[:2] user_profile_setname(jwang_token, "Sue Anne", "Stein Holmes") jwang_profile = user_profile(jwang_token, jwang_u_id)["user"] assert jwang_profile["name_first"] == "Sue Anne" assert jwang_profile["name_last"] == "Stein Holmes"
def test_setname_upperlower(get_users): jwang_token, jwang_u_id = get_users[:2] user_profile_setname(jwang_token, "jOnaThAn", "WeMbleYeYEYEY") jwang_profile = user_profile(jwang_token, jwang_u_id)["user"] assert jwang_profile["name_first"] == "jOnaThAn" assert jwang_profile["name_last"] == "WeMbleYeYEYEY"
def test_user_profile_setname(get_users): kli_token, kli_u_id = get_users[2:] user_profile_setname(kli_token, "Kenneth", "Lithium") kli_profile = user_profile(kli_token, kli_u_id)["user"] assert kli_profile["name_first"] == "Kenneth" assert kli_profile["name_last"] == "Lithium"
def test_profile_setname_invalid_lname_long(): clear() test_user0 = create_one_test_user() # Invalid last name input - more than 50 characters with pytest.raises(InputError): user_profile_setname(test_user0['token'], "valid_new_fname", "A" * 51)
def test_name_first_too_long(): """ testing setname first name too long """ user = auth_register("*****@*****.**", "password", "Donald", "Trump") first_name = "arealllyreallyreallyreallyreallyreallyreallyreallyreallylongname" with pytest.raises(InputError): user_profile_setname(user['token'], first_name, "Trump")
def test_setname_info_updates_for_other_users(get_users): jwang_token, jwang_u_id, kli_token, kli_u_id = get_users # pylint: disable=unused-variable user_profile_setname(kli_token, " _D_ ", " ?E-utschl@nd ") kli_profile = user_profile(jwang_token, kli_u_id)["user"] assert kli_profile["name_first"] == " _D_ " assert kli_profile["name_last"] == " ?E-utschl@nd "
def test_user_profile_setname_name_both_short(): workspace_reset() details = reg_user1() payload = {'token': details['token'], 'name_first': "", 'name_last': ""} with pytest.raises(InputError): user_profile_setname(payload)
def test_name_first_too_short(): """ testing first name too short """ user = auth_register("*****@*****.**", "password", "Donald", "Trump") first_name = "" with pytest.raises(InputError): user_profile_setname(user['token'], first_name, "Trump")
def test_setname_allsymbols(get_users): kli_token, kli_u_id = get_users[2:] user_profile_setname(kli_token, "@#$%^&*(", ")(*&^%$#$%") kli_profile = user_profile(kli_token, kli_u_id)["user"] assert kli_profile["name_first"] == "@#$%^&*(" assert kli_profile["name_last"] == ")(*&^%$#$%"
def test_setname_manywhitespaces(get_users): kli_token, kli_u_id = get_users[2:] user_profile_setname(kli_token, " _D_ ", " ?E-utschl@nd ") kli_profile = user_profile(kli_token, kli_u_id)["user"] assert kli_profile["name_first"] == " _D_ " assert kli_profile["name_last"] == " ?E-utschl@nd "
def test_profile_setname_ivt(): """ testing setname invalid token """ auth_register("*****@*****.**", "password", "Donald", "Trump") first_name = "Donald" with pytest.raises(AccessError): user_profile_setname('THISISNOTATOKEN', first_name, "Trump")
def test_set_name_exactly_fifty(get_users): jwang_token, jwang_u_id = get_users[:2] user_profile_setname(jwang_token, "f" * 50, "l" * 50) assert user_profile(jwang_token, jwang_u_id)["user"]["name_first"] == "f" * 50 assert user_profile(jwang_token, jwang_u_id)["user"]["name_last"] == "l" * 50
def test_user_profile_setname_short_lasttname(): '''Test that checks if an exception is raised when last name is shorter than 1 character''' other.clear() test_user = auth.auth_register("*****@*****.**", "testpass", "Milhouse", "Houten") with pytest.raises(InputError): user.user_profile_setname(test_user['token'], "Thrillhouse", "")