Пример #1
0
def test_standup_send_valid():
    '''
    Test validly sending messages to get buffered in the standup queue
    '''
    clear()
    # Set up users and channel
    f_owner = auth_register('*****@*****.**', 'password', 'Flockr', 'Owner')
    f_user = auth_register('*****@*****.**', 'password', 'Random', 'User')
    f_channel = channels_create(f_owner['token'], 'Test Channel', True)
    channel_join(f_user['token'], f_channel['channel_id'])

    # Start standup for 5 seconds
    standup_start(f_owner['token'], f_channel['channel_id'], 5)

    # Users send messages during the standup
    message1 = 'F' * 1000
    message2 = 'X' * 1000
    for _ in range(0, 3):
        standup_send(f_owner['token'], f_channel['channel_id'], message1)
        standup_send(f_user['token'], f_channel['channel_id'], message2)

    # Check only one message (containing all the standup messages) is sent after the standup ends
    time.sleep(6)
    messages = channel_messages(f_owner['token'], f_channel['channel_id'], 0)
    assert len(messages['messages']) == 1
Пример #2
0
def test_standup_start_nvid():
    """ Tests if standup_start raises an InputError if the channel_id given is invalid. """

    user = auth.auth_register("*****@*****.**", "password", "Donkey", "Kong")

    with pytest.raises(error.InputError):
        standup.standup_start(user['token'], 100, 100)
Пример #3
0
def test_standup_start_invalid_channel_id():
    clear()
    user1 = register_n_users(1)

    invalid_channel_id = -1
    with pytest.raises(InputError):
        standup_start(user1["token"], invalid_channel_id, 1)
Пример #4
0
def test_standup_start_channel_running():
    time.sleep(1)
    _, wenyao_dict, _, channel_team1, _ = initialise_data()
    standup_start(wenyao_dict['token'], channel_team1['channel_id'], 5)
    with pytest.raises(InputError):
        assert standup_start(wenyao_dict['token'], channel_team1['channel_id'],
                             5)
Пример #5
0
def test_send_multiple():
    """
    Test if the standup_send can combine multiple message from send message
    """
    channel_creater = auth.auth_register("*****@*****.**", "password",
                                         "Quick", "Shadow")
    test_user1 = auth.auth_register("*****@*****.**", "password",
                                    "Optimus", "Prime")
    test_channel_id1 = channels.channels_create(channel_creater["token"],
                                                "test1", True)
    channel.channel_join(test_user1["token"], test_channel_id1["channel_id"])
    standup.standup_start(channel_creater["token"],
                          test_channel_id1["channel_id"], 1)
    creater_profile = user.user_profile(channel_creater["token"],
                                        channel_creater["u_id"])
    test_user_profile = user.user_profile(test_user1["token"],
                                          test_user1["u_id"])
    new_message = "Know the new message"
    new_message2 = "Second message"
    standup.standup_send(channel_creater["token"],
                         test_channel_id1["channel_id"], new_message)
    standup.standup_send(test_user1["token"], test_channel_id1["channel_id"],
                         new_message2)
    inserted_message = creater_profile["user"][
        "handle_str"] + ": " + new_message + "\n"
    inserted_message += test_user_profile["user"][
        "handle_str"] + ": " + new_message2 + "\n"
    time.sleep(2)
    message_from_channel = channel.channel_messages(
        channel_creater["token"], test_channel_id1["channel_id"], 0)
    assert inserted_message == message_from_channel["messages"][0]["message"]
    assert channel_creater["u_id"] == message_from_channel["messages"][0][
        "u_id"]
    other.clear()
