def test_invalid_token(): global my_users setupDict = setup() message_id = message_send(setupDict['token'], setupDict['channel_id'], 'A new message') auth_logout(setupDict['token']) with pytest.raises(AccessError, match=r'User is not a valid user') as excinfo: message_edit(setupDict['token'], message_id['message_id'], "Hello") assert excinfo.type == AccessError
def test_standard_edit(): global my_users setupDict = setup() message_id = message_send(setupDict['token'], setupDict['channel_id'], 'A new message') message_edit(setupDict['token'], message_id['message_id'], "Hello") start = 0 reply = channel_messages(setupDict['token'], setupDict['channel_id'], start) # dictionary reply_messages = reply['messages'] #list first_message = reply_messages[0] #dictionary assert first_message['message'] == "Hello"
def test_not_owner_or_poster(): global my_users setupDict = setup() auth_register("*****@*****.**", "password", "Student", "Citizen") userDict = auth_login("*****@*****.**", 'password') channel_invite(setupDict['token'], setupDict['channel_id'], userDict['u_id']) message_id = message_send(setupDict['token'], setupDict['channel_id'], 'A new message') with pytest.raises(AccessError, match=r'Not authorized user of message') as excinfo: message_edit(userDict['token'], message_id['message_id'], "Hello") assert excinfo.type == AccessError
def test_message_creator(): global my_users setupDict = setup() auth_register("*****@*****.**", "password", "Student", "Citizen") userDict = auth_login("*****@*****.**", 'password') channel_invite(setupDict['token'], setupDict['channel_id'], userDict['u_id']) message_id = message_send(userDict['token'], setupDict['channel_id'], 'A new message') message_edit(userDict['token'], message_id['message_id'], "Hello") start = 0 reply = channel_messages(setupDict['token'], setupDict['channel_id'], start) # dictionary reply_messages = reply['messages'] #list first_message = reply_messages[0] #dictionary assert first_message['message'] == "Hello"
def run_message_edit(): """ Run the message_edit function to edit a message and update the server database """ request_data = request.form return_value = message.message_edit(request_data["token"], int(request_data["message_id"]), request_data["message"]) return dumps(return_value)
def edit_message(): token = request.form.get('token') message_id = request.form.get('message_id') message = request.form.get('message') try: edit = message_edit(token, int(message_id), message) return sendSuccess({}) except ValueError as e: return sendError(400, "ValueError", e.args) except AccessError as a: return sendError(401, "AccessError", a.args)
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 edit(): token = get_args('token') message_id = int(get_args('message_id')) message = get_args('message') return dumps(message_edit(token, message_id, message))