Beispiel #1
0
def test_sendlater_valid_inputs(new_channel_and_user):
    '''
    checks that message is added to channels message after a delay
    '''
    token = new_channel_and_user['token']
    channel_id = new_channel_and_user['channel_id']
    time_sent = get_current_timestamp() + 2
    test_message = message_sendlater(token, channel_id, 'hi', time_sent)
    assert isinstance(test_message, dict)
    assert len(channel_messages(token, channel_id, 0)['messages']) == 0
    sleep(2.5)
    assert len(channel_messages(token, channel_id, 0)['messages']) == 1
Beispiel #2
0
def test_channel_messages_invalid_user(channel_dav, user_dav, user_chas):

    # There is only one message inside the channel
    msg_1 = message_send(user_dav['token'], channel_dav['channel_id'],
                         "message")

    with pytest.raises(AccessError):
        assert channel_messages(user_chas['token'], channel_dav['channel_id'],
                                0)
Beispiel #3
0
def test_channel_messages_invalid_start(channel_dav, user_dav):

    # There is only one message inside the channel
    msg_1 = message_send(user_dav['token'], channel_dav['channel_id'],
                         "message")

    with pytest.raises(InputError):
        assert channel_messages(user_dav['token'], channel_dav['channel_id'],
                                100)
Beispiel #4
0
def test_standup_send(new_channel_and_user):
    '''
    tests standup send correctly adds a message to a channel
    '''
    token = new_channel_and_user['token']
    channel_id = new_channel_and_user['channel_id']
    standup_start(token, channel_id, 1)
    standup_send(token, channel_id, 'Message 1')
    sleep(1.5)
    messages = channel_messages(token, channel_id, 0)
    assert len(messages['messages']) == 1
Beispiel #5
0
def test_standup_empty(new_channel_and_user):
    '''
    test function.
    tests that if no message was sent during a standup,
    the standup is discarded and not added to a channels messages.
    '''
    token = new_channel_and_user['token']
    channel_id = new_channel_and_user['channel_id']
    standup_start(token, channel_id, 1)
    sleep(1.5)
    messages = channel_messages(token, channel_id, 0)
    assert len(messages['messages']) == 0
Beispiel #6
0
def test_standup_send_invalid_message(new_channel_and_user):
    '''
    test function
    checks that standup_send raises an input error when given a message >1000 characters
    '''
    token = new_channel_and_user['token']
    channel_id = new_channel_and_user['channel_id']
    standup_start(token, channel_id, 1)
    with pytest.raises(InputError):
        standup_send(token, channel_id, '1' * 1001)
    sleep(1.5)
    messages = channel_messages(token, channel_id, 0)
    assert len(messages['messages']) == 0
Beispiel #7
0
def test_channel_messages_num_messages(channel_dav, user_dav):

    # Create couple messages
    message_send(user_dav['token'], channel_dav['channel_id'], "Message")
    message_send(user_dav['token'], channel_dav['channel_id'], "I love cs1531")
    message_send(user_dav['token'], channel_dav['channel_id'], "Make it")
    message_send(user_dav['token'], channel_dav['channel_id'], "can't do it")

    # Test 0
    # When the start index is 0
    test_0 = channel_messages(user_dav['token'], channel_dav['channel_id'], 0)

    assert test_0['start'] == 0
    assert test_0['end'] == -1
    assert len(test_0['messages']) == 4
    # Test 1
    # When the start index is 1
    test_1 = channel_messages(user_dav['token'], channel_dav['channel_id'], 1)

    assert test_1['start'] == 1
    assert test_1['end'] == -1
    assert len(test_1['messages']) == 3
Beispiel #8
0
def channel_messages_wsgi():
    json = request.args
    return jsonify(
        channel_messages(json['token'], int(json['channel_id']),
                         int(json['start'])))
Beispiel #9
0
def test_channel_messages_invalid_channel_id(user_dav):
    with pytest.raises(InputError):
        assert channel_messages(user_dav['token'], 0, 0)