Пример #6
0
def test_standup_send_handle():
    """ 
    Tests if standup_start and standup_send works. 
    """
    clear()
    user1 = auth.auth_register("*****@*****.**", "password", "Bilbo", "Baggins")
    channel_dict = channels.channels_create(user1['token'], "test_channel", True)
    user.user_profile_sethandle(user1['token'], 'handle')
    standup.standup_start(user1['token'], channel_dict['channel_id'], 3)
    standup.standup_send(user1['token'], channel_dict['channel_id'], "message1")

    time.sleep(5)
    standup.standup_active(user1['token'], channel_dict['channel_id'])
    
    message_dict = channel.channel_messages(user1['token'], channel_dict['channel_id'], 0)
    
    assert message_dict['messages'][0]['message'] == ("handle: message1")
    user.user_profile_sethandle(user1['token'], 'eren')
    standup.standup_start(user1['token'], channel_dict['channel_id'], 3)
    standup.standup_send(user1['token'], channel_dict['channel_id'], "message1")

    time.sleep(5)
    standup.standup_active(user1['token'], channel_dict['channel_id'])
    
    message_dict = channel.channel_messages(user1['token'], channel_dict['channel_id'], 0)
    assert message_dict['messages'][0]['message'] == ("eren: message1")
Пример #7
0
def test_standup_send_functionality(create_owner_with_channel_and_user):
    '''
    Checks that standup_send actually works correctly and sends through a
    message in the correct format
    '''

    owner = create_owner_with_channel_and_user['owner']
    channel_1 = create_owner_with_channel_and_user['channel_1']
    user = create_owner_with_channel_and_user['user']

    standup.standup_start(owner['token'], channel_1['channel_id'], 2)

    standup.standup_send(owner['token'], channel_1['channel_id'],
                         "Message 1 sent")
    standup.standup_send(user['token'], channel_1['channel_id'],
                         "Message 2 sent")

    expected_message = '''homersimpson: Message 1 sent\nbartsimpson: Message 2 sent'''

    time.sleep(2)

    message_list = channel.channel_messages(owner['token'],
                                            channel_1['channel_id'], 0)

    standup_message = message_list['messages'][0]

    assert standup_message['message_id'] == 1
    assert standup_message['u_id'] == owner['u_id']
    assert standup_message['message'] == expected_message
Пример #8
0
def test_standup_active_usernotinchannel():   
    clear()
    channels = getChannelData()
    #Registering a user
    register = auth_register('*****@*****.**', '123abc!@#', 'Hayden', 'Everest', None)
    #Storing token generated from registration process in a variable for easy access
    creator_token = register['token']
    #Using the registered user to create a channel
    new_channel = channels_create(creator_token, "Testing Channel", True)
    #Storing channel_id generated from channel creation in a variable for easy access
    channel_id = new_channel['channel_id']

    for channel in channels:
        if channel['channel_id'] == channel_id:
            assert channel['is_standup'] == False

    standup_start(creator_token, channel_id, 3)  

    for channel in channels:
        if channel['channel_id'] == channel_id:
            assert channel['is_standup'] == True         

    #Registering a user
    register1 = auth_register('*****@*****.**', '!!!123abc!@#', 'Howard', 'Fog',  None)
    #Storing token generated from registration process in a variable for easy access
    another_token = register1['token']

    with pytest.raises(AccessError):
        standup_active(another_token, channel_id)
Пример #9
0
def test_standup_send_complex():
    reset_data()
    member1 = auth_register('*****@*****.**', 'helloworld', 'a', 'A')
    member2 = auth_register('*****@*****.**', 'thisisfun', 'b', 'B')
    member3 = auth_register('*****@*****.**', 'iamrobbie', 'c', 'C')
    channel = channels_create(member1['token'], 'Hey Channel', True)
    channel_id = channel['channel_id']
    channel_join(member2['token'], channel_id)
    channel_join(member3['token'], channel_id)
    standup_start(member1['token'], channel_id, 1)
    assert standup_send(member1['token'], channel_id, '1\nSTOP') == {}
    assert standup_send(member2['token'], channel_id, '2\nSTOP') == {}
    assert standup_send(member3['token'], channel_id, '3\nSTOP') == {}
    sleep(1.1)
    tmp = channel_messages(member1['token'], channel_id, 0)
    message = tmp['messages'][0]
    timestamp = message['time_created']
    assert channel_messages(member1['token'], channel_id, 0) == {
        'messages': [
            {
                'message_id': 1,
                'u_id': 1,
                'message': 'aa: 1\nSTOP\nbb: 2\nSTOP\ncc: 3\nSTOP',
                'time_created': timestamp
            },
            ],
        'start': 0,
        'end': -1,
        }
