def test_simple(): ''' Test sending multiple messages in different channels ''' reset_data() # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') token = registered_user['token'] c_id = channel_create(token, 'Channel1', 'true') # SETUP END # Send message message_send(token, c_id, 'Hello world!') message_list = get_messages(c_id) assert find_message(message_list, 'Hello world!') == 'Hello world!' # Send message to a channel that already has a message message_send(token, c_id, 'another message') message_list = get_messages(c_id) assert find_message(message_list, 'Hello world!') == 'Hello world!' assert find_message(message_list, 'another message') == 'another message' # Send message to another channel c2_id = channel_create(token, 'Channel2', 'true') # Send message message_send(token, c2_id, 'Hello world!') message_list = get_messages(c2_id) assert find_message(message_list, 'Hello world!') == 'Hello world!'
def test_user_profile(): helper.reset_data() # SETUP START admin = helper.token_admin() user = helper.token_account_1() # Invalid User invalid_token = "invalidTest" invalid_user = -1 # SETUP END # Checks that an error is raised for invalid token with pytest.raises(validation_helper.AccessError): stub.user_profile(invalid_token, user["u_id"]) # Checks that an error is raised for invalid user with pytest.raises(validation_helper.ValueError): stub.user_profile(admin["token"], invalid_user) # Checks that the correct user profile is returned assert stub.user_profile(admin["token"], admin["u_id"]) == {"u_id": admin["u_id"], "email": "*****@*****.**", "name_first": "Daddy", "name_last": "Pig", "handle_str": "daddypig", "profile_img_url": "/static/default.jpg", } assert stub.user_profile(user["token"], user["u_id"]) == {"u_id": user["u_id"], "email": "*****@*****.**", "name_first": "Mommy", "name_last": "Pig", "handle_str": "mommypig", "profile_img_url": "/static/default.jpg", }
def test_user_profile_sethandle(): helper.reset_data() # SETUP START admin = helper.token_admin() admin_profile_dict = stub.user_profile(admin["token"], admin["u_id"]) curr_handle = admin_profile_dict["handle_str"] new_handle = 'pig_daddy' # Invalid handle with >20 characters max_handle = 'a' * 21 # Invalid handle with no valid characters invalid_handle = '??' # Invalid handle with no input no_handle = ' ' # SETUP END # Checks that an error is raised for >20 characters with pytest.raises(validation_helper.ValueError): stub.user_profile_sethandle(admin["token"], max_handle) # Checks that an error is raised for invalid characters with pytest.raises(validation_helper.ValueError): stub.user_profile_sethandle(admin["token"], invalid_handle) # Checks that an error is raised for no characters with pytest.raises(validation_helper.ValueError): stub.user_profile_sethandle(admin["token"], no_handle) # Successfully updated the handle stub.user_profile_sethandle(admin["token"], new_handle) assert curr_handle != new_handle
def test_message_remove(): helper.reset_data() # Valid parameters token = helper.token_account_1()["token"] channel_id = helper.get_valid_channel(token) message_id = helper.get_valid_message(token, channel_id) message = "This message was produced by the get_valid_message function." # Invalid parameters unauthorised_token = helper.token_account_2()["token"] stub.channel_leave(unauthorised_token, channel_id) # Test that it raises an access erorr if the user is not in the channel # to remove a message with pytest.raises(validation_helper.AccessError): stub.message_remove(unauthorised_token, message_id) # Test that it raises an access erorr if the user does not have the proper # authority to remove a message with pytest.raises(validation_helper.AccessError): stub.channel_join(unauthorised_token, channel_id) stub.message_remove(unauthorised_token, message_id) # Attempt to successfully remove a message assert stub.message_remove(token, message_id) == {} # Test that it raises an error if trying to remove a already removed message with pytest.raises(validation_helper.ValueError): stub.message_remove(token, message_id) # Test that the message disappears from search assert message_id not in stub.search(token, message)
def test_message_unreact(): helper.reset_data() # Set up valid parameters token = helper.token_account_1()["token"] react_id = 1 # We do not have any way of obtaining a valid react_id atm channel_id = helper.get_valid_channel(token) message_id = helper.get_valid_message(token, channel_id) stub.message_react(token, message_id, react_id) # Set up invalid parameters invalid_react_id = -1 invalid_message_id = -1 # message_id is invalid with pytest.raises(validation_helper.ValueError): stub.message_unreact(token, invalid_message_id, react_id) # react_id is not a valid React ID with pytest.raises(validation_helper.ValueError): stub.message_unreact(token, invalid_message_id, invalid_react_id) # successfully unreact a message assert stub.message_unreact(token, message_id, react_id) == {} # unreact something you already unreacted with pytest.raises(validation_helper.ValueError): stub.message_unreact(token, message_id, react_id)
def test_channel_removeowner(): helper.reset_data() # SETUP START user1 = helper.token_admin() user2 = helper.token_account_1() new_channel_id = helper.channelid_public(user1["token"]) # SETUP END # Check that error is raised if an invalid token is passed in with pytest.raises(validation_helper.AccessError): stub.channel_removeowner("fake token", new_channel_id, user1["u_id"]) with pytest.raises(validation_helper.ValueError): # check that validation_helper.ValueError is raised if channel does not exist # Assumption: channel_id cannot be negative stub.channel_removeowner(user1["token"], -1, user1["u_id"]) with pytest.raises(validation_helper.ValueError): # Check ValueError raised if target user is not an owner stub.channel_removeowner(user1["token"], new_channel_id, user2["u_id"]) with pytest.raises(validation_helper.AccessError): # Check accessError raised if user not an owner stub.channel_removeowner(user2["token"], new_channel_id, user1["u_id"]) with pytest.raises(validation_helper.AccessError): # Check accessError raised if target is an owner stub.channel_removeowner(user1["token"], new_channel_id, user1["u_id"]) # Check that call is successful if all inputs are valid stub.channel_addowner(user1["token"], new_channel_id, user2["u_id"]) stub.channel_removeowner(user1["token"], new_channel_id, user2["u_id"]) assert validation_helper.is_owner(user2["u_id"], new_channel_id) is not True
def test_channels_create(): helper.reset_data() user = helper.token_admin() # Invalid token with pytest.raises(validation_helper.AccessError): stub.channels_create("fake token", "name", True) with pytest.raises(validation_helper.ValueError): # check that validation_helper.ValueError is raised if name is more than 20 characters long stub.channels_create(user["token"], "123456789012345678901", True) with pytest.raises(validation_helper.ValueError): # check that validation_helper.ValueError is raised if name is an empty string (assumption) stub.channels_create(user["token"], "", True) # check that call is successful otherwise public_channel_id = stub.channels_create(user["token"], "Public Channel", True)["channel_id"] private_channel_id = stub.channels_create(user["token"], "Private Channel", False)["channel_id"] assert stub.channels_listall(user["token"]) == { "channels": [ {"channel_id": public_channel_id, "name": "Public Channel"}, {"channel_id": private_channel_id, "name": "Private Channel"} ] }
def test_remove_admin(): ''' Test remove as an admin of the slack ''' reset_data() # SETUP registered_user = auth_register("*****@*****.**", "123456", "John", "Smith") first_token = registered_user['token'] c_id = channel_create(first_token, "Channel1", 'true') # Add two messages message_send(first_token, c_id, "Hello world!") message_send(first_token, c_id, "another message") message_list = get_messages(c_id) assert find_message(message_list, "Hello world!") == "Hello world!" assert find_message(message_list, "another message") == "another message" # Login as a new user registered_user = auth_register("*****@*****.**", "1password", "Bob", "Smith") token = registered_user['token'] u_id = registered_user['u_id'] # Set new user as an admin of slack admin_userpermission_change(first_token, u_id, 2) # SETUP END message_list = get_messages(c_id) msg1_id = get_message_id(message_list, "Hello world!") message_remove(token, msg1_id) assert find_message(message_list, "Hello world!") is None
def test_remove_diffuser(): ''' Test remove as a different user in the channel ''' reset_data() # SETUP registered_user = auth_register("*****@*****.**", "123456", "John", "Smith") token = registered_user['token'] c_id = channel_create(token, "Channel1", 'true') # Add two messages message_send(token, c_id, "Hello world!") message_send(token, c_id, "another message") message_list = get_messages(c_id) assert find_message(message_list, "Hello world!") == "Hello world!" assert find_message(message_list, "another message") == "another message" msg1_id = get_message_id(message_list, "Hello world!") # Logout auth_logout(token) # Login as a new user registered_user = auth_register("*****@*****.**", "1password", "Bob", "Smith") token = registered_user['token'] # SETUP END with pytest.raises(AccessError, match=r"*"): message_remove(token, msg1_id)
def test_remove_simple(): ''' Test remove with multiple messages ''' reset_data() # SETUP registered_user = auth_register("*****@*****.**", "123456", "John", "Smith") token = registered_user['token'] c_id = channel_create(token, "Channel1", 'true') # Add two messages message_send(token, c_id, "Hello world!") message_send(token, c_id, "another message") message_list = get_messages(c_id) assert find_message(message_list, "Hello world!") == "Hello world!" assert find_message(message_list, "another message") == "another message" msg1_id = get_message_id(message_list, "Hello world!") msg2_id = get_message_id(message_list, "another message") # SETUP END # Delete both messages one by one message_remove(token, msg1_id) message_list = get_messages(c_id) assert find_message(message_list, "Hello world!") is None message_remove(token, msg2_id) message_list = get_messages(c_id) assert find_message(message_list, "another message") is None
def test_remove_owner(): ''' Test remove as an owner of the channel ''' reset_data() # SETUP registered_user = auth_register("*****@*****.**", "123456", "John", "Smith") first_token = registered_user['token'] c_id = channel_create(first_token, "Channel1", 'true') # Add two messages message_send(first_token, c_id, "Hello world!") message_list = get_messages(c_id) # Login as a new user registered_user = auth_register("*****@*****.**", "1password", "Bob", "Smith") token = registered_user['token'] u_id = registered_user['u_id'] # Set new user as a channel owner channel_join(token, c_id) channel_addowner(first_token, c_id, u_id) # SETUP END msg1_id = get_message_id(message_list, "Hello world!") message_remove(token, msg1_id) message_list = get_messages(c_id) assert find_message(message_list, "Hello world!") is None
def test_edit_diffuser(): ''' Test edit as a different user ''' reset_data() # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') token = registered_user['token'] c_id = channel_create(token, "Channel1", 'true') # SETUP END # Add two messages message_send(token, c_id, "Hello world!") message_send(token, c_id, "another message") message_list = get_messages(c_id) assert find_message(message_list, "Hello world!") == "Hello world!" assert find_message(message_list, "another message") == "another message" msg1_id = get_message_id(message_list, "Hello world!") # Logout auth_logout(token) # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') token = registered_user['token'] # SETUP END with pytest.raises(AccessError, match=r"*"): message_edit(token, msg1_id, "update")
def test_edit_notoken(): ''' Test edit with an invalid or no token ''' reset_data() # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') token = registered_user['token'] c_id = channel_create(token, "Channel1", 'true') # SETUP END # Add two messages message_send(token, c_id, "Hello world!") message_send(token, c_id, "another message") message_list = get_messages(c_id) assert find_message(message_list, "Hello world!") == "Hello world!" assert find_message(message_list, "another message") == "another message" msg1_id = get_message_id(message_list, "Hello world!") msg2_id = get_message_id(message_list, "another message") # SETUP END with pytest.raises(AccessError, match=r"*"): message_edit("123", msg1_id, "update") message_edit('', msg2_id, "there is no message")
def test_message_edit(): ''' Test edit as the poster of the message on multiple messages ''' reset_data() # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') token = registered_user['token'] c_id = channel_create(token, "Channel1", 'true') # SETUP END # Add two messages message_send(token, c_id, "Hello world!") message_send(token, c_id, "another message") message_list = get_messages(c_id) assert find_message(message_list, "Hello world!") == "Hello world!" assert find_message(message_list, "another message") == "another message" msg1_id = get_message_id(message_list, "Hello world!") msg2_id = get_message_id(message_list, "another message") # SETUP END message_edit(token, msg1_id, "Updated message") message_list = get_messages(c_id) assert find_message(message_list, "Updated message") == "Updated message" message_edit(token, msg2_id, "Another update") message_list = get_messages(c_id) assert find_message(message_list, "Another update") == "Another update"
def test_channel_invite(): helper.reset_data() # Create users for testing user1 = helper.token_account_1() user2 = helper.token_account_2() # create a new channel for testing channel_id = helper.channelid_public(user1["token"]) # Check that error is raised if an invalid token is passed in with pytest.raises(validation_helper.AccessError): stub.channel_invite("fake token", channel_id, user1["u_id"]) # Invalid channel_id with pytest.raises(validation_helper.ValueError): stub.channel_invite(user1["token"], -1, user2["u_id"]) # Invalid u_id with pytest.raises(validation_helper.ValueError): stub.channel_invite(user1["token"], channel_id, -1) # valid call assert stub.channel_invite(user1["token"], channel_id, user2["u_id"]) == {} # Test that the user is in the channel message_id = stub.message_send(user2["token"], channel_id, "Hi")["message_id"] # check that nothing happens if the user is already in the channel stub.channel_invite(user1["token"], channel_id, user1["u_id"]) # check that if an admin/owner of the slackr is invited, they become an owner stub.channel_leave(user1["token"], channel_id) stub.channel_invite(user2["token"], channel_id, user1["u_id"]) stub.message_remove(user1["token"], message_id) # can do this since they should be an owner
def test_message_unreact(): ''' Test working message_unreact and its errors ''' reset_data() # SETUP START token = auth_register('*****@*****.**', 'pass123', 'john', 'apple')['token'] second_token = auth_register('*****@*****.**', 'pass147', 'vicks', 'uwu')['token'] channel_id_public = channel_create(token, 'newChannel', 'true') msg_id = message_send(token, channel_id_public, "firstMessage") react_id = 1 message_react(token, msg_id, react_id) # SETUP END # Invalid token with pytest.raises(AccessError): message_unreact('invalidToken', msg_id, react_id) # msg_id is invalid with pytest.raises(ValueError): message_unreact(token, 666, react_id) # User is not in the channel with pytest.raises(AccessError): message_unreact(second_token, msg_id, react_id) # React id is invalid with pytest.raises(ValueError): message_unreact(token, msg_id, 200) # Working unreact message_unreact(token, msg_id, react_id)
def test_auth_login(): helper.reset_data() # Create users for testing user1 = stub.auth_register("*****@*****.**", "123456", "first", "user") user1_token = user1["token"] user1_id = user1["u_id"] # Invalid email with pytest.raises(validation_helper.ValueError): stub.auth_login("hi", "123456") # Email doesn't belong to a user with pytest.raises(validation_helper.ValueError): stub.auth_login("*****@*****.**", "123456") # Invalid password with pytest.raises(validation_helper.ValueError): stub.auth_login("*****@*****.**", "hi") # Empty string with pytest.raises(validation_helper.ValueError): stub.auth_login("", "") # Successfully login stub.auth_logout(user1_token) assert stub.auth_login("*****@*****.**", "123456")["u_id"] == user1_id
def test_reset_req(): ''' Tests passwordreset_request ''' reset_data() # registering user auth_register("*****@*****.**", "testpass", "john", "smith") assert server_data.data['users'][0]['reset_token'] is None # testing an invalid data type with pytest.raises(TypeError): auth_passwordreset_request(3333345) with pytest.raises(ValueError): # testing an invalid email will do nothing auth_passwordreset_request("notUser@invalid") with pytest.raises(ValueError): # testing an email does not exist will do nothing auth_passwordreset_request("*****@*****.**") # if the email exists, the reset code will be generated assert (auth_passwordreset_request("*****@*****.**")) == {} assert server_data.data["users"][0]['reset_token'] is not None
def test_channels_list(): helper.reset_data() # SETUP START user1 = helper.token_admin() user2 = helper.token_account_1() channel1_id = helper.channelid_public(user1["token"]) channel2_id = helper.channelid_private(user1["token"]) # SETUP END assert stub.channels_list(user1["token"]) == { "channels": [ {"channel_id": channel1_id, "name": "Public Channel"}, {"channel_id": channel2_id, "name": "Private Channel"} ] } # Invalid token with pytest.raises(validation_helper.AccessError): stub.channels_list("fake token") # check that no channels are returned if user is not in any channel assert stub.channels_list(user2["token"]) == {"channels": []} stub.channel_join(user2["token"], channel1_id) # check that output changes once a user joins a channel assert stub.channels_list(user2["token"]) == {"channels": [{"channel_id": channel1_id, "name": "Public Channel"}]} # check that output changes once a user leaves a channel stub.channel_leave(user1["token"], channel1_id) assert stub.channels_list(user1["token"]) == {"channels": [{"channel_id": channel2_id, "name": "Private Channel"}]}
def test_reset_reset(): ''' Tests passwordreset_reset ''' reset_data() res = auth_register("*****@*****.**", "testpass", "john", "smith") token = res['token'] with pytest.raises(ValueError): # when the user has not requested a reset auth_passwordreset_reset(token, "newpass") auth_passwordreset_request("*****@*****.**") reset_code = str(server_data.data["users"][0]['reset_token']) with pytest.raises(ValueError): # if the password entered is not valid auth_passwordreset_reset(reset_code, "s") with pytest.raises(ValueError): # if the token is invalid auth_passwordreset_reset("invalidtoken", "newpass") # Working reset print(server_data.data["users"][0]['reset_token']) print(reset_code) auth_passwordreset_reset(reset_code, "newpassword") assert server_data.data["users"][0]['password'] == hash_pw("newpassword")
def test_message_send(): helper.reset_data() # Valid parameters token = helper.token_account_1()["token"] channel_id = helper.get_valid_channel(token) message = "Testing the function message_send." # Invalid parameters invalid_channel_id = -00000 invalid_message = message*3000 unauthorised_token = helper.token_account_2()["token"] # Test that it raises an erorr if the channel does not exist with pytest.raises(validation_helper.ValueError): stub.message_send(token, invalid_channel_id, message) # Test that it raises an erorr if the message is >1000 characters with pytest.raises(validation_helper.ValueError): stub.message_send(token, channel_id, invalid_message) # Test that it raises an access erorr if the token is not an authorised user. # Note: we assume the second account is not part of the channel. This will fail if the second # account is in the channel with pytest.raises(validation_helper.AccessError): stub.channel_leave(unauthorised_token, channel_id) stub.message_send(unauthorised_token, channel_id, message) # Test that the function successfully completes with valid parameters # (this may require manual verification) assert stub.message_send(token, channel_id, message)["message_id"] > -1
def test_register(): ''' Tests auth_register ''' # check output is returned with correct parameters output = auth_register("*****@*****.**", "strong_pw", "regi", "ster") assert output == { 'u_id': token_to_user(output['token']), 'token': output['token'] } # the following will result in value errors with pytest.raises(ValueError): # entering an invalid email auth_register("BadEmail", "strong_pw", "A", "AA") # password is not valid auth_register("*****@*****.**", 1235, "A", "AA") auth_register("*****@*****.**", "1", "A", "AA") # first name > 50 characters auth_register("*****@*****.**", "strong_pw", "A" * 51, "AA") # last name > 50 characters auth_register("*****@*****.**", "strong_pw", "A", "AA" * 51) # email address already in use with pytest.raises(ValueError): auth_register("*****@*****.**", "strong_pw", "regi", "ster") reset_data() # first user output = auth_register("*****@*****.**", "strong_pw", "regi", "ster") assert output == { 'u_id': token_to_user(output['token']), 'token': output['token'] }
def test_message_react(): helper.reset_data() # Valid parameters token = helper.token_account_1()["token"] react_id = 1 # We do not have any way of obtaining a valid react_id atm channel_id = helper.get_valid_channel(token) message_id = helper.get_valid_message(token, channel_id) # Invalid parameters invalid_react_id = -1 invalid_message_id = -1 # message_id is not a valid message within a channel that the authorised user has joined with pytest.raises(validation_helper.ValueError): stub.message_react(token, invalid_message_id, react_id) # react_id is not a valid React ID with pytest.raises(validation_helper.ValueError): stub.message_react(token, message_id, invalid_react_id) # Successfully react a message assert stub.message_react(token, message_id, react_id) == {} # Message with ID message_id already contains an active React with ID react_id with pytest.raises(validation_helper.ValueError): stub.message_react(token, message_id, react_id)
def test_standup_start(): helper.reset_data() # SETUP START admin = helper.token_admin() token = admin["token"] channel_id = helper.channelid_public(token) # Invalid channel id invalid_channel_id = -111111 # SETUP END # Check that error is raised if an invalid token is passed in with pytest.raises(validation_helper.AccessError): stub.standup_start("fake token", channel_id, 10) # Checks that it raises an error when channel id does not exist with pytest.raises(validation_helper.ValueError): stub.standup_start(token, invalid_channel_id, 10) # Checks that a standup has successfully started time_check = get_info_helper.get_serializable_datetime(datetime.now() + timedelta(seconds=6)) assert stub.standup_start(token, channel_id, 5)["time_finish"] < time_check # Checks that it raises an error when the user is not part of the channel with pytest.raises(validation_helper.AccessError): stub.channel_leave(admin["token"], channel_id) stub.standup_start(token, channel_id, 10)
def test_message_unpin(): helper.reset_data() # Set up valid parameters token = helper.token_admin()["token"] not_admin = helper.token_account_1()["token"] channel_id = helper.get_valid_channel(not_admin) message_id = helper.get_valid_message(not_admin, channel_id) stub.channel_join(token, channel_id) stub.message_pin(token, message_id) # Set up invalid parameters invalid_message_id = -1 # message_id is not a valid message with pytest.raises(validation_helper.ValueError): stub.message_unpin(token, invalid_message_id) # Error when the authorised user is not an admin with pytest.raises(validation_helper.ValueError): stub.message_unpin(not_admin, message_id) # Error when the admin is not a member of the channel that the message is within with pytest.raises(validation_helper.AccessError): stub.channel_leave(token, channel_id) stub.message_unpin(channel_id, message_id) stub.channel_join(token, channel_id) # successfully unpin a message assert stub.message_unpin(token, message_id) == {} # try and unpin a message again with pytest.raises(validation_helper.ValueError): stub.message_unpin(token, message_id)
def test_standup_send(): helper.reset_data() # SETUP START admin = helper.token_admin() token = admin["token"] channel_id = helper.channelid_public(token) text = "Hi" stub.standup_start(token, channel_id, 5) # Invalid inputs invalid_channel_id = -111111 invalid_text = 'Hi' * 1001 # SETUP END # Checks that it raises an error when the channel ID does not exit with pytest.raises(validation_helper.ValueError): stub.standup_send(token, invalid_channel_id, text) # Checks that it raises an error for > 1000 characters with pytest.raises(validation_helper.ValueError): stub.standup_send(token, channel_id, invalid_text) # Successfully send a message in a standup assert stub.standup_send(token, channel_id, text) == {} # Checks that it raises an error when user is not part of the channel with pytest.raises(validation_helper.AccessError): stub.channel_leave(admin["token"], channel_id) stub.standup_send(admin["token"], channel_id, text) # Checks that it raises an error if the standup time has stopped with pytest.raises(validation_helper.AccessError): time.sleep(6) stub.standup_send(token, channel_id, text)
def test_user_profile_setemail(): helper.reset_data() # SETUP START admin = helper.token_admin() token = admin["token"] profile_dict = stub.user_profile(admin["token"], admin["u_id"]) curr_email = profile_dict['email'] # New email new_email = "*****@*****.**" # Used email used_email = "*****@*****.**" # Invalid email invalid_email = "user.com" # SETUP END # Checks that it raises an error for used emails with pytest.raises(validation_helper.ValueError): stub.user_profile_setemail(token, used_email) # Checks that it raises an error for invalid emails with pytest.raises(validation_helper.ValueError): stub.user_profile_setemail(token, invalid_email) # Checks that the function has successfully changed valid email stub.user_profile_setemail(token, new_email) assert curr_email != new_email
def test_admin_userpermission_change(): helper.reset_data() user1 = helper.token_admin() user2 = helper.token_account_1() # Invalid token with pytest.raises(validation_helper.AccessError): stub.admin_userpermission_change("fake token", user2["u_id"], 2) with pytest.raises(validation_helper.ValueError): # check that validation_helper.ValueError is raised if u_id is not valid # Assumption: u_ids cannot be negative stub.admin_userpermission_change(user1["token"], -1, 2) with pytest.raises(validation_helper.ValueError): # check that validation_helper.ValueError is raised if permission_id is not valid stub.admin_userpermission_change(user1["token"], user1["u_id"], 10) # check that function can run if all inputs are valid stub.admin_userpermission_change(user1["token"], user2["u_id"], 1) # if previous call was successful, user2 should be able to change their own permissions # Assumption: users can change their own permissions provided they are currently an admin stub.admin_userpermission_change(user2["token"], user2["u_id"], 3) with pytest.raises(validation_helper.AccessError): # check that validation_helper.AccessError is raised if user is not an admin or owner # this should raise an error since user2 has removed their own permissions stub.admin_userpermission_change(user2["token"], user1["u_id"], 3)
def test_user_profiles_uploadphoto(): helper.reset_data() # SETUP START admin = helper.token_admin() token = admin["token"] img_url = "https://data.junkee.com/wp-content/uploads/2018/04/peppapig-680x454.jpg" x_start = 0 y_start = 0 x_end = 100 y_end = 100 # Invalid Inputs invalidx_start = -1 invalidx_end = -1 largex_start = 1000000 largex_end = 1000000 invalid_img = "https://www.peppapig.com/wp-content/uploads/sites/3/2019/02/peppa_pig_splat.png" # Checks that it raises an error for invalid bounds with pytest.raises(validation_helper.ValueError): stub.user_profiles_uploadphoto(token, img_url, invalidx_start, y_start, invalidx_end, y_end) # Checks that it raises an error for HTTP other than 200 with pytest.raises(validation_helper.ValueError): stub.user_profiles_uploadphoto(token, invalid_img, x_start, y_start, x_end, y_end) # Checks that it raises an error if bounds are not within image dimensions with pytest.raises(validation_helper.ValueError): stub.user_profiles_uploadphoto(token, img_url, largex_start, y_start, largex_end, y_end) # Checks that valid profile photo is updated stub.user_profiles_uploadphoto(token, img_url, x_start, y_start, x_end, y_end)
def test_simple_sendlater(): ''' Test sendlater with multiple messages in different channels ''' reset_data() # SETUP registered_user = auth_register('*****@*****.**', '123456', 'John', 'Smith') token = registered_user['token'] c_id = channel_create(token, 'Channel1', 'true') # SETUP END # Send message later time_sent = int(t.time() + 10) msg_id = message_sendlater(token, c_id, 'Hello world', time_sent) # Assert is stored for later assert check_later(msg_id) is msg_id # Sending message later in another channel c2_id = channel_create(token, 'Channel1', 'true') # Send message later time_sent = t.time() + 10 msg_id3 = message_sendlater(token, c2_id, 'Hello world', time_sent) # Assert message is in channel assert check_later(msg_id3) is msg_id3