Esempio n. 1
0
def test_success_no_delay(create_input):
    assert channel_messages_v2(create_input[0][0]["token"],
                               create_input[1][0]["channel_id"],
                               0).json()["messages"] == []
    current_time = int(time.time())
    msg = message_sendlater_v1(create_input[0][0]["token"],
                               create_input[1][0]["channel_id"], "Hey there!",
                               current_time).json()
    assert type(msg) == dict
    assert type(msg["message_id"]) == int

    # Message should have been sent already
    msgs = channel_messages_v2(create_input[0][0]["token"],
                               create_input[1][0]["channel_id"],
                               0).json()["messages"]
    assert len(msgs) == 1
    assert msgs[0]["message"] == "Hey there!"
    assert msgs[0]["time_created"] == current_time
Esempio n. 2
0
def test_mixed_success(create_input):
    current_time = int(time.time())
    message_send_v2(create_input[0][0]["token"],
                    create_input[1][0]["channel_id"],
                    "This is the first normal message")
    assert len(
        channel_messages_v2(create_input[0][0]["token"],
                            create_input[1][0]["channel_id"],
                            0).json()["messages"]) == 1
    msg = message_sendlater_v1(create_input[0][1]["token"],
                               create_input[1][0]["channel_id"],
                               "Hey there, I'm from the past!",
                               current_time + 2).json()
    assert type(msg) == dict
    assert type(msg["message_id"]) == int
    message_send_v2(create_input[0][2]["token"],
                    create_input[1][0]["channel_id"],
                    "This is the second normal message")

    # Make sure delayed message has not been sent yet
    msgs = channel_messages_v2(create_input[0][1]["token"],
                               create_input[1][0]["channel_id"],
                               0).json()["messages"]
    assert len(msgs) == 2

    # Wait 2.5 seconds and check again; delayed message should be there
    time.sleep(2.5)
    msgs = channel_messages_v2(create_input[0][1]["token"],
                               create_input[1][0]["channel_id"],
                               0).json()["messages"]
    assert len(msgs) == 3
    assert msgs[0]["message"] == "Hey there, I'm from the past!"
    assert msgs[0]["time_created"] == current_time + 2
    assert msgs[1]["message"] == "This is the second normal message"
    assert msgs[1]["time_created"] == current_time
    assert msgs[2]["message"] == "This is the first normal message"
    assert msgs[2]["time_created"] == current_time
Esempio n. 3
0
def test_simple_success(create_input):
    assert channel_messages_v2(create_input[0][0]["token"],
                               create_input[1][0]["channel_id"],
                               0).json()["messages"] == []
    current_time = int(time.time())
    msg = message_sendlater_v1(create_input[0][0]["token"],
                               create_input[1][0]["channel_id"], "Hey there!",
                               current_time + 2).json()
    assert type(msg) == dict
    assert type(msg["message_id"]) == int

    # Make sure message has not been sent yet
    assert channel_messages_v2(create_input[0][0]["token"],
                               create_input[1][0]["channel_id"],
                               0).json()["messages"] == []

    # Wait 2.5 seconds and check again; message should be there
    time.sleep(2.5)
    msgs = channel_messages_v2(create_input[0][0]["token"],
                               create_input[1][0]["channel_id"],
                               0).json()["messages"]
    assert len(msgs) == 1
    assert msgs[0]["message"] == "Hey there!"
    assert msgs[0]["time_created"] == current_time + 2
Esempio n. 4
0
def test_invalid_token(create_input):
    assert message_sendlater_v1(
        123, create_input[1][1]["channel_id"], "I don't exist :(((",
        int(time.time()) + 2).status_code == ACCESS_ERROR
Esempio n. 5
0
def test_not_member(create_input):
    assert message_sendlater_v1(
        create_input[0][4]["token"], create_input[1][0]["channel_id"],
        "I'm not in this channel :(",
        int(time.time()) + 2).status_code == ACCESS_ERROR
Esempio n. 6
0
def test_time_sent_past(create_input):
    assert message_sendlater_v1(
        create_input[0][1]["token"], create_input[1][1]["channel_id"],
        "Hey from the future!",
        int(time.time()) - 20).status_code == INPUT_ERROR
Esempio n. 7
0
def test_message_too_long(create_input):
    msg = 'x' * 1001
    assert message_sendlater_v1(
        create_input[0][1]["token"], create_input[1][1]["channel_id"], msg,
        int(time.time()) + 2).status_code == INPUT_ERROR
Esempio n. 8
0
def test_invalid_channel(create_input):
    assert message_sendlater_v1(
        create_input[0][0]["token"], 123, "This message won't be sent",
        int(time.time()) + 2).status_code == INPUT_ERROR