def test_reset(): 'testing functionability of passwordreset request' workspace_reset() reset_store = get_reset_code_store() reg_user1() auth.request({'email': '*****@*****.**'}) for i in reset_store: if i['email'] == '*****@*****.**': code = i['reset_code'] auth.reset({'reset_code': code, 'new_password': '******'}) auth_store = get_auth_data_store() password_check = 0 #if new password is in auth store let = 1 for i in auth_store: if i['password'] == 'thisiscool': password_check = 1 assert password_check == 1
def test_bad_token(): ''' Test logout on a bad token ''' reset_auth_store() reg_user1() user2 = reg_user2() auth.logout(user2) assert auth.logout(user2) == False
def test_invalid_password(): 'error case' workspace_reset() reg_user1() reset_code = id_generator() auth.request({'email': '*****@*****.**'}) with pytest.raises(InputError): auth.reset({'reset_code': reset_code, 'new_password': '******'})
def test_invalid_resetcode(): 'error case' workspace_reset() reg_user1() auth.request({'email': '*****@*****.**'}) with pytest.raises(InputError): auth.reset({ 'reset_code': 'ABCD', 'new_password': '******' }) #pylint disable = C0304
def test_unreact(): ''' Test a valid case of message_unreact to a message someone else had sent ''' workspace_reset() user1 = reg_user1() user2 = reg_user2() channel1 = create_ch1(user1) invite_to_ch1(user1, user2, channel1) msg1 = send_msg1(user1, channel1) # react to the message react_to_msg(1, msg1, user2) payload = { 'token': user2['token'], 'message_id': msg1['message_id'], 'react_id': 1 } message.unreact(payload) message1_reacts = find_message(msg1['message_id'])['reacts'] for i in message1_reacts: if i['react_id'] == 1: assert user2['u_id'] not in i['u_ids']
def test_user_profile_setname_working(): workspace_reset() details = reg_user1() token = details['token'] uid = details['u_id'] #do some tests to test that everying is running fine #initially the user's name is varun kashyap, and is changed to jeff jefferson name_first2 = "Jeff" name_last2 = "Jefferson" payload5 = { 'token': details['token'], 'name_first': name_first2, 'name_last': name_last2 } assert (user_profile_setname(payload5) == {}) payload3 = {'token': details['token'], 'u_id': details['u_id']} profile2 = user_profile(payload3) assert (profile2['name_first']) == name_first2 assert (profile2['name_last']) == name_last2
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_user_profile_sethandle_length(): workspace_reset() string_3 = "aaa" string_20 = "x" * 20 string_2 = "aa" string_21 = "q" * 21 string_long = "w" * 50 details = reg_user1() token = details['token'] uid = details['u_id'] assert (user_profile_sethandle(token, string_3) == {}) #check handle has been changed assert (user_profile(token, ["handle_str"] == string_3)) assert (user_profile_sethandle(token, string_20) == {}) assert (user_profile(token, ["handle_str"] == string_20)) with pytest.raises(InputError): user_profile_sethandle(token, string_2) with pytest.raises(InputError): user_profile_sethandle(token, string_21) with pytest.raises(InputError): user_profile_sethandle(token, string_long)
def test_logout1(): ''' Test a valid use case of auth.logout ''' reset_auth_store() user1 = reg_user1() assert auth.logout(user1) == True
def test_user_profile_sethandle_already_used(): workspace_reset() details1 = reg_user1() token1 = details1['token'] uid1 = details1['u_id'] details2 = reg_user2() token2 = details2['token'] uid2 = details2['u_id'] valid_handle = "ValidHandle" #test handle already used payload1 = {'token': token1, 'handle_str': valid_handle} payload2 = {'token': token1, 'u_id': uid1} payload3 = {'token': token2, 'handle_str': valid_handle} user_profile_sethandle(payload1) assert (user_profile(payload2) == {}) with pytest.raises(InputError): user_profile_sethandle(payload3)
def test_user_profile_setemail_invalidEmail(): #create some users workspace_reset() details = reg_user1() token = details['token'] uid = details['u_id'] #function will fail if the email provided is invalid payload1 = {'token': token, 'email': "@gmail.com"} payload2 = {'token': token, 'email': "[email protected]"} payload3 = {'token': token, 'email': "new_email@gmail."} payload4 = {'token': token, 'email': "new_emailgmail.com"} # No prefix with pytest.raises(InputError): user_profile_setemail(payload1) # No suffix with pytest.raises(InputError): user_profile_setemail(payload2) # No .com with pytest.raises(InputError): user_profile_setemail(payload3) # no @ with pytest.raises(InputError): user_profile_setemail(payload4)
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_profile_invalid_uID2(): workspace_reset() details = reg_user1() payload = {'token': details['token'], 'u_id': "22tt3t3tt3r4r"} with pytest.raises(InputError): user_profile(payload)
def test_profile_invalid_uID3(): workspace_reset() details = reg_user1() payload = {'token': details['token'], 'u_id': "126261261----22322323"} with pytest.raises(InputError): user_profile(payload)
def test_request(): 'testing functionability of passwordreset request' workspace_reset() reg_user1() #pylint disable = W0612 auth.request({'email': '*****@*****.**'}) reset_store = get_reset_code_store() email_match = 0 #if found = 1 for i in reset_store: if i['email'] == '*****@*****.**': email_match = 1 assert email_match == 1 #pylint disable = R0123
def test_invalid_email_login(): ''' Test login if provided an invalid login ''' reset_auth_store() user1 = reg_user1() auth.logout({'token': user1['token']}) with pytest.raises(InputError): auth.login({'email': 'Kennan@com', 'password': '******'})
def test_profile_invalid_uID1(): workspace_reset() details = reg_user1() payload = {'token': details['token'], 'u_id': "NOT_VALID_UID"} with pytest.raises(InputError): user_profile(payload)
def test_wrong_pass(): ''' Test login if provided with an incorrect pass ''' reset_auth_store() user1 = reg_user1() auth.logout({'token': user1['token']}) with pytest.raises(InputError): auth.login({'email': '*****@*****.**', 'password': '******'})
def test_invalid_msg_id(): ''' Test reacting with an invalid message id ''' workspace_reset() user1 = reg_user1() payload = {'token': user1['token'], 'message_id': 1, 'react_id': 1} with pytest.raises(InputError): message.react(payload)
def test_user_profile_setname_invalidToken(): workspace_reset() details = reg_user1() payload = { 'token': "INVALID", 'name_first': "THISISAVALIDNAME", 'name_last': "ValidName" } with pytest.raises(InputError): user_profile_setname(payload)
def test_invalid_userid(): 'Invalid user case' workspace_reset() user1 = reg_user1() token1 = user1['token'] # Invalid user_id = 100 payload = {'token': token1, 'u_id': 100} # InputError when trying to remove user from slackr with invalid user ID with pytest.raises(InputError) as e: user_remove(payload)
def test_invalid_name(): 'error case for channels create' workspace_reset() user1 = reg_user1() payload = { 'token': user1['token'], 'name': 'Thisnameislongerthan20characters', 'is_public': True } with pytest.raises(InputError): channels.create(payload)
def test_login1(): ''' Test basic functionality of login ''' reset_auth_store() user1 = reg_user1() auth.logout({'token': user1['token']}) assert auth.login({ 'email': '*****@*****.**', 'password': '******' })['token'] == user1['token']
def test_user_profile_sethandle_working(): #create user workspace_reset() details = reg_user1() 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_create(): 'testing functionability of channels create' workspace_reset() user1 = reg_user1() payload = {'token': user1['token'], 'name': 'Slackrs', 'is_public': True} result1 = channels.create(payload) channel_store = get_channel_data_store() assert result1 in channel_store
def test_admin_user_remove_successful1(): 'Successful case with registering' workspace_reset() user1 = reg_user1() token1 = user1['token'] u_id1 = user1['u_id'] user2 = reg_user2() token2 = user2['token'] u_id2 = user2['u_id'] payload = {'token': token1, 'u_id': u_id2} # Remove user1 from slackr user_remove(payload)
def test_invalid_msg_id(): ''' Test unreacting with an invalid message id ''' workspace_reset() user1 = reg_user1() channel1 = create_ch1(user1) msg1 = send_msg1(user1, channel1) react_to_msg(1, msg1, user1) payload = {'token': user1['token'], 'message_id': 2, 'react_id': 1} with pytest.raises(InputError): message.unreact(payload)
def test_user_profile_setname_name_last_short(): workspace_reset() details = reg_user1() valid_first = "THISISAVALIDFIRSTNAME" payload = { 'token': details['token'], 'name_first': valid_first, 'name_last': "" } with pytest.raises(InputError): user_profile_setname(payload)
def test_unauthorised_slackr(): 'Authorised user is not an owner of slackr case' workspace_reset() user1 = reg_user1() u_id1 = user1['u_id'] user2 = reg_user2() token2 = user2['token'] payload = {'token': token2, 'u_id': u_id1} if not check_owner_slackr(token2): # AccessError when authorised user isn't an owner and tries to remove someone from the # slackr with pytest.raises(AccessError) as e: user_remove(payload)
def test_user_profile_setname_name_last_long(): workspace_reset() details = reg_user1() token = details['token'] string_51 = "a" * 51 payload = { 'token': details['token'], 'name_first': "THISISAVALIDNAME", 'name_last': string_51 } with pytest.raises(InputError): user_profile_setname(payload)