def test_message_unpin(): storage.clear_data_store() # set up user (assuming user has admin privlages) dic1 = authentication.auth_register('*****@*****.**', 'password1', 'Bob', 'James') token1 = dic1['token'] # creat a valid channel in the name of user1 dic = channel_utils.channels_create(token1, 'name', True) channel_id_valid = dic['channel_id'] # message to pin/unpin message = "unPin me :)" token = token1 message_id = message_utils.message_send(token, channel_id_valid, message) message_utils.message_pin(token, message_id) # second user dic2 = authentication.auth_register('*****@*****.**', 'password2', 'Bobb', 'Jamesss') token2 = dic2['token'] # The authorised user isn't a member of the channel that contains the message # ACCESS ERROR token = token2 with pytest.raises(errors.AccessError): message_utils.message_unpin(token, message_id) # make the user a member of the channel, but not an admin channel_utils.channel_join(token2, channel_id_valid) # The authoriserd user isn't an admin # VALUE ERROR token = token2 with pytest.raises(ValueError): message_utils.message_unpin(token, message_id) # Everything valid token = token1 message_utils.message_unpin(token, message_id) # Prove that it worked channel = channel_utils.get_channel(channel_id_valid) assert channel['messages'][0]['is_pinned'] == False # Message_id isn't a valid message # VALUE ERROR token = token1 bad_message_id = -99 with pytest.raises(ValueError): message_utils.message_unpin(token, bad_message_id) # Message id is already unpinned # VALUE ERROR token = token1 with pytest.raises(ValueError): message_utils.message_unpin(token, message_id) pass
def test_auth_passwordreset_request(): """ Tests password reset request """ storage.clear_data_store() # pass a valid email email = "*****@*****.**" first_name = "test" last_name = "test" password = "******" authentication.auth_register(email, password, first_name, last_name) assert authentication.auth_passwordreset_request(email) # pass an email with no @ symbol email = "validemail.com" with pytest.raises(ValueError): authentication.auth_passwordreset_request(email) # pass an email with no .com suffix email = "valid@email" with pytest.raises(ValueError): authentication.auth_passwordreset_request(email) # Pass an email purely whitespaces email = " @ .com" with pytest.raises(ValueError): authentication.auth_passwordreset_request(email)
def test_auth_passwordreset_reset(): """ Tests reset password """ storage.clear_data_store() # Test valid code email = "*****@*****.**" first_name = "test" last_name = "test" password = "******" authentication.auth_register(email, password, first_name, last_name) valid_code = authentication.auth_passwordreset_request(email) assert authentication.auth_passwordreset_reset( valid_code, "new_password") == "new_password" storage.clear_data_store() # Test invalid code email = "*****@*****.**" first_name = "test" last_name = "test" password = "******" authentication.auth_register(email, password, first_name, last_name) invalid_code = "as980123" with pytest.raises(ValueError): authentication.auth_passwordreset_reset(invalid_code, "new_password") storage.clear_data_store() # test invalid password < len(password) reset_code = "1234" new_password = "******" with pytest.raises(ValueError): authentication.auth_passwordreset_reset(reset_code, new_password) # test invalid password only numebrs no characters reset_code = "1234" new_password = "******" with pytest.raises(ValueError): authentication.auth_passwordreset_reset(reset_code, new_password) # test password with just whitespace - 6 whitespaces reset_code = "1234" new_password = "******" with pytest.raises(ValueError): authentication.auth_passwordreset_reset(reset_code, new_password) # test invalid password with just characters reset_code = "1234" new_password = "******" with pytest.raises(ValueError): authentication.auth_passwordreset_reset(reset_code, new_password)
def test_message_edit(): # set up user storage.clear_data_store() dic1 = authentication.auth_register('*****@*****.**', 'password1', 'Bob', 'James') token1 = dic1['token'] # creat a valid channel in the name of user1 dic = channel_utils.channels_create(token1, 'name', False) channel_id_valid = dic['channel_id'] # Message to be edited message = "Unedited message" message_id = message_utils.message_send(token1, channel_id_valid, message) # When all of the following isn't true: # Meassage with message_id wasn't sent by the authorised user making the request # Meassage with message_id was not sent by an owner of this channel # Meassage with message_id was not sent by an admin or owner of the slack # VALUE ERROR dic2 = authentication.auth_register('*****@*****.**', 'password2', 'Bobby', 'Jamesy') token2 = dic2['token'] token = token2 message = "Editted message." with pytest.raises(errors.AccessError): message_utils.message_edit(token, message_id, message) # Message is too long (over 1000 characters). token = token1 message = "0123456789" * 101 with pytest.raises(ValueError): message_utils.message_edit(token, message_id, message) # Message_id is invalid. token = token1 bad_message_id = -99 message = "Editted message." with pytest.raises(errors.AccessError): message_utils.message_edit(token, bad_message_id, message) # Everything valid. token = token1 message = "Editted message." message_utils.message_edit(token, message_id, message) # Prove that it worked data = channel_utils.get_data() assert data["channels"][0]['messages'][0] == "Editted message." pass
def test_user_profile_setname(): storage.clear_data_store() user = authentication.auth_register( '*****@*****.**', 'password', 'Randy', 'Random') valid_token = user["token"] error_token = None # Try update a user's name correctly assert user_utils.user_profile_setname(valid_token, 'Short', 'Name') == {} # try with invalid token with pytest.raises(errors.AccessError): user_utils.user_profile_setname(error_token, 'Short', 'Name') # Try update a user's FIRST name to be too long with pytest.raises(ValueError): user_utils.user_profile_setname(valid_token, 'a' * 51, 'Name') # Try update a user's LAST name to be too long with pytest.raises(ValueError): user_utils.user_profile_setname(valid_token, 'Randy', 'a' * 51) # Try update a user's BOTH first and last name to be too long with pytest.raises(ValueError): user_utils.user_profile_setname(valid_token, 'a' * 51, 'a' * 51) # Test with an empty string with pytest.raises(ValueError): user_utils.user_profile_sethandle(valid_token, '')
def test_message_unreact(): storage.clear_data_store() # set up user dic1 = authentication.auth_register('*****@*****.**', 'password1', 'Bob', 'James') token1 = dic1['token'] # creat a valid channel in the name of user1 dic = channel_utils.channels_create(token1, 'name', False) channel_id_valid = dic['channel_id'] # message to be unreacted message = "unReact to me :)" message_id = message_utils.message_send(token1, channel_id_valid, message) # Setting the message to have been reacted to by token1 with a react_id 1 react_id = 1 message_utils.message_react(token1, message_id, react_id) # Everything valid. token = token1 react_id = 1 message_utils.message_unreact(token, message_id, react_id) # Prove that it worked channel = channel_utils.get_channel(channel_id_valid) u_id = authentication.decode_token(token)["u_id"] assert channel['messages'][0]['reacts'] == [{'is_this_user_reacted': False, \ 'react_id': 1, 'u_ids': []}] # message_id isn't a valid message within a channel that the user has joined # VALUE ERROR token = token1 message_id = -99 react_id = 1 with pytest.raises(ValueError): message_utils.message_unreact(token, message_id, react_id) # react id isn't valid # VALUE ERROR token = token1 react_id = -99 with pytest.raises(ValueError): message_utils.message_unreact(token, message_id, react_id) # message with id message_id does not contain an active react with given id # VALUE ERROR token = token1 react_id = 1 with pytest.raises(ValueError): message_utils.message_unreact(token, message_id, react_id) # Invalid token token = "Invalidtoken" react_id = 1 with pytest.raises(ValueError): message_utils.message_unreact(token, message_id, react_id)
def test_message_remove(): storage.clear_data_store() # set up user dic1 = authentication.auth_register('*****@*****.**', 'password1', 'Bob', 'James') token1 = dic1['token'] # Channel to post message which will be deleated dic = channel_utils.channels_create(token1, 'name', False) channel_id_valid = dic['channel_id'] # Message to be deleated message_id = message_utils.message_send(token1, channel_id_valid, "Hello") # ValueError when message doesn't exist # VALUE ERROR token = token1 message_id1 = -99 with pytest.raises(errors.AccessError): message_utils.message_remove(token, message_id1) # When all of the following isn't true: # Meassage with message_id wasn't sent by the authorised user making the request # Meassage with message_id was not sent by an owner of this channel # Meassage with message_id was not sent by an admin or owner of the slack # ACCESS ERROR # second user without access dic2 = authentication.auth_register('*****@*****.**', 'password2', 'Bobby', 'Jamesy') token2 = dic2['token'] token = token2 with pytest.raises(errors.AccessError): message_utils.message_remove(token, message_id) # Everything valid token = token1 message_utils.message_remove(token, message_id) # Check channel = channel_utils.get_channel(channel_id_valid) assert channel['messages'] == [] pass
def test_standup_start(): storage.clear_data_store() # set up user dic1 = authentication.auth_register('*****@*****.**', 'password1', 'Bob', 'James') token1 = dic1['token'] # creat a valid channel in the name of user1 dic = channel_utils.channels_create(token1, 'name', False) channel_id_valid = dic['channel_id'] # set up 2nd user dic2 = authentication.auth_register('*****@*****.**', 'password11', 'Bobby', 'Jamesy') token2 = dic2['token'] # Valid token, valid channel_id, but no access: usertoken = token2 channel_id = channel_id_valid with pytest.raises(errors.AccessError): standup.standup_start(usertoken, channel_id) # Valid token, valid channel_id: usertoken = token1 channel_id = channel_id_valid time = standup.standup_start(usertoken, channel_id) data = channel_utils.get_data() assert time < datetime.datetime.now() + datetime.timedelta(minutes=16) assert time > datetime.datetime.now() + datetime.timedelta(minutes=14) assert time == data["channels"][0]["standup_time"] # invalid token, valid channel_id: usertoken = "invalidToken" channel_id = channel_id_valid with pytest.raises(ValueError): standup.standup_start(usertoken, channel_id) # valid token, invalid channel_id: usertoken = token1 channel_id = 9191 with pytest.raises(ValueError): standup.standup_start(usertoken, channel_id)
def test_user_profile_setemail(): storage.clear_data_store() user = authentication.auth_register( '*****@*****.**', 'password', 'Randy', 'Random') valid_token = user["token"] error_token = None # Try update a user's email correctly assert user_utils.user_profile_setemail( valid_token, '*****@*****.**') == {} # Try setting an email that already exists user = authentication.auth_register( '*****@*****.**', 'password', 'Randy', 'Random') valid_token = user["token"] with pytest.raises(errors.AccessError): user_utils.user_profile_setemail( error_token, '*****@*****.**') with pytest.raises(ValueError): user_utils.user_profile_setemail( valid_token, '*****@*****.**') # Set an email that already exists with leading and trailing whitespace with pytest.raises(ValueError): user_utils.user_profile_setemail( valid_token, ' [email protected] ') # Try setting an invalid email (missing @) with pytest.raises(ValueError): user_utils.user_profile_setemail(valid_token, 'wrong') # Try setting an invalid email (empty string) with pytest.raises(ValueError): user_utils.user_profile_setemail(valid_token, '') # Try setting an invalid email with pytest.raises(ValueError): user_utils.user_profile_setemail(valid_token, ' @.com')
def auth_register(): email = request.form.get("email") password = request.form.get("password") first_name = request.form.get("name_first") last_name = request.form.get("name_last") res = auth_utils.auth_register(email, password, first_name, last_name) return dumps(res)
def test_user_profile_sethandle(): storage.clear_data_store() user = authentication.auth_register( '*****@*****.**', 'password', 'Randy', 'Random') valid_token = user["token"] error_token = None # Try update a user's handle correctly assert user_utils.user_profile_sethandle( valid_token, '*****@*****.**') == {} # Test with a handle that is too long (>20 chars) with pytest.raises(ValueError): user_utils.user_profile_sethandle( valid_token, 'a' * 21) # Test with a handle that is already used with pytest.raises(errors.AccessError): user_utils.user_profile_sethandle( error_token, 'validhanlde') # Test with a handle that is already used with pytest.raises(ValueError): user_utils.user_profile_sethandle( valid_token, '*****@*****.**') # Test with an empty string with pytest.raises(ValueError): user_utils.user_profile_sethandle(valid_token, '') # Test with an Blank with pytest.raises(ValueError): user_utils.user_profile_sethandle(valid_token, ' ') # Test with a handle that already exists but with a space on the end with pytest.raises(ValueError): user_utils.user_profile_sethandle(valid_token, '[email protected] ') # Test with a handle that already exists but with more than one space on the end with pytest.raises(ValueError): user_utils.user_profile_sethandle(valid_token, '[email protected] ') storage.clear_data_store()
def test_auth_logout(): """ Tests logout """ storage.clear_data_store() # test a simple logout email = "*****@*****.**" first_name = "test" last_name = "test" password = "******" user = authentication.auth_register(email, password, first_name, last_name) token = user["token"] assert authentication.auth_logout(token) # Should return None because token is expired assert authentication.decode_token(user["token"]) is None # test logout invalid token assert not authentication.auth_logout("invalid")
def test_user_profile(): storage.clear_data_store() # Get valid user's profile user = authentication.auth_register( '*****@*****.**', 'password', 'Randy', 'Random') valid_uid = user["u_id"] valid_token = user["token"] valid_profile = user_utils.user_profile(valid_token, valid_uid) assert "email" in valid_profile and valid_profile["email"] assert "name_first" in valid_profile and valid_profile["name_first"] assert "name_last" in valid_profile and valid_profile["name_last"] assert "handle_str" in valid_profile and valid_profile["handle_str"] # Get user profile with an invalid u_id invalid_uid = '-1' with pytest.raises(ValueError): user_utils.user_profile(valid_token, invalid_uid)
def test_message_sendlater(): storage.clear_data_store() # set up user dic1 = authentication.auth_register('*****@*****.**', 'password1', 'Bob', 'James') token1 = dic1['token'] # creat a valid channel in the name of user1 dic = channel_utils.channels_create(token1, 'name', False) channel_id_valid = dic['channel_id'] # Everything valid. token = token1 channel_id = channel_id_valid message = "Valid message." time_sent = datetime(2019, 10, 31, 10, 10) message_id = message_utils.message_sendlater(token, channel_id, message, time_sent) # Prove it worked u_id = authentication.decode_token(token)["u_id"] channel = channel_utils.get_channel(channel_id) assert channel['messages'][0]['message_id'] == message_id # Token invaid token = "NotValid" channel_id = channel_id_valid message = "Valid message." time_sent = datetime(2019, 10, 31, 10, 10) with pytest.raises(ValueError): message_utils.message_sendlater(token, channel_id, message, time_sent) # The channel which the message is getting posted too doesn't exist # VALUE ERROR token = token1 channel_id = -12 message = "Valid message." time_sent = datetime(2019, 10, 31, 10, 10) # use channel_list with pytest.raises(ValueError): message_utils.message_sendlater(token, channel_id, message, time_sent) # set up another channel, which the original user doesn't have access too dic2 = authentication.auth_register('*****@*****.**', 'password2', 'Bobby', 'Jamesy') token2 = dic2['token'] # creat a valid channel in the name of user1 dic_a = channel_utils.channels_create(token2, 'name', False) channel_id_valid1 = dic_a['channel_id'] # User lacks access to current channel trying to post in. token = token1 channel_id = channel_id_valid1 message = "Valid message" time_sent = datetime(2019, 10, 31, 10, 10) with pytest.raises(errors.AccessError): message_utils.message_sendlater(token, channel_id, message, time_sent) # Message is too long (over 1000 characters). # VALUE ERROR token = token1 channel_id = channel_id_valid message = "0123456789" * 101 time_sent = datetime(2019, 10, 31, 10, 10) with pytest.raises(ValueError): message_utils.message_sendlater(token, channel_id, message, time_sent) # Time sent is in the past # VALUE ERROR token = token1 channel_id = channel_id_valid message = "Valid message." time_sent = datetime(2019, 8, 31, 10, 10) with pytest.raises(ValueError): message_utils.message_sendlater(token, channel_id, message, time_sent) pass
def test_message_send(): storage.clear_data_store() # set up user dic1 = authentication.auth_register('*****@*****.**', 'password1', 'Bob', 'James') token1 = dic1['token'] # creat a valid channel in the name of user1 dic = channel_utils.channels_create(token1, 'name', False) channel_id_valid = dic['channel_id'] # Value error when message too long # VALUE ERROR token = token1 channel_id = channel_id_valid message = "0123456789" * 101 with pytest.raises(ValueError): message_utils.message_send(token, channel_id, message) # Invalid token. token = "InvalidToken" channel_id = channel_id_valid message = "Valid message" with pytest.raises(ValueError): message_utils.message_send(token, channel_id, message) # Channel_id doesn't exist. token = token1 channel_id = -1 message = "Valid message" with pytest.raises(ValueError): message_utils.message_send(token, channel_id, message) # set up another channel, which the original user doesn't have access too dic2 = authentication.auth_register('*****@*****.**', 'password2', 'Bobby', 'Jamesy') token2 = dic2['token'] # creat a valid channel in the name of user1 dic_a = channel_utils.channels_create(token2, 'matth', False) channel_id_valid1 = dic_a['channel_id'] # User lacks access to current channel trying to post in. token = token1 channel_id = channel_id_valid1 message = "Valid message" with pytest.raises(errors.AccessError): message_utils.message_send(token, channel_id, message) # Everything Valid token = token1 channel_id = channel_id_valid message = "Valid message" message_id = message_utils.message_send(token, channel_id, message) u_id = authentication.decode_token(token)["u_id"] channel = channel_utils.get_channel(channel_id) assert channel['messages'][0]['message_id'] == message_id assert channel['messages'][0]['u_id'] == u_id assert channel['messages'][0]['message'] == "Valid message" assert channel['messages'][0]['reacts'] == [{ 'react_id': 1, 'u_ids': [], 'is_this_user_reacted': False }] assert channel['messages'][0]['is_pinned'] == False # send a second message message = "Second message" token = token1 message_id2 = message_utils.message_send(token, channel_id, message) channel = channel_utils.get_channel(channel_id) assert channel['messages'][0]['message_id'] == message_id2 assert channel['messages'][1]['message_id'] == message_id
def test_admin_userpermission_change(): storage.clear_data_store() result = authentication.auth_register( '*****@*****.**', 'password', 'Randy', 'Random') valid_primary_uid = result["u_id"] valid_primary_token = result["token"] result = authentication.auth_register( '*****@*****.**', 'password', 'Randy', 'Random') valid_test_uid = result["u_id"] valid_test_token = result["token"] # Try update a user's permission levels # Set to user level (3) with pytest.raises(errors.AccessError): admin.admin_userpermission_change("invalid_token", valid_test_uid, 3) # Try update a user's permission levels # Set to user level (3) assert admin.admin_userpermission_change(valid_primary_token, valid_test_uid, 3) # Set to admin level (2) assert admin.admin_userpermission_change(valid_primary_token, valid_test_uid, 2) # set to owner level (1) assert admin.admin_userpermission_change(valid_primary_token, valid_test_uid, 1) # Test with invalid user id with pytest.raises(ValueError): admin.admin_userpermission_change(valid_primary_token, -1, 1) # Test with an invalid permission id with pytest.raises(ValueError): admin.admin_userpermission_change(valid_primary_token, valid_test_uid, -1) # Test access permissions (not at least an admin) # Demote the test user to member first assert admin.admin_userpermission_change(valid_primary_token, valid_test_uid, 3) # Should raise AccessError with pytest.raises(errors.AccessError): assert admin.admin_userpermission_change(valid_test_token, valid_primary_uid, 2) # Should be unable to modify self permissions (to prevent having no one with admin powers left) with pytest.raises(ValueError): assert admin.admin_userpermission_change(valid_primary_token, valid_primary_uid, 3) # Test admin modifying an owner (should raise AccessError) assert admin.admin_userpermission_change(valid_primary_token, valid_test_uid, 2) with pytest.raises(errors.AccessError): assert admin.admin_userpermission_change(valid_test_token, valid_primary_uid, 3) storage.clear_data_store()
def test_auth_login(): """ Tests login """ storage.clear_data_store() # test for an email with no word before the @ symbol email = "@938.com" password = "******" with pytest.raises(ValueError): authentication.auth_login(email, password) # test for an email missing the @ symbol email = "myname938.com" password = "******" with pytest.raises(ValueError): authentication.auth_login(email, password) # test for an email that uses whitespaces as input: email = " @ .com" password = "******" with pytest.raises(ValueError): authentication.auth_login(email, password) # test for an email missing the .com suffix email = "myname938" password = "******" with pytest.raises(ValueError): authentication.auth_login(email, password) # test an invalid password < len(5) email = "*****@*****.**" password = "******" with pytest.raises(ValueError): authentication.auth_login(email, password) # test for a password that uses only whitespaces email = "*****@*****.**" password = "******" with pytest.raises(ValueError): authentication.auth_login(email, password) # test for a valid password email = "*****@*****.**" password = "******" with pytest.raises(ValueError): authentication.auth_login(email, password) # test logining in as a valid user # first create the user first_name = "Bob" last_name = "James" email = "*****@*****.**" password = "******" reg_res = authentication.auth_register( email, password, first_name, last_name) u_id = reg_res["u_id"] token = reg_res["token"] # then login as the user email = "*****@*****.**" password = "******" result = authentication.auth_login(email, password) # check u_id matches assert "u_id" in result and result["u_id"] == u_id # check token exists and is NOT the same as the registration token (should have expired) assert "token" in result and result["token"] != token # Check for wrong password with pytest.raises(ValueError): authentication.auth_login(email, "NotTheCorrectPassword")
def test_auth_register(): """ Tests registering users """ storage.clear_data_store() # test an invalid first name and last name > 50 characters first_name = "a" * 100 last_name = "B" * 100 email = "*****@*****.**" password = "******" with pytest.raises(ValueError): authentication.auth_register(email, password, first_name, last_name) storage.clear_data_store() # test an invalid first name > 50 characters first_name = "a" * 100 last_name = "B" * 5 email = "*****@*****.**" password = "******" with pytest.raises(ValueError): authentication.auth_register(email, password, first_name, last_name) storage.clear_data_store() # test an invalid last name > 50 characters first_name = "a" * 5 last_name = "B" * 100 email = "*****@*****.**" password = "******" with pytest.raises(ValueError): authentication.auth_register(email, password, first_name, last_name) storage.clear_data_store() # test an invalid password < len(5) first_name = "hello" last_name = "hello" email = "*****@*****.**" password = "******" with pytest.raises(ValueError): authentication.auth_register(email, password, first_name, last_name) storage.clear_data_store() # test an invalid password no characters only numbers first_name = "hello" last_name = "hello" email = "*****@*****.**" password = "******" with pytest.raises(ValueError): authentication.auth_register(email, password, first_name, last_name) storage.clear_data_store() # test an invalid password only whitespace first_name = "hello" last_name = "hello" email = "*****@*****.**" password = "******" with pytest.raises(ValueError): authentication.auth_register(email, password, first_name, last_name) storage.clear_data_store() # test authenticating a valid user first_name = "Bob" last_name = "James" email = "*****@*****.**" password = "******" u_id, token = authentication.auth_register( email, password, first_name, last_name) assert u_id is not None assert token is not None storage.clear_data_store() # test for invalid email and password, but valid first_name and last_name first_name = "Bob" last_name = "James" email = " " password = "******" with pytest.raises(ValueError): authentication.auth_register(email, password, first_name, last_name) storage.clear_data_store() # create a user with 40 character first name and last name first_name = "papappapappapappapappapappapappapappapap" last_name = "papappapappapappapappapappapappapappapap" email = "*****@*****.**" password = "******" u_id, token = authentication.auth_register( email, password, first_name, last_name) assert u_id is not None assert token is not None storage.clear_data_store() # create an invalid user with a first_name and last_name that contains numbers first_name = "pap23" last_name = "dragonSlayer55" email = "*****@*****.**" password = "******" with pytest.raises(ValueError): authentication.auth_register(email, password, first_name, last_name) storage.clear_data_store() # create an invalid user with a first_name and last_name that symbols first_name = "pap@23" last_name = "dragonSlayer55!" email = "*****@*****.**" password = "******" with pytest.raises(ValueError): authentication.auth_register(email, password, first_name, last_name) storage.clear_data_store() # Use an existing email first_name = "test" last_name = "test" email = "*****@*****.**" password = "******" authentication.auth_register(email, password, first_name, last_name) with pytest.raises(ValueError): authentication.auth_register(email, password, first_name, last_name) storage.clear_data_store() # Use an invalid email first_name = "test" last_name = "test" email = "notaemail.com" password = "******" with pytest.raises(ValueError): authentication.auth_register(email, password, first_name, last_name) storage.clear_data_store()
def test_search(): storage.clear_data_store() # User to search dic1 = authentication.auth_register('*****@*****.**', 'password1', 'Bob', 'James') token1 = dic1['token'] # Second user dic2 = authentication.auth_register('*****@*****.**', 'password3', 'Bb', 'Js') token2 = dic2['token'] # channel to search through dic = channel_utils.channels_create(token1, 'name', False) channel_id_valid = dic['channel_id'] # Submit messages message = "Valid message" message_id = message_utils.message_send(token1, channel_id_valid, message) message = "second message" message_id = message_utils.message_send(token1, channel_id_valid, message) message = "third message" message_id = message_utils.message_send(token1, channel_id_valid, message) # Messages in the channel # Search using a valid token for a query which doesn't exist token = token1 queryString = "hello" assert search.search(token, queryString) == [] token = token1 queryString = "Va" assert search.search(token, queryString)[0]['message'] == "Valid message" token = token1 queryString = " mess" assert search.search(token, queryString)[1]['message'] == "second message" # Serch using a valid token, without access to the channel where the messages are token = token2 queryString = " mess" assert search.search(token, queryString) == [] # search using an invalid token for a valid string. token = "invalid" queryString = "wassup" with pytest.raises(ValueError): search.search(token, queryString) # handle whitespace as a query string. token = token1 queryString = " " assert search.search(token, queryString) == [] # handle 1000 characters - Different words. token = token1 queryString = "Hello There Lorem ipsum dolor sit amet, consectetuer \ adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. \ Cum sociis natoque penatibus et magnis dis parturient montes, nascetur \ ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium \ quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, \ aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, \ venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer \ tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate \ eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend \ ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. \ Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. \ Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. \ Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper\ libero, sit amet adipiscing sem neque sed ipsum. N" with pytest.raises(ValueError): search.search(token, queryString) # handle 1001 characters - Same letter. token = token1 queryString = "H" * 1001 with pytest.raises(ValueError): search.search(token, queryString)
def test_standup_send(): storage.clear_data_store() # set up user dic1 = authentication.auth_register('*****@*****.**', 'password1', 'Bob', 'James') token1 = dic1['token'] # creat a valid channel in the name of user1 dic = channel_utils.channels_create(token1, 'name', False) channel_id_valid = dic['channel_id'] # No active standup usertoken = token1 channel_id = channel_id_valid message = "No start up" with pytest.raises(ValueError): standup.standup_send(usertoken, channel_id, message) # Start the standup standup.standup_start(usertoken, channel_id) # Valid token, valid channel_id: usertoken = token1 channel_id = channel_id_valid message = "Stand up active" standup.standup_send(usertoken, channel_id, message) data = channel_utils.get_data() assert data["channels"][0]["standup_time"] == data["channels"][0][ "messages"][0]["time_created"] # Error when Channel does not exist message = "Hello There" usertoken = "mytoken1234" channel_id = 12123 # this is an invalid channel with pytest.raises(ValueError): standup.standup_send(usertoken, channel_id, message) # Error when message > 1000 chars message = "H" * 1001 usertoken = "mytoken1234" channel_id = 1 with pytest.raises(ValueError): standup.standup_send(usertoken, channel_id, message) # set up 2nd user, which isn't a member of the channel dic2 = authentication.auth_register('*****@*****.**', 'password12', 'Boby', 'Jamesy') token2 = dic2['token'] # AccessError if the user is authorised, but not a member of the channel message = "Hello There" usertoken = token2 channel_id = channel_id_valid with pytest.raises(errors.AccessError): standup.standup_send(usertoken, channel_id, message) # Error if user doesn't exist message = "Hello There" usertoken = "mytoken1234" channel_id = channel_id_valid with pytest.raises(ValueError): standup.standup_send(usertoken, channel_id, message)