Пример #1
0
def test_standup_send_v1_errors(user_setup, channel_setup, standup_setup):

    # Test 1:
    # invalid token
    with pytest.raises(AccessError):
        standup_send_v1(make_token(414345), 0, "invalid token error")
    # "Invalid token"

    # Test 2:
    # auhtorised user is not part of channel
    with pytest.raises(AccessError):
        standup_send_v1(make_token(2), 0, "Not part of channel error")
    # "Authorised user is not part of the channel"

    # Test 3:
    # invalid channel id
    with pytest.raises(InputError):
        standup_send_v1(make_token(2), 414345, "invalid channel error")
    # "Invalid channel"

    # Test 4:
    # message too long
    with pytest.raises(AccessError):
        standup_send_v1(make_token(2), 0, "1" * 999 + "Message too long error")
    # "Authorised user is not part of the channel"

    # Test 5:
    # no active standup is running in channel
    with pytest.raises(InputError):
        standup_send_v1(make_token(1), 1, "no active standup error")
Пример #2
0
def test_standup_start_v1():
    clear_v1()

    auth_user_1_data = auth_register_v2("*****@*****.**", "123456", "Andy", "Dandy")
    auth_user_1_token = auth_user_1_data["token"]
    auth_user_1_id = auth_user_1_data["auth_user_id"]
    auth_user_1_handle = user_profile_v2(auth_user_1_token, auth_user_1_id)["user"]["handle_str"]

    channel_id_1 = channels_create_v2(auth_user_1_token, "Andys channel", True)["channel_id"]

    message_id_1 = message_send_v2(auth_user_1_token, channel_id_1, "Hey Guys!")["message_id"]

    standup_start_v1(auth_user_1_token, channel_id_1, 3)
    standup_send_v1(auth_user_1_token, channel_id_1, "Hello")

    message_list = channel_messages_v2(auth_user_1_token, channel_id_1, 0)["messages"]
    assert len(message_list) == 1
    assert message_list[0]["message_id"] == message_id_1
    assert message_list[0]["message"] == "Hey Guys!"

    time.sleep(5)
 
    message_list_1 = channel_messages_v2(auth_user_1_token, channel_id_1, 0)["messages"]
    assert len(message_list_1) == 2
    assert message_list_1[0]["message_id"] == message_id_1 + 1
    assert message_list_1[0]["message"] == auth_user_1_handle + ": Hello"
    assert message_list_1[1]["message_id"] == message_id_1
    assert message_list_1[1]["message"] == "Hey Guys!"
Пример #3
0
def test_standup_send_v1(user_setup, channel_setup):

    # send some messages to standup
    standup_start_v1(make_token(0), 3, 1)
    assert standup_send_v1(make_token(0), 3, "0") == {}
    assert standup_send_v1(make_token(1), 3, "1") == {}
    assert standup_send_v1(make_token(2), 3, "2") == {}
    assert standup_send_v1(make_token(3), 3, "3") == {}
def test_not_active_standup(reg_user, crt_channel):
    clear_v2()

    token = reg_user(0)['token']

    channel_id = crt_channel(token)['channel_id']

    with pytest.raises(InputError):
        standup_send_v1(token, channel_id, 'helloworld')
def test_common_case(reg_user, crt_channel):
    clear_v2()

    token = reg_user(0)['token']

    channel_id = crt_channel(token)['channel_id']
    standup_length = 1
    standup_start_v1(token, channel_id, standup_length)

    assert standup_send_v1(token, channel_id, 'HELLOWORLD') == {}
    assert standup_send_v1(token, channel_id, 'PYTHON') == {}
def test_not_correct_channel_number(reg_user, crt_channel):
    clear_v2()

    token0 = reg_user(0)['token']
    token1 = reg_user(1)['token']
    channel_id1 = crt_channel(token1)['channel_id']
    standup_length = 1
    standup_start_v1(token1, channel_id1, standup_length)

    with pytest.raises(AccessError):
        standup_send_v1(token0, channel_id1, 'helloworld')
def test_invalid_token(reg_user, crt_channel):
    clear_v2()

    token = reg_user(0)['token']

    channel_id = crt_channel(token)['channel_id']
    standup_length = 1
    standup_start_v1(token, channel_id, standup_length)

    with pytest.raises(AccessError):
        standup_send_v1("Invalid token", channel_id, 'helloworld')
