def test_admin_userpermission_change_user_permission_possible_permissions(): ''' Testing if it is possible to go through the entire permission set ''' # Initialising global_var.initialise_all() # Creating a valid user who can change permissions owner = auth_register("*****@*****.**", "pass123", "Rayden", "Smith") get_user_by_u_id(owner["u_id"]).permission = SLACKR_OWNER # Creating normal member user = auth_register("*****@*****.**", "pass123", "Rayden", "Smith") get_user_by_u_id(user["u_id"]).permission = SLACKR_USER # Changing normal member to admin admin_userpermission_change(get_user_token_by_u_id(owner["u_id"]), \ user["u_id"], SLACKR_ADMIN) assert get_user_by_u_id(user["u_id"]).permission == SLACKR_ADMIN # Changing admin to owner admin_userpermission_change(get_user_token_by_u_id(owner["u_id"]), \ user["u_id"], SLACKR_OWNER) assert get_user_by_u_id(user["u_id"]).permission == SLACKR_OWNER # Changing owner to member admin_userpermission_change(get_user_token_by_u_id(owner["u_id"]), \ user["u_id"], SLACKR_USER) assert get_user_by_u_id(user["u_id"]).permission == SLACKR_USER
def test_message_pin(): ''' Function tests for message_pin ''' #Initialisation global_var.initialise_all() #Create users owner = auth_functions.auth_register("*****@*****.**", "pass123", \ "Sally", "Bob") assert owner == {"u_id": 0, "token": encode_token_for_u_id(0)} owner_token = owner["token"] user = auth_functions.auth_register("*****@*****.**", "pass123", \ "Rayden", "Smith") token = user["token"] #owner that creates the channel and so is the owner channel = channel_functions.channels_create(owner_token, "Name", True) channel_id = channel["channel_id"] #user joins the channel channel_functions.channel_join(token, channel_id) #user sends 3 messages assert funcs.message_send(token, channel_id, "This is a valid message") \ == {"message_id" : 0} assert funcs.message_send(token, channel_id, \ "This is another valid message") == {"message_id" : 1} assert funcs.message_send(owner_token, channel_id, \ "This is not your message") == {"message_id" : 2} #Init finished #A invalid token is sent to the function # (A invalid user is trying to use the function) with pytest.raises(AccessError, match="Invalid token"): funcs.message_pin("111111", 0) #A user is not an admin with pytest.raises(ValueError, match="User is not an admin"): funcs.message_pin(token, 0) #A admin user successfully pins a message assert funcs.message_pin(owner_token, 0) == {} #Message is invalid based on message_id with pytest.raises(ValueError, match="Message does not exist"): funcs.message_pin(owner_token, -1) #Message is already pinned with pytest.raises(ValueError, match="Message is currently pinned"): funcs.message_pin(owner_token, 0) #Admin leaves channel channel_functions.channel_leave(owner_token, channel_id) #Admin is not a member of the channel with pytest.raises(AccessError, match=\ "Authorised user is not a member of the channel"): funcs.message_pin(owner_token, 1)
def test_auth_login(): ''' Test functions for auth_login ''' data.initialise_all() # Register a user and then log in auth.auth_register("*****@*****.**", "registered_password", "a", "b") # A registered user is logged in login = auth.auth_login("*****@*****.**", "registered_password") \ # Check database for id and token user_id = get_user_by_email("*****@*****.**").u_id user_token = get_user_token_by_u_id(user_id) assert login == {"u_id": user_id, "token": user_token} # An invalid email is given with pytest.raises(ValueError, match="Invalid Email"): auth.auth_login("invalid_email", "valid_password") # Email is not a registered email with pytest.raises(ValueError, match="Email not registered"): auth.auth_login("*****@*****.**", "valid_password") # Password is incorrect with pytest.raises(ValueError, match="Password Incorrect"): auth.auth_login("*****@*****.**", "bpas")
def test_standup_send(): ''' Test functions for standup_send ''' data.initialise_all() # A message is buffered in the standup queue - Owner owner = auth.auth_register("*****@*****.**", "valid_password", "a", "b") channel = channel_func.channels_create(owner["token"], "Owner", True) length = 2 # Channel is not currently in standup mode with pytest.raises(ValueError, match="Not Currently In Standup"): standup_send(owner["token"], channel["channel_id"], \ "correct_and_valid_message") standup_start(owner["token"], channel["channel_id"], length) assert standup_send(owner["token"], channel["channel_id"], \ "correct_and_valid_message") == {} # A invalid token is used to access the function with pytest.raises(AccessError, match="Invalid token"): standup_send("123456", channel["channel_id"], length) user = auth.auth_register("*****@*****.**", "valid_password", "a", "b") # User tries to send message but has not joined channel with pytest.raises(AccessError, match="Cannot Access Channel"): standup_send(user["token"], channel["channel_id"], \ "correct_and_valid_message") # A message is buffered in the standup queue - Member channel_func.channel_join(user["token"], channel["channel_id"]) assert standup_send(user["token"], channel["channel_id"], \ "correct_and_valid_message") == {} # Channel given does not exist with pytest.raises(ValueError, match="Channel Does Not Exist"): standup_send(user["token"], 523523523, \ "correct_and_valid_message") # The message sent was greater than max message length with pytest.raises(ValueError, match="Message Too Long"): long_string = "a" * 1001 standup_send(user["token"], channel["channel_id"], long_string) # Check still works in private channel private = channel_func.channels_create(owner["token"], "Owner", False) standup_start(owner["token"], private["channel_id"], length) assert standup_send(owner["token"], private["channel_id"], \ "correct_and_valid_message") == {} time.sleep(2)
def test_message_react(): ''' Function tests for message_react ''' #Initialisation global_var.initialise_all() user = auth_functions.auth_register("*****@*****.**", "pass123", \ "Rayden", "Smith") token = user["token"] user_2 = auth_functions.auth_register("*****@*****.**", "password", \ "Bob", "Sally") token_2 = user_2["token"] #User creates a channel channel = channel_functions.channels_create(token, "Name", True) channel_id = channel["channel_id"] #user sends 3 messages assert funcs.message_send(token, channel_id, "This is a valid message") \ == {"message_id" : 0} assert funcs.message_send(token, channel_id, \ "This is another valid message") == {"message_id" : 1} assert funcs.message_send(token, channel_id, \ "This is your message") == {"message_id" : 2} #Initialisation finished # User not a member of channel with pytest.raises(AccessError, match=\ "Authorised user is not a member of the channel"): funcs.message_react(token_2, 0, LIKE_REACT) channel_functions.channel_join(token_2, channel_id) #An invalid token is sent to the function with pytest.raises(AccessError, match="Invalid token"): funcs.message_react("111111", 0, LIKE_REACT) #A user successfully reacts assert funcs.message_react(token, 0, LIKE_REACT) == {} #A user successfully reacts - with a different react (Not implemented in frontend) assert funcs.message_react(token, 0, HEART_REACT) == {} #Another user also reacts to the same message assert funcs.message_react(token_2, 0, LIKE_REACT) == {} #An user tries to react to a invalid message based on message_id with pytest.raises(ValueError, match="Message does not exist"): funcs.message_react(token, -1, LIKE_REACT) #An user tries to react to a message already reacted to with pytest.raises(ValueError, match="Message contains an active react"): funcs.message_react(token, 0, LIKE_REACT) #An user uses a invalid react id with pytest.raises(ValueError, match="Invalid React ID"): funcs.message_react(token, 1, -1)
def test_channels_list(): ''' Function tests for channels_list ''' #Initialisation global_var.initialise_all() user1 = auth_register("*****@*****.**", \ "valid_correct_password", "valid_correct_first_name",\ "valid_correct_last_name") token1 = user1["token"] user2 = auth_register("*****@*****.**", \ "valid_correct_password", "valid_correct_first_name", \ "valid_correct_last_name") token2 = user2["token"] # Initialisation finished assert func.channels_list(token1) == {"channels": []} #user1 create a channel func.channels_create(token1, "TestChannel", True) #user2 create a channel func.channels_create(token2, "TestChannel2", True) assert func.channels_list(token1) == { "channels": [{ "channel_id": 0, "name": "TestChannel" }] } assert func.channels_list(token2) == { "channels": [{ "channel_id": 1, "name": "TestChannel2" }] } #user2 creates another channel func.channels_create(token2, "TestChannel3", True) #assert token2 is in two channels assert func.channels_list(token2) == { "channels": [{ "channel_id": 1, "name": "TestChannel2" }, { "channel_id": 2, "name": "TestChannel3" }] } # The function is called using a invalid token with pytest.raises(AccessError, match="Invalid token"): func.channels_list("12345")
def test_message_remove(): ''' Function tests for message_remove ''' #Initialisation global_var.initialise_all() assert global_var.data["users"] == [] #Create users owner = auth_functions.auth_register("*****@*****.**", "pass123", \ "Sally", "Bob") owner_token = owner["token"] user = auth_functions.auth_register("*****@*****.**", "pass123", \ "Rayden", "Smith") token = user["token"] assert global_var.data["users"] != [] #owner creates a channel and so is the owner channel = channel_functions.channels_create(owner_token, "Name", True) assert channel == {"channel_id": 0} channel_id = channel["channel_id"] #user joins the channel channel_functions.channel_join(token, channel_id) #3 messages are sent assert funcs.message_send(token, channel_id, "This is a valid message") \ == {"message_id" : 0} assert funcs.message_send(token, channel_id, \ "This is another valid message") == {"message_id" : 1} assert funcs.message_send(owner_token, channel_id, \ "This is not your message") == {"message_id" : 2} #Initialisation finished #A invalid token is sent to the function with pytest.raises(AccessError, match="Invalid token"): funcs.message_remove("111111", 0) #owner successfully removes a message assert funcs.message_remove(owner_token, 0) == {} # As message was removed, it can not be removed again with pytest.raises(ValueError, match="Message does not exist"): funcs.message_remove(owner_token, 0) #user successfully removes his own message assert funcs.message_remove(token, 1) == {} #A owner tries to remove a invalid message based on message_id with pytest.raises(ValueError, match="Message does not exist"): funcs.message_remove(owner_token, -1) #A user tries to remove a invalid message based on message_id with pytest.raises(ValueError, match="Message does not exist"): funcs.message_remove(token, -1) #user is unable to remove a message not his/her's with pytest.raises(AccessError, match="User does not have permission"): funcs.message_remove(token, 2)
def test_channel_addowner(): ''' Function tests for channel_addowner ''' #Initialisation global_var.initialise_all() owner = auth_register("*****@*****.**", \ "valid_correct_password", "valid_correct_first_name", \ "valid_correct_last_name") token_owner = owner["token"] user1 = auth_register("*****@*****.**", \ "valid_correct_password", "valid_correct_first_name",\ "valid_correct_last_name") token1 = user1["token"] userid1 = user1["u_id"] user2 = auth_register("*****@*****.**",\ "valid_correct_password", "valid_correct_first_name", \ "valid_correct_last_name") userid2 = user2["u_id"] token2 = user2["token"] #owner creates a channel and is automatically the owner channel = func.channels_create(token_owner, "TestChannel", True) channel_id = channel["channel_id"] # Initialisation finished #if given an invalid channel_id with pytest.raises(ValueError, match="Channel does not exist"): func.channel_addowner(token_owner, 100, userid1) #token 1&2 joins channel that owner created func.channel_join(token1, channel_id) func.channel_join(token2, channel_id) #token1 is not an owner of the channel with pytest.raises(AccessError, match="User is not an owner of the channel"): func.channel_addowner(token1, channel_id, userid2) # owner successfully promotes user to owner assert func.channel_addowner(token_owner, channel_id, userid1) == {} # user 1 can now promote other to owner assert func.channel_addowner(token1, channel_id, userid2) == {} #token1/userid1 is already an owner of the channel with pytest.raises(ValueError, match="User is already an owner of the channel"): func.channel_addowner(token_owner, channel_id, userid1) # The function is called using a invalid token with pytest.raises(AccessError, match="Invalid token"): func.channel_addowner("12345", channel_id, userid1)
def test_delete_NotOwner(): reset_data() A = auth_register("*****@*****.**", "wsad1990", "Good", "Morning") B = auth_register("*****@*****.**", "wsad1990", "Bad", "Night") Pub_channel = CF.channels_create(A['token'], 'DeleteChannel', 'True') token = B['token'] channelID = Pub_channel['channel_id'] CF.channel_join(token, channelID) with pytest.raises(CF.ValueError): CF.channel_delete(token, channelID)
def test_channel_invite_success(): reset_data() A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee") B = auth_register("*****@*****.**", "wsad1990", "Good", "Morning") Pub_channel = CF.channels_create(A['token'], 'Num2', 'True') channelID = Pub_channel['channel_id'] token = A['token'] u_id = B['u_id'] CF.channel_invite(token, channelID, u_id)
def test_Invalid_public_channelID(): reset_data() A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee") B = auth_register("*****@*****.**", "wsad1990", "Good", "Morning") token = A['token'] u_id = B['u_id'] channelID = Pub_channel['channel_id'] + 10086 with pytest.raises(CHF.AccessError): CF.channel_invite(token, channelID, u_id)
def test_set_successful(): reset_data() A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee") B = auth_register("*****@*****.**", "wsad1990", "Good", "Morning") Pub_channel = channels_create(A['token'], 'STDChannel', 'True') token = A['token'] channelID = Pub_channel['channel_id'] length = '15' OF.standup_start(token, channelID, length)
def test_noAdmain_join_list(): reset_data() A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee") B = auth_register("*****@*****.**", "wsad1990", "Good", "Morning") Pub_channel = CF.channels_create(A['token'], 'Num2', 'True') channelID = Pub_channel['channel_id'] token1 = B['token'] CF.channel_join(token1, channelID) CF.channels_list(token1)
def test_channel_invite(): ''' Testing for inviting a user to a channel ''' #Initialisation global_var.initialise_all() # Create an user who owns the channel user1 = auth_register("*****@*****.**", "password123", \ "Rayden", "Smith") token_1 = user1["token"] # Create user that is invited to channel user2 = auth_register("*****@*****.**", "thisisapassword", \ "Bob", "Sally") token_2 = user2["token"] userid_2 = user2["u_id"] # Create user that will not be part of channel user3 = auth_register("*****@*****.**", "arandompassword", \ "Coen", "Kevin") token_3 = user3["token"] # Create a channel channel = func.channels_create(token_1, "TestChannel1", True) channel_id = channel["channel_id"] # Initialisation finished # User2 is successfully invited to channel assert func.channel_invite(token_1, channel_id, userid_2) == {} # If the invite was successful, user2 can send a message assert message_send(token_2, channel_id, "A successful message") \ == {"message_id" : 0} # User leaves the channel assert func.channel_leave(token_2, channel_id) == {} # User is not invited if given an invalid token with pytest.raises(AccessError, match="Invalid token"): func.channel_invite("12345", channel_id, userid_2) # User is not inivited if given an invalid channel_id with pytest.raises(ValueError, match="Channel does not exist"): func.channel_invite(token_1, 100, userid_2) # Inviting user is not apart of the channel with pytest.raises(AccessError, \ match="Authorised user is not a member of the channel"): func.channel_invite(token_3, channel_id, userid_2) # If user being invited is not an user with pytest.raises(ValueError, match="Invalid User ID"): func.channel_invite(token_1, channel_id, 111111)
def test_memeber_addOwner(): reset_data() A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee") B = auth_register("*****@*****.**", "wsad1990", "Good", "Morning") Pub_channel = CF.channels_create(A['token'], 'Test1', 'True') CF.channel_join(B['token'], Pub_channel['channel_id']) token = A['token'] u_id = B['u_id'] channelID = Pub_channel['channel_id'] CF.channel_addowner(token, channelID, u_id)
def test_user_notTheOwner(): reset_data() B = auth_register("*****@*****.**", "wsad1990", "Good", "Morning") A = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee") Pub_channel = channels_create(A['token'], 'STDChannel', 'True') token = B['token'] channelID = Pub_channel['channel_id'] length = '15' with pytest.raises(OF.AccessError): OF.standup_start(token, channelID, length)
def test_search_otherMember_success(): reset_data() B = auth_register("*****@*****.**", "wsad1990", "Good", "Morning") A = auth_register("*****@*****.**", 'HoyaLee2019', 'Hoya', 'Lee') Pub_channel = CF.channels_create(A['token'], 'Num0', 'True') CF.channel_join(B['token'], Pub_channel['channel_id']) token = B['token'] query_str = 'Hello' OF.search(token, query_str)
def test_succ_admain(): reset_data() O = auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee") token = O['token'] u_id = O['u_id'] A = auth_register("*****@*****.**", "wsad1990", "Good", "Morning") i_token = A['token'] permission_id = 2 OF.admin_permission_change(token, u_id, permission_id)
def test_profile_sethandle(): ''' Update the user's handle ''' # Initialisation global_var.initialise_all() # Creating a user user = auth_functions.auth_register("*****@*****.**", "pass123", \ "Rayden", "Smith") token = user["token"] u_id = user["u_id"] # A valid handle is given assert funcs.user_profile_sethandle(token, "a handle") == {} # Updating the handle of the user funcs.user_profile_sethandle(token, "new handle") # Checking if the user's handle has been updated successfully assert funcs.user_profile(token, u_id) == { "u_id": u_id, "email": "*****@*****.**", "name_first": "Rayden", "name_last": "Smith", "handle_str": "new handle", "profile_img_url": 'http://*****:*****@gmail.com", "pass123", \ "Rayden", "Smith") funcs.user_profile_sethandle(user1["token"], "new handle")
def test_user_REMOVE_SUCC(): reset_data() B = auth_register("*****@*****.**", "wsad1990", "Tony", "Hex") A = auth_register("*****@*****.**", 'HoyaLee2019', 'Hoya', 'Lee') Pub_channel = CF.channels_create(A['token'], 'channelFirst', 'True') CF.channel_addowner(A['token'], Pub_channel['channel_id'], B['u_id']) token = A['token'] u_id = B['u_id'] channelID = Pub_channel['channel_id'] CF.channel_addowner(token, channelID, u_id) CF.channel_removeowner(token, channelID, u_id)
def test_user_already_moved(): reset_data() B = auth_register("*****@*****.**", "wsad1990", "Tony", "Hex") A = auth_register("*****@*****.**", 'HoyaLee2019', 'Hoya', 'Lee') Pub_channel = CF.channels_create(A['token'], 'channelFirst', 'True') CF.channel_join(B['token'], Pub_channel['channel_id']) token = A['token'] u_id = B['u_id'] channelID = Pub_channel['channel_id'] with pytest.raises(CHF.AccessError): CF.channel_removeowner(token, channelID, u_id)
def test_standup_start(): ''' Test functions for standup_start ''' data.initialise_all() # A valid token and channel successfully starts a standup - Owner owner = auth.auth_register("*****@*****.**", "valid_password", "a", "b") channel1 = channel_func.channels_create(owner["token"], "Owner", True) channel2 = channel_func.channels_create(owner["token"], "User", True) length = 1 # Testing return time end_ex = get_standup_end(length) end_ac = standup_start(owner["token"], channel1["channel_id"], length) assert same_time(end_ex, end_ac["time_finish"]) time.sleep(1) # A invalid token is used to access the function with pytest.raises(AccessError, match="Invalid token"): standup_start("123456", channel2["channel_id"], length) # A valid token and channel successfully starts a standup - User user = auth.auth_register("*****@*****.**", "valid_password", "a", "b") # User tries to start standup but has not joined the channel with pytest.raises(AccessError, match="Cannot Access Channel"): standup_start(user["token"], channel2["channel_id"], length) # User starts standup channel_func.channel_join(user["token"], channel2["channel_id"]) end_ex = get_standup_end(length) end_ac = standup_start(user["token"], channel2["channel_id"], length) assert same_time(end_ex, end_ac["time_finish"]) # Channel id given does not exist with pytest.raises(ValueError, match="Channel Does Not Exist"): standup_start(user["token"], 21512512521512, length) # Start standup when already running with pytest.raises(ValueError, match="Standup Already Running"): standup_start(user["token"], channel2["channel_id"], length) # Standup works on private channel private = channel_func.channels_create(owner["token"], "Owner", False) end_ex = get_standup_end(length) end_ac = standup_start(owner["token"], private["channel_id"], length) assert same_time(end_ex, end_ac["time_finish"]) time.sleep(1)
def test_channel_removeowner(): ''' Function tests for channel_removeowner ''' #Initialisation global_var.initialise_all() user1 = auth_register("*****@*****.**", \ "valid_correct_password", "valid_correct_first_name", \ "valid_correct_last_name") token1 = user1["token"] userid1 = user1["u_id"] user2 = auth_register("*****@*****.**", \ "valid_correct_password", "valid_correct_first_name", \ "valid_correct_last_name") token2 = user2["token"] userid2 = user2["u_id"] #token1 create a channel channel = func.channels_create(token1, "TestChannel", True) channel_id = channel["channel_id"] #token2 joins the channel token1 made func.channel_join(token2, channel_id) # Initialisation finished #user2 is not the owner, thus trying to removeowner raises an error with pytest.raises(ValueError, match=\ "User id is not an owner of the channel"): func.channel_removeowner(token1, channel_id, userid2) # user2 is not the owner and tries to remove owner of channel with pytest.raises(AccessError, match=\ "User is not an owner of the channel or slackrowner"): func.channel_removeowner(token2, channel_id, userid1) #token1 makes token2 a owner func.channel_addowner(token1, channel_id, userid2) assert func.channel_removeowner(token1, channel_id, userid2) == {} #if given an invalid channel_id with pytest.raises(ValueError, match="Channel does not exist"): func.channel_removeowner(token1, 100, userid2) # The function is called using a invalid token with pytest.raises(AccessError, match="Invalid token"): func.channel_removeowner("12345", channel_id, userid2)
def test_generate_handle(): ''' Ensures handles that are generated are unique ''' # Initialisation global_var.initialise_all() # First instance of handle in server user1 = auth.auth_register("*****@*****.**", "pass123", "Ashley", "Huang") user1 = helpers.get_user_by_token(user1["token"]) assert user1.handle == "ashleyhuang" # Non-first instance of handle in server - substitute found user2 = auth.auth_register("*****@*****.**", "pass123", "Ashley", "Huang") user2 = helpers.get_user_by_token(user2["token"]) assert user2.handle == "1ashleyhuang" # Non-first instance of handle in server - first no substitute found auth.auth_register("*****@*****.**", "pass123", "3Ashley", "Huang") user4 = auth.auth_register("*****@*****.**", "pass123", "Ashley", "Huang") user4 = helpers.get_user_by_token(user4["token"]) assert user4.handle == "0" # Non-first instance of handle in server - second no substitute found auth.auth_register("*****@*****.**", "pass123", "5Ashley", "Huang") user6 = auth.auth_register("*****@*****.**", "pass123", "Ashley", "Huang") user6 = helpers.get_user_by_token(user6["token"]) assert user6.handle == "1"
def test_channels_create(): ''' Function tests for channels_create ''' #Initialisation global_var.initialise_all() user1 = auth_register("*****@*****.**", \ "valid_correct_password", "valid_correct_first_name",\ "valid_correct_last_name") token1 = user1["token"] user2 = auth_register("*****@*****.**", \ "valid_correct_password", "valid_correct_first_name",\ "valid_correct_last_name") token2 = user2["token"] #user1 create a channel func.channels_create(token1, "TestChannel", True) # Initialisation finished assert func.channels_create(token1, "Channel1", True) == \ {"channel_id" : 1} assert func.channels_create(token1, "Channel2", False) == \ {"channel_id" : 2} # User can join public channel assert func.channel_join(token2, 1) == {} # User cannot join private channel with pytest.raises(AccessError, \ match="Channel is private and user is not admin"): func.channel_join(token2, 2) # Channel cannot be created by an invalid token with pytest.raises(AccessError, match="Invalid token"): func.channels_create("12345", "Channel3", True) #public channel, name longer than 20 characters with pytest.raises(ValueError, match=\ "Name is longer than 20 characters"): func.channels_create(token1, "a" * 21, True) #private channel, name longer than 20 characters with pytest.raises(ValueError, match=\ "Name is longer than 20 characters"): func.channels_create(token1, "a" * 21, False)
def test_auth_passwordreset_request(): ''' Test functions for auth_passwordreset_request ''' data.initialise_all() # Create account to be password reset request auth.auth_register("*****@*****.**", "valid_password", "a", "b") # Password reset request is sent to valid email auth.auth_passwordreset_request("*****@*****.**") # Password reset request is sent to invalid email with pytest.raises(ValueError, match="Email is not valid"): auth.auth_passwordreset_request("comp1531receive.com")
def test_search_one(): ''' Testing successful case for a search for one message ''' # Initialising global_var.initialise_all() # Creating user user = auth_register('*****@*****.**', 'password', 'search', 'test') token = get_user_token_by_u_id(user["u_id"]) # Creating channel channel = channels_create(token, "chat", True) channel_id = channel["channel_id"] # Adding messages to channel message_send(token, channel_id, "121") message_send(token, channel_id, "321") message_send(token, channel_id, "342") message_send(token, channel_id, "499") # Searching message messages = search.search(token, '99') # Checking if message obtained assert messages["messages"][0]["message"] == "499" assert messages["messages"][0]["u_id"] == user["u_id"] # Ensuring that no other messages are obtained with pytest.raises(IndexError, match="list index out of range"): message = messages["messages"][1]
def test_search_multi_channel(): ''' Testing successful case of being able to obtain messages from multiple channels that the user is apart of ''' # Initialising global_var.initialise_all() # Creating user user = auth_register('*****@*****.**', 'password', 'search', 'test') token = get_user_token_by_u_id(user["u_id"]) # Creating channel 1 channel1 = channels_create(token, "chat1", True) channel1_id = channel1["channel_id"] # Creating channel 2 channel2 = channels_create(token, "chat2", True) channel2_id = channel2["channel_id"] # Adding messages to channel message_send(token, channel1_id, "121") message_send(token, channel2_id, "321") # Search messages = search.search(token, '21') # Checking if messages obtained assert messages["messages"][0]["message"] == "121" assert messages["messages"][0]["u_id"] == user["u_id"] assert messages["messages"][1]["message"] == "321" # Ensuring that no other messages are obtained with pytest.raises(IndexError, match="list index out of range"): message = messages["messages"][2]
def test_get_channel_by_channel_id(): ''' Ensures get_channel_by_channel_id returns correct channel id ''' # Initialisation global_var.initialise_all() # Creating a user user = auth.auth_register("*****@*****.**", "pass123", "Raydon", "Smith") token = user["token"] # Creating first channel channel_1 = channel_functions.channels_create(token, "Channel 1", True) channel_1_id = channel_1["channel_id"] # Creating second channel channel_2 = channel_functions.channels_create(token, "Channel 2", True) channel_2_id = channel_2["channel_id"] # Ensuring that first channel has id assert helpers.get_channel_by_channel_id(channel_1_id).id == 0 # Ensuring that second channel has id assert helpers.get_channel_by_channel_id(channel_2_id).id == 1 # Checking no such channel_id assert helpers.get_channel_by_channel_id(-1) is None
def test_user_handle_success(): reset_data() A = auth_register("*****@*****.**", "wsad1990", "Good", "Morning") token = A['token'] handle = 'goodmorning1' UF.user_profile_sethandle(token, handle)