def test_unpin_good(): data = generate_data() user_admin = getting_user(data)[0] message_admin = getting_message(data)[0] # Pin the message in advance, if the next test raise exception # means the message is successfully pinned pin_unpin(data, user_admin.token, message_admin.message_id, 'pin') output = pin_unpin(data, user_admin.token, message_admin.message_id, 'unpin') assert output == {}
def test_pin_good(): data = generate_data() user_admin, user_owner, user_in_channel, user_notin_channel = getting_user( data) message_admin = getting_message(data)[0] # Pin the message in advance, if the next test raise exception # means the message is successfully pinned output = pin_unpin(data, user_admin.token, message_admin.message_id, 'pin') assert output == {} assert pin_unpin(data, user_admin.token, message_admin.message_id, 'pin') == { "ValueError": "Message with ID message_id is already pinned" }
def message_unpin(): global data message_id, token = do_get(request.form, ['message_id', 'token']) result = pin_unpin(data, token, int(message_id), 'unpin') catch_error_and_return(result) save() return dumps(result)
def message_unpin(): global data message_id = int(request.form.get('message_id')) token = request.form.get('token') output = pin_unpin(data, token, message_id, 'unpin') if 'ValueError' in output: raise ValueError(description=output['ValueError']) if 'AccessError' in output: raise AccessError(description=output['AccessError']) save() return dumps(output)
def test_unpin_bad(): data = generate_data() user_admin, user_owner, user_in_channel, user_notin_channel = getting_user( data) channel = getting_channel(data) message_admin = getting_message(data)[0] # Invalid input assert pin_unpin(data, user_admin.token, 100, 'unpin') == { 'ValueError': 'message_id is not a valid message' } assert pin_unpin(data, user_owner.token, message_admin.message_id, 'unpin') == { 'ValueError': 'The authorised user is not an admin' } assert pin_unpin(data, user_notin_channel.token, message_admin.message_id, 'unpin') == { 'AccessError': 'The authorised user is not \ a member of the channel that the message is within' } assert pin_unpin(data, user_admin.token, message_admin.message_id, 'unpin') == { "ValueError": "Message with ID message_id is already unpinned" } # admin leave the channel ch_join_leave(data, user_admin.token, channel.channel_id, 'leave') assert pin_unpin(data, user_admin.token, message_admin.message_id, 'unpin') == { 'AccessError': 'The authorised user is not a member of the channel \ that the message is within' }
def test_pin_bad(): data = generate_data() user_admin, user_owner, user_in_channel, user_notin_channel = getting_user( data) message_admin = getting_message(data)[0] # Invalid input assert pin_unpin(data, user_admin.token, 100, 'pin') == { 'ValueError': '\ message_id is not a valid message' } assert pin_unpin(data, user_in_channel.token, message_admin.message_id, 'pin') == { 'ValueError': 'The authorised user is not an admin' } assert pin_unpin(data, user_notin_channel.token, message_admin.message_id, 'pin') == { 'AccessError': 'The authorised user is not a member of the channel \ that the message is within' }