def test_react_bad(): data = generate_data() user_admin = getting_user(data)[0] message_admin = getting_message(data)[0] assert react_unreact(data, user_admin.token, 100, 1, 'react') == { 'ValueError': 'Message (based on ID) no longer exists' } assert react_unreact(data, user_admin.token, message_admin.message_id, 100, 'react') == { 'ValueError': 'react_id is not a valid React ID' }
def message_unreact(): global data message_id, react_id, token = do_get(request.form, ['message_id', 'react_id', 'token']) result = react_unreact(data, token, int(message_id), int(react_id), 'unreact') catch_error_and_return(result) save() return dumps(result)
def message_unreact(): global data message_id = int(request.form.get('message_id')) react_id = int(request.form.get('react_id')) token = request.form.get('token') output = react_unreact(data, token, message_id, react_id, 'unreact') if 'ValueError' in output: raise ValueError(description=output['ValueError']) save() return dumps(output)
def get_data(): test_data = Data() user_chowner = register(test_data, '*****@*****.**', 'password', 'name_first1', 'name_last', 'http://127.0.0.1:5555/') user_inch = register(test_data, '*****@*****.**', 'password', 'name_first2', 'name_last', 'http://127.0.0.1:5555/') register(test_data, '*****@*****.**', 'password', 'name_first3', 'name_last', 'http://127.0.0.1:5555/') channel = ch_create(test_data, user_chowner['token'], 'test_channel', True) ch_join_leave(test_data, user_inch['token'], channel['channel_id'], 'join') message_inch = send_message(test_data, user_inch['token'], channel['channel_id'], 'test2') message_chowner = send_message(test_data, user_chowner['token'], channel['channel_id'], 'test') react_unreact(test_data, user_inch['token'], message_inch['message_id'], 1, 'react') react_unreact(test_data, user_inch['token'], message_chowner['message_id'], 1, 'react') ch_create(test_data, user_chowner['token'], 'test_channel2', True) return test_data
def test_react_good(): data = generate_data() user_admin, user_owner, user_in_channel, user_notin_channel = getting_user( data) message_admin = getting_message(data)[0] # React the message in advance # If the next text raises an exception means the react is successfully added output = react_unreact(data, user_admin.token, message_admin.message_id, 1, 'react') assert output == {} output = react_unreact(data, user_owner.token, message_admin.message_id, 1, 'react') assert output == {} output = react_unreact(data, user_in_channel.token, message_admin.message_id, 1, 'react') assert output == {} # React the message again see whether raise exception assert react_unreact(data, user_admin.token, message_admin.message_id, 1, 'react') == { 'ValueError': 'user has reacted' }
def test_unreact_bad(): data = generate_data() user_admin, user_owner, user_in_channel, user_notin_channel = getting_user( data) message_admin = getting_message(data)[0] # react in advance react_unreact(data, user_admin.token, message_admin.message_id, 1, 'react') react_unreact(data, user_owner.token, message_admin.message_id, 1, 'react') react_unreact(data, user_in_channel.token, message_admin.message_id, 1, 'react') assert react_unreact(data, user_admin.token, 100, 1, 'unreact') == { 'ValueError': 'Message (based on ID) no longer exists' } assert react_unreact(data, user_admin.token, message_admin.message_id, 100, 'unreact') == { 'ValueError': 'react_id is not a valid React ID' }
def test_unreact_good(): data = generate_data() user_admin, user_owner, user_in_channel, user_notin_channel = getting_user( data) message_admin = getting_message(data)[0] # react in advance react_unreact(data, user_admin.token, message_admin.message_id, 1, 'react') react_unreact(data, user_owner.token, message_admin.message_id, 1, 'react') react_unreact(data, user_in_channel.token, message_admin.message_id, 1, 'react') # Unreact the message again see whether raise excepion output = react_unreact(data, user_admin.token, message_admin.message_id, 1, 'unreact') assert output == {} output = react_unreact(data, user_owner.token, message_admin.message_id, 1, 'unreact') assert output == {} output = react_unreact(data, user_in_channel.token, message_admin.message_id, 1, 'unreact') assert output == {} # React the message again see whether raise exception assert react_unreact(data, user_admin.token, message_admin.message_id, 1, 'unreact') == { 'ValueError': 'user has not reacted' } assert react_unreact(data, user_owner.token, message_admin.message_id, 1, 'unreact') == { 'ValueError': 'user has not reacted' } assert react_unreact(data, user_in_channel.token, message_admin.message_id, 1, 'unreact') == { 'ValueError': 'user has not \ reacted' }