コード例 #1
0
def test_remove_invalid_token():
    testData = create_data(1)

    testMessage = send(testData[0]['token'], testData[1]['channel_id'],
                       "Message")['message_id']
    testData[0]['token'] = "NOT_VALID_TOKEN"
    with pytest.raises(AccessError):
        remove("NOT_VALID_TOKEN", testMessage)
コード例 #2
0
def test_remove_unauthorised_not_admin():
    testData = create_data(1)
    testData2 = create_data(2)

    joi(testData2[0]['token'], testData[1]['channel_id'])
    # testData sent the message and is admin
    testMessage = send(testData2[0]['token'], testData[1]['channel_id'],
                       "Message")
    # testData sent the message and testData is the owner/admin of BOTH the slackr and the channel so testData 2 shouldn't be able to remove
    with pytest.raises(AccessError):
        remove(testData2[0]['token'], testMessage)
コード例 #3
0
def test_edit_empty_string():
    testData = create_data(1)

    testMessage = send(testData[0]['token'], testData[1]['channel_id'],
                       "This is a message that should be removed")
    result = edit(
        testData[0]['token'], testMessage,
        "")  # Should NOT throw an error here - should remove the message

    # First, a quick sanity check on the return value and type
    assert type(result) is dict
    assert result == {}

    # Now, we can check the message is actually gone by trying to remove it (should throw AccessError - should have been deleted)
    with pytest.raises(InputError):
        remove(testData[0]['token'], testMessage)
コード例 #4
0
def test_remove_authorised_not_admin():
    testData = create_data(1)
    testData2 = create_data(2)

    joi(testData2[0]['token'], testData[1]['channel_id'])

    # The user of testData2 sent the message; but is not an admin (did not joi the channel first - see assumptions)
    testMessage = send(testData2[0]['token'], testData[1]['channel_id'],
                       "Message")

    # The user of testData2 should still be able to remove the message
    result = remove(testData2[0]['token'], testMessage)
    assert type(result) is dict
    assert result == {}
コード例 #5
0
def test_remove_unauthorised_admin():
    # Create 1 admin of channel and 1 member of channel
    testData = create_data(1)
    testData2 = create_data(2)
    # The user of testData is owner (joied first - see assumptions)

    joi(testData2[0]['token'], testData[1]['channel_id'])
    testMessage = send(testData2[0]['token'], testData[1]['channel_id'],
                       "Test")

    # The user of testData2 sent the message but testData is the owner/admin of †he channel so should be able to remove
    result = remove(testData[0]['token'], testMessage)
    assert type(result) is dict
    assert result == {}
コード例 #6
0
def msg_remove():
    data = request.get_json()
    message.remove(data['token'], int(data['message_id']))
    return dumps({})
コード例 #7
0
def test_remove_createnot_found():
    testData = create_data(1)

    with pytest.raises(InputError):
        remove(testData[0]['token'], 000000000000)