Пример #10
0
def test_standup_start_complex():
    reset_data()
    member1 = auth_register('*****@*****.**', 'helloworld', 'ARoy', 'Wallace')
    member2 = auth_register('*****@*****.**', 'helloworld', 'BRoy', 'Wallace')
    test_channel = channels_create(member1['token'], 'New Channel', True)
    channel_id = test_channel['channel_id']
    channel_join(member2['token'], channel_id)

    standup_start(member2['token'], channel_id, 1)
    standup_send(member1['token'], channel_id, 'Standup message1')
    standup_send(member2['token'], channel_id, 'Standup message2')
    sleep(1.1)
    tmp = channel_messages(member1['token'], channel_id, 0)
    message = tmp['messages'][0]
    timestamp = message['time_created']
    assert channel_messages(member2['token'], channel_id, 0) == {
        'messages': [
            {
                'message_id': 1,
                'u_id': 2,
                'message': 'aroywallace: Standup message1\nbroywallace: Standup message2',
                'time_created': timestamp
            },
            ],
        'start': 0,
        'end': -1,
        }
Пример #11
0
def test_standup_active_basecase():
    clear()
    channels = getChannelData()
    #Registering a user
    register = auth_register('*****@*****.**', '123abc!@#', 'Hayden', 'Everest', None)
    #Storing token generated from registration process in a variable for easy access
    creator_token = register['token']
    #Using the registered user to create a channel
    new_channel = channels_create(creator_token, "Testing Channel", True)
    #Storing channel_id generated from channel creation in a variable for easy access
    channel_id = new_channel['channel_id']

    for channel in channels:
        if channel['channel_id'] == channel_id:
            assert channel['is_standup'] == False

    standup_start(creator_token, channel_id, 3)  

    for channel in channels:
        if channel['channel_id'] == channel_id:
            assert channel['is_standup'] == True         

    res = standup_active(creator_token, channel_id)      

    assert len(res) == 2  
Пример #12
0
def test_standup_whole():
    time.sleep(5)
    _, wenyao_dict, _, channel_team1, _ = initialise_data()
    # start standup
    standup_start(wenyao_dict['token'], channel_team1['channel_id'], 5)
    # check if standup is active
    is_active = standup_active(wenyao_dict['token'],
                               channel_team1['channel_id'])['is_active']
    assert is_active == True
    standup_send(wenyao_dict['token'], channel_team1['channel_id'], "Hi")
    time.sleep(1)
    standup_send(wenyao_dict['token'], channel_team1['channel_id'], "Hello")
    # sleep for 5s
    time.sleep(5)
    # check if standup is active
    is_active = standup_active(wenyao_dict['token'],
                               channel_team1['channel_id'])['is_active']
    assert is_active == False
    # get handle
    wenyao_profile = user_profile(wenyao_dict['token'], wenyao_dict['u_id'])
    handle = wenyao_profile['user']['handle_str']
    # check the return value for channel_message
    message_dict = channel_messages(wenyao_dict['token'],
                                    channel_team1['channel_id'], 0)
    msg = handle + ': ' + "Hi" + '\n' + handle + ': ' + "Hello"
    assert message_dict['messages'][0]['message'] == msg
Пример #13
0
def test_send_too_long():
    """
    Test if an error is raised if message is too long
    """
    channel_creater = auth.auth_register("*****@*****.**", "password",
                                         "Quick", "Shadow")
    test_channel_id1 = channels.channels_create(channel_creater["token"],
                                                "test1", True)
    standup.standup_start(channel_creater["token"],
                          test_channel_id1["channel_id"], 1)
    message_exp = (
        "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula "
        "eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient "
        "montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, "
        "pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, "
        "aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis "
        "vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras "
        "dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo "
        "ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus "
        "in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. "
        "Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper "
        "ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum "
        "rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum...12345"
    )
    with pytest.raises(InputError):
        standup.standup_send(channel_creater["token"],
                             test_channel_id1["channel_id"], message_exp)
    other.clear()
