def test_user_profile_setemail(): reset_data() #SETUP Begin authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith") auth_login("*****@*****.**", "qwerty") token1 = authRegDict1['token'] auth_register("*****@*****.**", "qwerty", "John", "Smith") #SETUP End #Test Case 1: Successful update of user's email user_profile_setemail(token1, "*****@*****.**") #Test Case 2: Unsuccessful update of user email because the email not change with pytest.raises(ValueError): user_profile_setemail(token1, "*****@*****.**") #Test Case 3: Unsuccessful update of user email due to conflict with existing email with pytest.raises(ValueError): user_profile_setemail(token1, "jim.gmail.com") #Test Case 3: Unsuccessful update of user email because the email has been used with pytest.raises(ValueError): user_profile_setemail(token1, "*****@*****.**") auth_logout(token1) reset_data()
def test_channels_list(): reset_data() # SETUP BEGIN # Assume all users have registered in function: test_channel_invite() auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic1 = auth_login("*****@*****.**", "123456") token1 = auth_dic1['token'] auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic2 = auth_login("*****@*****.**", "123456") token2 = auth_dic2['token'] channels_create(token1, "channel 1", True) # SETUP END # successful test channels_list(token1) assert channels_list(token2) == {'channels': []} # logout auth_logout(token1) auth_logout(token2) reset_data()
def test_message_unpin(): reset_data() # SETUP BEGIN authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden', 'Diego') auth_login('*****@*****.**', '123456') token1 = authRegisterDict1['token'] authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally', 'Juan') auth_login('*****@*****.**', '123456') token2 = authRegisterDict2['token'] authRegisterDict3 = auth_register('*****@*****.**', '123456', 'Nena', 'Smith') auth_login('*****@*****.**', '123456') token3 = authRegisterDict3['token'] authRegisterDict4 = auth_register('*****@*****.**', '123456', 'Carmen', 'Davis') auth_login('*****@*****.**', '123456') token4 = authRegisterDict4['token'] channelidDict1 = channels_create(token1, 'channel_1', True) channel_id1 = channelidDict1['channel_id'] channel_join(token2, channel_id1) messages_dic1 = message_send(token1, channel_id1, "hello") message_id1 = messages_dic1['message_id'] messagedic2 = message_send(token1, channel_id1, "helloooo") message_id2 = messagedic2['message_id'] message_pin(token1, message_id1) message_pin(token1, message_id2) # SETUP END # The right example assert message_unpin(token1, message_id1) == {} with pytest.raises(ValueError): # message_id 8 is not a valid message message_unpin(token1, 8) with pytest.raises(ValueError): # The authorised user token2 is not an admin message_unpin(token2, message_id2) with pytest.raises(ValueError): # Message message_1 is already unpinned message_unpin(token1, message_id1) with pytest.raises(AccessError): # The authorised user is not a member of the channel that the message is within message_unpin(token3, message_id2) # logout auth_logout(token1) auth_logout(token2) auth_logout(token3) auth_logout(token4) reset_data()
def test_user_profile_setname(): reset_data() #SETUP Begin authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith") auth_login("*****@*****.**", "qwerty") token1 = authRegDict1['token'] #SETUP End #Test Case 1: successful update of authorised user's first and last name user_profile_setname(token1, "Jim", "Smiths") #Test Case 2: Successful update of user's first and last name # containing allowed non-alphabetical character user_profile_setname(token1, "Karl-Anthony", "Towns") #Test Case 3 Unsuccessful update of user's first and last name # due to first name exceeding character limit with pytest.raises(ValueError, match='Invalid first name length'): user_profile_setname(token1, "a" * 51, "Smith") #Test Case 4: Unsuccessful update of first and last name due to last name exceeding limit with pytest.raises(ValueError, match='Invalid last name length'): user_profile_setname(token1, "John", "a" * 51) auth_logout(token1) reset_data()
def test_auth_login(): ''' assumption: [email protected] is the only registered email. 2.all the value errors have been modified into specfic words. ''' reset_data() #successful test user_dic = auth_register('*****@*****.**', '1q2w3e4r', 'HAHA', 'JIANG') login_dic = auth_login('*****@*****.**', '1q2w3e4r') assert user_dic['u_id'] == login_dic['u_id'] token = login_dic['token'] #test1: login with invalid email: with pytest.raises(ValueError, match=r'Invalid email'): auth_login('wrongemail.com', '1q2w3e4r') #test2: login with email which doesn't belong to a user: with pytest.raises(ValueError, match=r'Email entered does not belong to a user'): auth_login("*****@*****.**", "123456") #test3: login with a user's email but the password is wrong: with pytest.raises(ValueError, match=r'Password incorrect'): auth_login('*****@*****.**', 'wrongpassword') auth_logout(token) reset_data()
def test_channels_create(): reset_data() # SETUP BEGIN # Assume all users have registered in function: test_channel_invite() auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic1 = auth_login("*****@*****.**", "123456") token1 = auth_dic1['token'] auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic2 = auth_login("*****@*****.**", "123456") token2 = auth_dic2['token'] # SETUP END # successful test # assume the channelid is 1 assert channels_create(token1, "channel 1", True) == {'channel_id': 0} with pytest.raises(ValueError): # Name is more than 20 characters long channels_create(token1, "qwertyuiopasdfghjklzxcvbnmqwertyuiop", True) # logout auth_logout(token1) auth_logout(token2) reset_data()
def test_user_profiles_uploadphoto(): reset_data() #SETUP Begin - initialisation of variables for calling the function authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith") auth_login("*****@*****.**", "qwerty") token1 = authRegDict1['token'] # successful test user_profiles_uploadphoto( token1, "https://www.flowerglossary.com/wp-content/uploads/2019/04/blue-rose.jpg", 0, 0, 100, 100, 5001) # error test # Image uploaded is not a JPG. with pytest.raises(ValueError): user_profiles_uploadphoto(token1, "https://www.baidu.com", 0, 0, 10, 10, 5001) # any of x_start, y_start, x_end, y_end are not within the dimensions of the image at the URL. with pytest.raises(ValueError): user_profiles_uploadphoto( token1, "https://www.flowerglossary.com/wp-content/uploads/2019/04/blue-rose.jpg", 10, 10, 0, 0, 5001) auth_logout(token1)
def test_user_profile_sethandle(): reset_data() #SETUP Begin authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith") token1 = authRegDict1['token'] auth_login("*****@*****.**", "qwerty") authRegDict2 = auth_register("*****@*****.**", "qwerty1", "Johnn", "Smithh") token2 = authRegDict2['token'] auth_login("*****@*****.**", "qwerty1") #SETUP End #Test Case 1: Successful update of user's display name user_profile_sethandle(token1, "jsmith") #Test Case 2: Unsuccessful update of user's display name due to exceeding of character limit with pytest.raises(ValueError, match='Display name exceeds character limit'): user_profile_sethandle(token1, 'jsmith12345678dfghnmdfghj90qwerty') #Test Case 3: Unsuccessful update of user's display name because the handle is too short with pytest.raises(ValueError): user_profile_sethandle(token1, 'j') #Test Case 4: Unsuccessful update of user's display name due to it containing an offensive word with pytest.raises(ValueError): user_profile_sethandle(token2, 'jsmith') #User accidentally includes offensive word auth_logout(token1) auth_logout(token2) reset_data()
def test_standup_active(): reset_data() #SETUP Begin authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith") token1 = authRegDict1['token'] channelCreateDict1 = channels_create(token1, 'New Channel', True) channel_id1 = channelCreateDict1['channel_id'] authRegDict2 = auth_register("*****@*****.**", "asdfgh", "Jim", "Smith") token2 = authRegDict2['token'] assert standup_active(token1, channel_id1) == {'is_active' : False, 'time_finish' : None} standup_start(token1, channel_id1, 5) standup_dic = standup_active(token1, channel_id1) assert standup_dic['is_active'] with pytest.raises(ValueError): standup_active(token1, 10) with pytest.raises(AccessError): standup_active(token2, channel_id1) auth_logout(token1) auth_logout(token2)
def test_search(): ''' assumption: [email protected] is the only registered email for now. 2.all the value errors have been modified into specfic words. 3.the channel called "channelname" hasn't been created ''' #successful test: #login reset_data() auth_register('*****@*****.**', 'q1w2e3r4', 'BEAR', 'XI') login1_dic = auth_login('*****@*****.**', 'q1w2e3r4') token = login1_dic['token'] #create a channel channelValue = channels_create(token, "channelname", True) channel_id = channelValue['channel_id'] #sending a message message_send(token, channel_id, "1q2w3e4r") #search messages_dic = search(token, "1q") assert messages_dic['messages'][0]['message'] == "1q2w3e4r" #logout auth_logout(token) reset_data()
def test_channels_listall(): reset_data() # SETUP BEGIN # Assume all users have registered in function: test_channel_invite() auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic1 = auth_login("*****@*****.**", "123456") token1 = auth_dic1['token'] auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic2 = auth_login("*****@*****.**", "123456") token2 = auth_dic2['token'] channels_create(token1, "channel 1", True) # SETUP END # successful test # because it output all channel, whatever the user is, the output should be same assert channels_listall(token1) == channels_listall(token2) # just for check # logout auth_logout(token1) auth_logout(token2) reset_data()
def test_message_send(): reset_data() # SETUP BEGIN authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden', 'Diego') auth_login('*****@*****.**', '123456') token1 = authRegisterDict1['token'] authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally', 'Juan') auth_login('*****@*****.**', '123456') token2 = authRegisterDict2['token'] channelidDict1 = channels_create(token1, 'channel_1', True) channel_id1 = channelidDict1['channel_id'] channelidDict2 = channels_create(token2, 'channel_8', True) channel_id2 = channelidDict2['channel_id'] # SETUP END # The right example message_send(token1, channel_id1, 'hello') # error test with pytest.raises(ValueError): # Message is more than 1000 characters message_send(token1, channel_id1, 'a' * 1001) with pytest.raises(AccessError): # token1 has not joined Channel channel_id2 message_send(token1, channel_id2, 'hello') # logout auth_logout(token1) auth_logout(token2) reset_data()
def test_message_edit(): reset_data() # SETUP BEGIN authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden', 'Diego') auth_login('*****@*****.**', '123456') token1 = authRegisterDict1['token'] authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally', 'Juan') auth_login('*****@*****.**', '123456') token2 = authRegisterDict2['token'] authRegisterDict3 = auth_register('*****@*****.**', '123456', 'Nena', 'Smith') auth_login('*****@*****.**', '123456') token3 = authRegisterDict3['token'] authRegisterDict4 = auth_register('*****@*****.**', '123456', 'Carmen', 'Davis') auth_login('*****@*****.**', '123456') token4 = authRegisterDict4['token'] channelidDict1 = channels_create(token1, 'channel_1', True) channel_id1 = channelidDict1['channel_id'] channel_join(token2, channel_id1) messages_dic1 = message_send(token1, channel_id1, "hello") message_id1 = messages_dic1['message_id'] # SETUP END # The right example # Assume the message id 1 is a valid id for user1 assert message_edit(token1, message_id1, 'hello') == {} with pytest.raises(ValueError): # Assume Message id 2 does not exist message_edit(token1, 10, 'hello') with pytest.raises(ValueError): # Message is more than 1000 characters message_edit(token1, message_id1, 'a' * 1001) with pytest.raises(AccessError): # message_id1 was not sent by the authorised user token2 making this request message_edit(token2, message_id1, 'hello') with pytest.raises(AccessError): # token3 is not an owner of this channel message_edit(token3, message_id1, 'hello') with pytest.raises(AccessError): # token4 is not an admin or owner of the slack message_edit(token4, message_id1, 'hello') # logout auth_logout(token1) auth_logout(token2) auth_logout(token3) auth_logout(token4) reset_data()
def test_users_all(): reset_data() authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith") token1 = authRegDict1['token'] auth_login("*****@*****.**", "qwerty") # successful test users_all(token1) auth_logout(token1) reset_data()
def test_channel_invite(): reset_data() # SETUP BEGIN auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic1 = auth_login("*****@*****.**", "123456") token1 = auth_dic1['token'] uid1 = auth_dic1['u_id'] auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic2 = auth_login("*****@*****.**", "123456") token2 = auth_dic2['token'] uid2 = auth_dic2['u_id'] auth_dic3 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic3 = auth_login("*****@*****.**", "123456") token3 = auth_dic3['token'] channelid_dic1 = channels_create(token1, "channel 1", True) channel_id1 = channelid_dic1['channel_id'] channelid_dic2 = channels_create(token1, "channel 2", True) channel_id2 = channelid_dic2['channel_id'] # SETUP END # successful test assert channel_invite(token1, channel_id1, uid2) == {} # error test with pytest.raises(ValueError): # the channel if does not exist channel_invite(token1, 10, uid2) with pytest.raises(AccessError): # channel_id does not refer to a valid channel that the authorised user is part of. channel_invite(token3, channel_id2, uid2) with pytest.raises(ValueError): # u_id does not refer to a valid user # assume u_id 5 does not refer to a valid user channel_invite(token1, channel_id1, 10) with pytest.raises(ValueError): # u_id does not refer to a valid user # invite the user that is in channel (by calling function above, uid2 is in channel) channel_invite(token2, channel_id1, uid1) # logout auth_logout(token1) auth_logout(token2) auth_logout(token3) reset_data()
def test_message_react(): reset_data() # SETUP BEGIN authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden', 'Diego') auth_login('*****@*****.**', '123456') token1 = authRegisterDict1['token'] authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally', 'Juan') auth_login('*****@*****.**', '123456') token2 = authRegisterDict2['token'] authRegisterDict3 = auth_register('*****@*****.**', '123456', 'Nena', 'Smith') auth_login('*****@*****.**', '123456') token3 = authRegisterDict3['token'] authRegisterDict4 = auth_register('*****@*****.**', '123456', 'Carmen', 'Davis') auth_login('*****@*****.**', '123456') token4 = authRegisterDict4['token'] channelidDict1 = channels_create(token1, 'channel_1', True) channel_id1 = channelidDict1['channel_id'] channel_join(token2, channel_id1) messages_dic1 = message_send(token1, channel_id1, "hello") message_id1 = messages_dic1['message_id'] # SETUP END # The right example # message_id1 is a valid message for user1 # assume the react id 1 is a valid id assert message_react(token1, message_id1, 1) == {} # error example with pytest.raises(ValueError): # assume message_id 2 is not a valid message message_react(token1, 2, 1) with pytest.raises(ValueError): # assume react_id id 3 is not a valid React ID message_react(token1, message_id1, 3) with pytest.raises(ValueError): # message_id 1 already contains an active React with react_id 1 message_react(token1, message_id1, 1) with pytest.raises(ValueError): # user3 is not a member of channel which contain messageid1 message_react(token3, message_id1, 1) # logout auth_logout(token1) auth_logout(token2) auth_logout(token3) auth_logout(token4)
def test_auth_logout(): ''' assumption: [email protected] is the only registered email. 2.all the value errors have been modified into specfic words. ''' #successful test auth_register('*****@*****.**', 'q1w2e3r4', 'BEAR', 'XI') login_dic = auth_login('*****@*****.**', 'q1w2e3r4') assert auth_logout(login_dic['token']) == {'is_success': True} reset_data()
def test_message_sendlater(): reset_data() # SETUP BEGIN authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden', 'Diego') auth_login('*****@*****.**', '123456') token1 = authRegisterDict1['token'] authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally', 'Juan') auth_login('*****@*****.**', '123456') token2 = authRegisterDict2['token'] channelidDict1 = channels_create(token1, 'channel_1', True) channel_id1 = channelidDict1['channel_id'] channelidDict2 = channels_create(token2, 'channel_8', True) channel_id2 = channelidDict2['channel_id'] # SETUP END # The right example ''' later_time = datetime.datetime.utcnow() + datetime.timedelta(seconds=50) str_later_time = later_time.strftime("%Y-%m-%d %H:%M:%S") timeArray = time.strptime(str_later_time, "%Y-%m-%d %H:%M:%S") timestamp = time.mktime(timeArray) print(timestamp) ''' timestamp = int(datetime.datetime.now().strftime("%s")) + 3 mid = message_sendlater(token1, channel_id1, 'hello', timestamp) assert mid['message_id'] == 1 # error example with pytest.raises(ValueError): # Message is more than 1000 characters message_sendlater(token1, channel_id1, 'a' * 1001, 1603066156) with pytest.raises(ValueError): # Assume Channel channel_id 3 does not exist (not valid channel) message_sendlater(token1, 3, 'hello', 1603066156) with pytest.raises(ValueError): # Assume Time 2018-10-01 00:09:06 is a time in the past (1538352546 in Timestamp) message_sendlater(token1, channel_id1, 'hello', 1538352546) with pytest.raises(AccessError): # token1 has not joined Channel channel_id2 message_sendlater(token1, channel_id2, 'hello', 1603066156) # logout auth_logout(token1) auth_logout(token2) reset_data()
def test_admin_userpermission_change(): ''' assumption: [email protected] is the only registered email for now. 2.all the value errors have been modified into specfic words. 3.there is a permission id dictionary which contains 3 different types of permission id. [email protected] hasn't been registered. ''' #successful test: reset_data() auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic1 = auth_login("*****@*****.**", "123456") token1 = auth_dic1['token'] uid1 = auth_dic1['u_id'] auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic2 = auth_login("*****@*****.**", "123456") token2 = auth_dic2['token'] uid2 = auth_dic2['u_id'] auth_dic3 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic3 = auth_login("*****@*****.**", "123456") token3 = auth_dic3['token'] assert admin_userpermission_change(token1, uid2, 1) == {} #test1:u_id does not refer to a valid user with pytest.raises(ValueError): admin_userpermission_change(token1, 10, 1) #test2:permission_id does not refer to a value permission with pytest.raises( ValueError, match=r'permission_id does not refer to a value permission'): admin_userpermission_change(token1, uid2, 10) #test3:The authorised user is not an admin or owner with pytest.raises(AccessError, match=r'the authorised user is not an admin or owner'): admin_userpermission_change(token3, uid1, 1) auth_logout(token1) auth_logout(token2) auth_logout(token3) reset_data()
def test_channel_messages(): reset_data() # SETUP BEGIN # Assume all users have registered in function: test_channel_invite() auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic1 = auth_login("*****@*****.**", "123456") token1 = auth_dic1['token'] auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic2 = auth_login("*****@*****.**", "123456") token2 = auth_dic2['token'] channelid_dic1 = channels_create(token1, "channel 1", True) channel_id1 = channelid_dic1['channel_id'] # SETUP END # successful test # assume the total number of messages in the channel is 0 # which means there is no message in the channel # assume the start number is 0 # send a message to channel1 message_send(token1, channel_id1, "hello") channel_messages(token1, channel_id1, 0) # error test with pytest.raises(ValueError): # Channel (based on ID) does not exist # assume the channel ID 2 does not exist channel_messages(token1, 10, 0) with pytest.raises(ValueError): # start is greater than the total number of messages in the channel # the total number of messages is 1, start is 2 channel_messages(token1, channel_id1, 2) with pytest.raises(AccessError): # Authorised user is not a member of channel with channel_id channel_messages(token2, channel_id1, 0) # logout auth_logout(token1) auth_logout(token2) reset_data()
def test_channel_join(): reset_data() # SETUP BEGIN # Assume all users have registered in function: test_channel_invite() auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic1 = auth_login("*****@*****.**", "123456") token1 = auth_dic1['token'] auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic2 = auth_login("*****@*****.**", "123456") token2 = auth_dic2['token'] channelid_dic1 = channels_create(token1, "channel 1", True) channel_id1 = channelid_dic1['channel_id'] # create a private channel channelid_dic2 = channels_create(token1, "channel 2", False) channel_id2 = channelid_dic2['channel_id'] # SETUP END # successful test assert channel_join(token2, channel_id1) == {} # error test with pytest.raises(ValueError): # Channel (based on ID) does not exist # assume channel id 3 does not exist channel_join(token1, 10) with pytest.raises(ValueError): # if token is already a member in this channel channel_join(token2, channel_id1) with pytest.raises(AccessError): # channel_id refers to a channel that is private (when the authorised user is not an admin) channel_join(token2, channel_id2) # logout auth_logout(token1) auth_logout(token2) reset_data()
def test_auth_passwordreset_request(): ''' assumption: [email protected] is the only registered email. 2.all the value errors have been modified into specfic words. 3.assume the reset code is 12345 ''' reset_data() auth_register('*****@*****.**', '1q2w3e4r', 'HAHA', 'JIANG') #successful test: # hard to test assert (auth_passwordreset_request("*****@*****.**") == {}) #test1: email hasn't been resgitered. with pytest.raises(ValueError): auth_passwordreset_request('*****@*****.**') reset_data()
def test_standup_send(): reset_data() #SETUP Begin authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith") token1 = authRegDict1['token'] channelCreateDict1 = channels_create(token1, 'New Channel', True) channel_id1 = channelCreateDict1['channel_id'] authRegDict2 = auth_register("*****@*****.**", "asdfgh", "Jim", "Smith") token2 = authRegDict2['token'] channelCreateDict2 = channels_create(token2, 'New Channel2', True) channel_id2 = channelCreateDict2['channel_id'] standup_start(token1, channel_id1, 7) #User 2 has not joined the 'New Channel' created by user 1 #SETUP End #Test Case 1: Successful message sent to get bufferred in the standup queue assert standup_send(token1, channel_id1, 'Hello') == {} #Test Case 2: Unsuccessful message due to channel not existing with pytest.raises(ValueError): standup_send( token1, 10, 'Hello') #Invalid channel ID hence the unsuccessful message #Test Case 3: Unsuccessful message due to message being more than 1000 characters with pytest.raises(ValueError): standup_send(token1, channel_id1, 'a' * 1001) #Test Case 4: Unsuccessful message due to user not being a member of the channel with pytest.raises(AccessError): #user 2 has not joined the channel created by user 1 so the message is Unsuccessful standup_send(token2, channel_id1, 'Hello') #Test Case 5: Unsuccessful standup message due to standup not being active with pytest.raises(ValueError): standup_send(token2, channel_id2, 'Hello') auth_logout(token1) auth_logout(token2) reset_data()
def test_user_profile(): reset_data() #SETUP Begin - initialisation of variables for calling the function authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith") auth_login("*****@*****.**", "qwerty") token1 = authRegDict1['token'] userId1 = authRegDict1['u_id'] #SETUP End #Test Case 1: successful case where calling user_profile returns the desired result assert user_profile(token1, userId1)['email'] == "*****@*****.**" #Test Case 2: Unsuccessful case where an invalid user ID is provided with pytest.raises(ValueError, match='not a valid u_id'): # the uis 10 do not exist user_profile(token1, 10) auth_logout(token1) reset_data()
def test_channel_leave(): reset_data() # SETUP BEGIN # Assume all users have registered in function: test_channel_invite() auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic1 = auth_login("*****@*****.**", "123456") token1 = auth_dic1['token'] auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic2 = auth_login("*****@*****.**", "123456") token2 = auth_dic2['token'] channelid_dic1 = channels_create(token1, "channel 1", True) channel_id1 = channelid_dic1['channel_id'] channel_join(token2, channel_id1) # SETUP END # successful test assert channel_leave(token2, channel_id1) == {} # error test with pytest.raises(AccessError): # if the user is not a member of channel with channel id channel_leave(token2, channel_id1) # assume if no one in the channel, the channel will does not exist with pytest.raises(ValueError): # Channel (based on ID) does not exist channel_leave(token1, 10) # if there is only one owner in the channel, cannot remove with pytest.raises(ValueError): channel_leave(token1, channel_id1) # logout auth_logout(token1) auth_logout(token2) reset_data()
def test_auth_register(): ''' assumption: [email protected] is the only registered email for now. 2.all the value errors have been modified into specfic words. 3.the [email protected] is a valid email which hasn't been registered. ''' reset_data() #successful test register_dic = auth_register('*****@*****.**', 'q1w2e3r4', 'BEAR', 'XI') login_dic1 = auth_login('*****@*****.**', 'q1w2e3r4') token = login_dic1['token'] assert register_dic['u_id'] == login_dic1['u_id'] #test1: register with an invalid email with pytest.raises(ValueError, match=r'Invalid email'): auth_register('wrongemail.com', '1q2w3e4r', 'HAHA', 'JIANG') #test2: the email has been registered with pytest.raises(ValueError, match=r'email has been used'): auth_register('*****@*****.**', '1q2w3e4r', 'HHAHA', 'JJIANG') #test3: the password used for registering with wrong format with pytest.raises(ValueError, match=r'Invalid password'): auth_register('*****@*****.**', '123', 'HAHA', 'JIANG') #test4: the user's first name is too long with pytest.raises(ValueError, match=r'Invalid first name length'): auth_register('*****@*****.**', '123456', 'HAHA'*13, 'JIANG') #test5: the user's last name is too long with pytest.raises(ValueError, match=r'Invalid last name length'): auth_register('*****@*****.**', '123456', 'HAHA', 'JIANG'*11) auth_logout(token) reset_data()
def test_auth_passwordreset_reset(): ''' assumption: [email protected] is the only registered email. 2.all the value errors have been modified into specfic words. 3.there is a reset code which is '12345' in the email dic. 4.the old password of [email protected] is 1q2w3e4r. ''' reset_data() #successful test: # hard to test the successful test,cause we cannot get the resetcode #test1: reset_code is not a valid reset code (hard to test, cuz we do not know reset_code with pytest.raises(ValueError): auth_passwordreset_reset('54321', 'r4e3w2q1') #test2: Password entered is not a valid password with pytest.raises(ValueError): auth_passwordreset_reset('12345', '1') reset_data()
def test_channel_details(): reset_data() # SETUP BEGIN # Assume all users have registered in function: test_channel_invite() auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic1 = auth_login("*****@*****.**", "123456") token1 = auth_dic1['token'] auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic2 = auth_login("*****@*****.**", "123456") token2 = auth_dic2['token'] channelid_dic1 = channels_create(token1, "channel 1", True) channel_id1 = channelid_dic1['channel_id'] # SETUP END # successful test # assume channel_details function return the channel name # and the uid of the owner_members/members channel_dic = channel_details(token1, channel_id1) assert channel_dic['name'] == "channel 1" # error test with pytest.raises(ValueError): # Channel (based on ID) does not exist # assume channel ID 2 does not exist channel_details(token1, 10) ''' with pytest.raises(AccessError): # Authorised user is not a member of channel with channel_id # user2 is not a member of channel1 channel_details(token2, channel_id1) ''' # logout auth_logout(token1) auth_logout(token2) reset_data()
def test_standup_start(): reset_data() #SETUP Begin authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith") token1 = authRegDict1['token'] channelCreateDict1 = channels_create(token1, 'New Channel', True) channel_id1 = channelCreateDict1['channel_id'] authRegDict2 = auth_register("*****@*****.**", "asdfgh", "Jim", "Smith") token2 = authRegDict2['token'] #User 2 has not joined the 'New Channel' created by user 1 #SETUP End #Test Case 1: Successful test case timestamp = int(datetime.datetime.now().strftime("%s")) + 5 finish = standup_start(token1, channel_id1, 5)['time_finish'] assert finish == timestamp # Successful test case should return datetime of current time + 5 minutes #Test Case 2: Unsuccessful test case where channel does not exist with pytest.raises(ValueError): standup_start( token1, 10, 5) #channel ID is invalid hence the unsuccessful function call #Test Case 3: Unsuccessful start of standup # due to user not being a member of the channel he/she is trying to send the message in with pytest.raises(AccessError): standup_start(token2, channel_id1, 5) #Test Case 3: Unsuccessful start of standup # because An active standup is currently running in this channel with pytest.raises(ValueError): standup_start(token1, channel_id1, 5) auth_logout(token1) auth_logout(token2) reset_data()
def test_channel_addowner(): reset_data() # SETUP BEGIN # Assume all users have registered in function: test_channel_invite() auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_login("*****@*****.**", "123456") token1 = auth_dic1['token'] auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic2 = auth_login("*****@*****.**", "123456") token2 = auth_dic2['token'] uid2 = auth_dic2['u_id'] auth_dic3 = auth_register("*****@*****.**", "123456", "firstone", "lastone") auth_dic3 = auth_login("*****@*****.**", "123456") token3 = auth_dic3['token'] uid3 = auth_dic3['u_id'] channelid_dic1 = channels_create(token1, "channel 1", True) channel_id1 = channelid_dic1['channel_id'] channel_join(token2, channel_id1) channel_join(token3, channel_id1) # create a private channel channelid_dic2 = channels_create(token2, "channel 2", True) channel_id2 = channelid_dic2['channel_id'] channel_join(token3, channel_id2) # SETUP END # successful test assert channel_addowner(token1, channel_id1, uid2) == {} assert channel_addowner(token1, channel_id2, uid3) == {} # token 1 is the owner of the slackr # error test with pytest.raises(ValueError): # Channel (based on ID) does not exist channel_addowner(token1, 10, uid2) with pytest.raises(ValueError): # When user with user id u_id is already an owner of the channel channel_addowner(token1, channel_id1, uid2) with pytest.raises(ValueError): # When the user with u_id is not a member of the channel channel_addowner(token1, channel_id2, uid2) with pytest.raises(AccessError): # when the authorised user is not an owner of the slackr, or an owner of this channel channel_addowner(token3, channel_id1, uid3) # logout auth_logout(token1) auth_logout(token2) auth_logout(token3) reset_data()