Пример #8
0
def test_standup_send_not_have_actived_standup():
    clear_v1()

    auth_user_1_data = auth_register_v2("*****@*****.**", "123456", "Andy",
                                        "Dandy")
    auth_user_1_token = auth_user_1_data["token"]

    channel_id_1 = channels_create_v2(auth_user_1_token, "Andys channel",
                                      True)["channel_id"]

    with pytest.raises(InputError):
        standup_send_v1(auth_user_1_token, channel_id_1, "Hello")
def test_long_messge(reg_user, crt_channel):
    clear_v2()

    token = reg_user(0)['token']

    channel_id = crt_channel(token)['channel_id']
    message = 'a' * 1001
    standup_length = 1
    standup_start_v1(token, channel_id, standup_length)

    with pytest.raises(InputError):
        standup_send_v1(token, channel_id, message)
Пример #10
0
def test_standup_send_message_over_1000():
    clear_v1()

    auth_user_1_data = auth_register_v2("*****@*****.**", "123456", "Andy",
                                        "Dandy")
    auth_user_1_token = auth_user_1_data["token"]

    channel_id_1 = channels_create_v2(auth_user_1_token, "Andys channel",
                                      True)["channel_id"]

    standup_start_v1(auth_user_1_token, channel_id_1, 10)

    with pytest.raises(InputError):
        standup_send_v1(auth_user_1_token, channel_id_1, "l" * 1001)
def test_other_menber_case(reg_user, crt_channel):
    clear_v2()

    token = reg_user(0)['token']
    user1 = reg_user(1)
    token1 = user1['token']
    u_id = user1['auth_user_id']

    channel_id = crt_channel(token)['channel_id']
    channel_invite_v2(token, channel_id, u_id)
    standup_length = 1
    standup_start_v1(token, channel_id, standup_length)

    assert standup_send_v1(token1, channel_id, 'HELLOWORLD') == {}
    assert standup_send_v1(token1, channel_id, 'PYTHON') == {}
Пример #12
0
def standup_send():
    parameters = request.get_json()
    token = parameters['token']
    channel_id = parameters['channel_id']
    message = parameters['message']
    output = standup_send_v1(token, channel_id, message)
    return dumps(output)
Пример #13
0
def test_standup_send_not_in_channel():
    clear_v1()

    auth_user_1_data = auth_register_v2("*****@*****.**", "123456", "Andy",
                                        "Dandy")
    auth_user_1_token = auth_user_1_data["token"]

    auth_user_2_data = auth_register_v2("*****@*****.**", "123456", "Bob",
                                        "Hobs")
    auth_user_2_token = auth_user_2_data["token"]

    channel_id_1 = channels_create_v2(auth_user_1_token, "Andys channel",
                                      True)["channel_id"]

    standup_start_v1(auth_user_1_token, channel_id_1, 10)

    with pytest.raises(AccessError):
        standup_send_v1(auth_user_2_token, channel_id_1, "Hello")
Пример #14
0
def standup_send():
    info = request.get_json()
    token = info["token"]
    channel_id = info["channel_id"]
    message = info["message"]

    standup_send = standup_send_v1(token, channel_id, message)

    return dumps(standup_send)