Пример #14
0
def test_standup_send_during_standup():
    '''
    Test that messages sent during the standup period are not actually sent
    untill after, and then, all as one message
    '''
    clear()
    user = auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    channel = channels_create(user['token'], "Channel", True)

    standup_start(user['token'], channel['channel_id'], 1)

    standup_send(user['token'], channel['channel_id'], "message1")
    check = search(user['token'], "message1")
    assert len(check['messages']) == 0
    standup_send(user['token'], channel['channel_id'], "message2")
    check = search(user['token'], "message2")
    assert len(check['messages']) == 0
    time.sleep(4)
    check = search(user['token'], "message")
    assert len(check['messages']) == 1

    name = user_profile(user['token'], user['u_id'])['user']['handle_str']

    assert check['messages'][0][
        'message'] == name + ": message1" + '\n' + name + ": message2"
Пример #15
0
def test_standup_send_invalid_token():
    '''
    Test basic error raising from invalid inputs
    '''
    clear()
    user = auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    user2 = auth_register("*****@*****.**", "password", "Firstname",
                          "Lastname")
    channel = channels_create(user['token'], "Channel", True)
    standup_start(user['token'], channel['channel_id'], 1)

    # User not in channel causes access error
    with pytest.raises(AccessError):
        standup_send(user2['token'], channel['channel_id'], "message")

    # invalid token raises AccessError
    with pytest.raises(AccessError):
        standup_send("notToken", channel['channel_id'], "message")

    # invalid channel_id raises InputError
    with pytest.raises(InputError):
        standup_send(user['token'], -1, "message")

    # message over 1000 characters long raises InputError
    message = "a" * 1001
    with pytest.raises(InputError):
        standup_send(user['token'], channel['channel_id'], message)
    time.sleep(2)
Пример #16
0
def test_standup_start1():
    """ 
    Tests if standup_start and standup_send works. 
    """
    clear()
    user1 = auth.auth_register("*****@*****.**", "password", "Bilbo", "Baggins")
    user2 = auth.auth_register("*****@*****.**", "password", "Frodo", "Baggins")
    user3 = auth.auth_register("*****@*****.**", "password", "Master", "Sauron")
    channel_dict = channels.channels_create(user1['token'], "test_channel", True)

    channel.channel_join(user2['token'], channel_dict['channel_id'])
    channel.channel_join(user3['token'], channel_dict['channel_id'])

    standup.standup_start(user1['token'], channel_dict['channel_id'], 3)
    standup.standup_send(user1['token'], channel_dict['channel_id'], "message1")
    standup.standup_send(user2['token'], channel_dict['channel_id'], "message2")
    standup.standup_send(user3['token'], channel_dict['channel_id'], "message3")

    time.sleep(5)
    standup.standup_active(user1['token'], channel_dict['channel_id'])

    message_dict = channel.channel_messages(user1['token'], channel_dict['channel_id'], 0)
    assert len(message_dict['messages']) == 1
    assert message_dict['messages'][0]['message'] == ("bilbobaggins: message1\n" +
                                                      "frodobaggins: message2\n" +
                                                      "mastersauron: message3")
Пример #17
0
def test_standup_start_invalid_token():
    """Tests passing an invalid token to standup_start"""
    clear()
    valid_user = auth_register("*****@*****.**", "validPassword",
                               "Validate", "Me")
    channels_create(valid_user["token"], "invalid_channel", False)
    with pytest.raises(AccessError):
        standup_start(90000, 1433125, 3)
Пример #18
0
def test_start_error_invalid_req(initial_data):
    '''
    error test when user calls standup_start when it is active in that channel
    user 1 calls standup_start in channel_1 and call start again
    '''
    standup_start(users[0]['token'], channels[0]['channel_id'], 3)
    with pytest.raises(InputError):
        standup_start(users[0]['token'], channels[0]['channel_id'], 3)
Пример #19
0
def test_start_error_invalid_channel(initial_data):
    '''
    error test when given channel_id is invalid
    channel_id does not exist
    '''
    # non-existing channel with id 0
    with pytest.raises(InputError):
        standup_start(users[0]['token'], 0, 1)
Пример #20
0
def test_send_error_invalid_msg(initial_data):
    '''
    error test when msg is too long (1000 characters)
    user1 calls start in channel1 and send a too long msg
    '''
    standup_start(users[0]['token'], channels[0]['channel_id'], 1)
    with pytest.raises(InputError):
        standup_send(users[0]['token'], channels[0]['channel_id'], 'm' * 1001)
