def test_successful_remove(): # normal remove msg_send(token1, '3rd msg', chan_id1) msg_id1 = data['channels'][0].messages[0].message_id msg_id3 = data['channels'][0].messages[2].message_id assert len(data['channels'][0].messages) == 3 assert msg_remove(token1, msg_id1) == {} assert len(data['channels'][0].messages) == 2 assert msg_remove(token1, msg_id3) == {} assert len(data['channels'][0].messages) == 1
def route_msg_remove(): token = request.form.get('token') msg_id = int(request.form.get('message_id')) return dumps(msg_remove(token, msg_id))
def test_msgid_notexist(): # when the message_id no longer exist or does not exist with pytest.raises(ValueError): msg_remove(token1, 12345)
def test_remover_notsender(): # when remover is not the actual sender of the message msg_send(token3, '3rd msg', chan_id1) msg_id3 = data['channels'][0].messages[2].message_id with pytest.raises(AccessError): msg_remove(token1, msg_id3)
def test_notowner_remove(): # when remover is not an owner msg_send(token3, '2nd msg', chan_id1) msg_id2 = data['channels'][0].messages[1].message_id with pytest.raises(AccessError): msg_remove(token3, msg_id2)