Пример #15
0
def test_standup_send_v1():
    clear_v1()

    auth_user_1_data = auth_register_v2("*****@*****.**", "123456", "Andy",
                                        "Dandy")
    auth_user_1_token = auth_user_1_data["token"]
    auth_user_1_id = auth_user_1_data["auth_user_id"]
    auth_user_1_handle = user_profile_v2(auth_user_1_token,
                                         auth_user_1_id)["user"]["handle_str"]

    auth_user_2_data = auth_register_v2("*****@*****.**", "123456", "Bob",
                                        "Hobs")
    auth_user_2_token = auth_user_2_data["token"]
    auth_user_2_id = auth_user_2_data["auth_user_id"]
    auth_user_2_handle = user_profile_v2(auth_user_2_token,
                                         auth_user_2_id)["user"]["handle_str"]

    auth_user_3_data = auth_register_v2("*****@*****.**", "123456", "Chris",
                                        "Wiz")
    auth_user_3_token = auth_user_3_data["token"]
    auth_user_3_id = auth_user_3_data["auth_user_id"]
    auth_user_3_handle = user_profile_v2(auth_user_3_token,
                                         auth_user_3_id)["user"]["handle_str"]

    channel_id_1 = channels_create_v2(auth_user_1_token, "Andys channel",
                                      True)["channel_id"]
    channel_join_v2(auth_user_2_token, channel_id_1)
    channel_join_v2(auth_user_3_token, channel_id_1)

    finish_time = standup_start_v1(auth_user_1_token, channel_id_1,
                                   3)["time_finish"]

    standup_send_v1(auth_user_1_token, channel_id_1, "Hello")
    standup_send_v1(auth_user_2_token, channel_id_1, "Hi")
    standup_send_v1(auth_user_3_token, channel_id_1, "Hey")

    message_list = channel_messages_v2(auth_user_1_token, channel_id_1,
                                       0)["messages"]
    assert len(message_list) == 0

    time.sleep(finish_time - time.time() + 1)

    message_list = channel_messages_v2(auth_user_1_token, channel_id_1,
                                       0)["messages"]
    assert len(message_list) == 1
    assert message_list[0]["u_id"] == auth_user_1_id

    message_sent_after_standup = f"""{auth_user_1_handle}: Hello
{auth_user_2_handle}: Hi
{auth_user_3_handle}: Hey"""
    assert message_list[0]["message"] == message_sent_after_standup
Пример #16
0
def message_send_v2(token, channel_id, message):
    '''
    Summary:
        Send a message from authorised_user to the channel specified by channel_id. 
        Note: Each message should have it's own unique ID. 
        I.E. No messages should share an ID with another message, 
        even if that other message is in a different channel.
    Args:
        token (string): A user session token 
        channel_id (int): A channel_id number
        message (string): a message string 
    Returns: 
        empty dictionary which contains the message_id
    Raises:
        InputError when:
            Message is more than 1000 characters
        AccessError when:
            the authorised user has not joined the channel they are trying to post to
    '''
    global users, channels, next_message_id, messages
    assert check_token(token)
    assert valid_channel(channel_id)

    auth_user = user_from_token(token)
    current_channel = find_channel(
        channel_id)  #current channel with the given channel id

    if current_channel['standup']['is_active']:
        standup_send_v1(token, channel_id, message)
        return

    if len(message) > 1000:
        raise InputError(f"Message more than 1000 characters")
    if auth_user['u_id'] not in current_channel['all_members']:
        raise AccessError(
            f"the authorised user has not joined the channel they are trying to post to"
        )

    current_time = current_unix_timestamp()  #gives us the current timestamp
    current_message = {}
    current_message['message_id'] = next_message_id['id']  #message_id
    current_message['channel_id'] = channel_id
    current_message[
        'dm_id'] = -1  #this is a channel message not dm so for all dm's give -1
    current_message['author_id'] = auth_user['u_id']
    current_message['message'] = message
    current_message['reacts'] = []
    current_message['time_created'] = current_time
    current_message['is_pinned'] = False
    current_channel['messages'].append(current_message['message_id'])
    next_message_id[
        'id'] += 1  #update the global message id so we get unique ids

    message_words = message.split(' ')

    # Standup start checker
    # Start a standup if message is exactly "/standup X" where X is a number of seconds
    if message.startswith('/standup') and len(
            message_words) == 2 and message_words[1].isdigit():
        duration = int(message_words[1])
        standup_start_v1(token, channel_id, duration)

    #notications checker and handler
    contains_tag = False
    tag_strings = []
    if '@' in message:
        for word in message_words:
            if word.startswith('@'):
                tag_strings.append(word[1:])
                contains_tag = True
    if contains_tag:
        for user_id in current_channel['all_members']:
            user = user_from_id(user_id)
            if user['handle_str'] in tag_strings:
                send_channel_tag_notification(auth_user['handle_str'], user_id,
                                              channel_id, message)

    messages.append(current_message)

    update_user_message_stats(auth_user['u_id'])

    update_message_stats()

    return {
        'message_id': current_message['message_id']  #message_id
    }