Пример #21
0
def test_standup_send_is_member():
    time.sleep(5)
    boyu_dict, wenyao_dict, _, channel_team1, _ = initialise_data()
    channel_invite(wenyao_dict['token'], channel_team1['channel_id'],
                   boyu_dict['u_id'])
    standup_start(wenyao_dict['token'], channel_team1['channel_id'], 5)
    sent = standup_send(boyu_dict['token'], channel_team1['channel_id'], "Hello")
    assert sent == {}
Пример #22
0
def test_standup_start_invalid_channel():
    """Tests passing an invalid channel ID to standup_start"""
    clear()
    valid_user = auth_register("*****@*****.**", "validPassword",
                               "Validate", "Me")
    channels_create(valid_user["token"], "invalid_channel", False)
    with pytest.raises(InputError):
        standup_start(valid_user["token"], 9001, 3)
Пример #23
0
def test_standup_send_long_message():
    reset_data()
    member = auth_register('*****@*****.**', 'helloworld', 'firstname', 'lastname')
    channel_id = channels_create(member['token'], 'Channel', True)
    standup_start(member['token'], channel_id['channel_id'], 3)

    with pytest.raises(InputError):
        standup_send(member['token'], 1, 'a'*1001)
Пример #24
0
def test_active_output3():
    clear()
    user = auth.auth_register("*****@*****.**", "password", "First", "Last")
    channel = channels.channels_create(user['token'], "name", True)
    standup.standup_start(user['token'], channel["channel_id"], 3)
    assert standup.standup_active(user['token'], channel['channel_id']).get('is_active') == True
    time.sleep(4)
    assert standup.standup_active(user['token'], channel['channel_id']).get('is_active') == False
Пример #25
0
def test_standup_start_nvt():
    """ Tests if standup_start raises an AccessError if the token given is invalid. """

    user = auth.auth_register("*****@*****.**", "password", "Dwayne", "Johnson")
    channel_dict = channels.channels_create(user['token'], "test_channel", False)

    with pytest.raises(error.AccessError):
        standup.standup_start("InvalidToken", channel_dict['channel_id'], 100)
Пример #26
0
def test_standup_start_already_active():
    reset_data()
    member1 = auth_register('*****@*****.**', 'helloworld', 'firstname', 'lastname')
    test_channel = channels_create(member1['token'], 'New Channel', True)
    standup_start(member1['token'], test_channel['channel_id'], 10)

    with pytest.raises(InputError):
        standup_start(member1['token'], test_channel['channel_id'], 6)
Пример #27
0
def test_standup_start_already_active():
    """Tests running a standup on a channel that currently has a standup running"""
    clear()
    valid_user = auth_register("*****@*****.**", "validPassword",
                               "Validate", "Me")
    new_channel = channels_create(valid_user["token"], "new_channel", False)
    standup_start(valid_user["token"], new_channel["channel_id"], 3)
    with pytest.raises(InputError):
        standup_start(valid_user["token"], new_channel["channel_id"], 3)
Пример #28
0
def test_send_error_not_active(initial_data):
    '''
    error test when standup is not active in given channel
    user 1 calls start in channel 1
    user 3 calls send in chanenl 2
    '''
    standup_start(users[0]['token'], channels[0]['channel_id'], 1)
    with pytest.raises(InputError):
        standup_send(users[2]['token'], channels[1]['channel_id'], 'msg')
Пример #29
0
def test_send_error_not_member(initial_data):
    '''
    error test when standup_send to wrong channel
    user 1 calls start in channel1
    user 3 calls standup_send to channel1
    '''
    standup_start(users[0]['token'], channels[0]['channel_id'], 1)
    with pytest.raises(AccessError):
        standup_send(users[2]['token'], channels[0]['channel_id'], 'msg')
Пример #30
0
def test_standup_send_user_not_in_channel():
    reset_data()
    member1 = auth_register('*****@*****.**', 'helloworld', 'a', 'A')
    member2 = auth_register('*****@*****.**', 'helloworld', 'b', 'B')
    channel_id = channels_create(member1['token'], 'Channel', True)
    standup_start(member1['token'], channel_id['channel_id'], 3)

    with pytest.raises(AccessError):
        standup_send(member2['token'], 1, 'a')