示例#1
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!"
示例#2
0
def test_standup_start_invalid_channel():
    clear_v1()

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

    with pytest.raises(InputError):
        standup_start_v1(auth_user_1_token, 99999, 10)
示例#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") == {}
示例#4
0
def test_standup_start_v1_invalid_channel_id(reg_user, basic_channel_name):
    clear_v2()
    token_1 = reg_user(0)['token']
    channel_name = basic_channel_name
    channel_id = channels_create_v2(token_1, channel_name, True)['channel_id']
    standup_length = 1
    
    with pytest.raises(InputError):
        standup_start_v1(token_1, channel_id+1, standup_length) #channel id does not exist 
示例#5
0
def test_standup_start_v1_token(reg_user, basic_channel_name):
    clear_v2()
    token_1 = reg_user(0)['token']
    channel_name = basic_channel_name
    channel_id = channels_create_v2(token_1, channel_name, True)['channel_id']
    fake_token ='adadsafqwevdw3qwqaswd'
    standup_length = 1
    
    with pytest.raises(AccessError):
        standup_start_v1(fake_token, channel_id, standup_length)
示例#6
0
def test_standup_start_v1_active_standup_currently_running_in_channel(reg_user, basic_channel_name):
    clear_v2()
    token_1 = reg_user(0)['token']
    channel_name = basic_channel_name
    channel_id = channels_create_v2(token_1, channel_name, True)['channel_id']
    standup_length = 10 
    standup_start_v1(token_1, channel_id, standup_length)
    
    with pytest.raises(InputError):
        standup_start_v1(token_1, channel_id, standup_length)# standup already running in the channel
示例#7
0
def test_standup_start_v1_auth_user_not_in_channel(reg_user, basic_channel_name):
    clear_v2()
    token_1 = reg_user(0)['token']
    user_not_in_channel_token = reg_user(1)['token']
    channel_name = basic_channel_name
    channel_id = channels_create_v2(token_1, channel_name, True)['channel_id']
    standup_length = 1
    
    with pytest.raises(AccessError):
        standup_start_v1(user_not_in_channel_token, channel_id, standup_length)#user not inside the channel cant stand up
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')
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_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_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)
示例#12
0
def test_standup_start_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"]

    standup_start_v1(auth_user_1_token, channel_id_1, 10)

    with pytest.raises(InputError):
        standup_start_v1(auth_user_1_token, channel_id_1, 10)
示例#13
0
def test_standup_start_v1_another_user_cant_start_standup_when_standup_running(reg_user, basic_channel_name):
    clear_v2()
    token_1 = reg_user(0)['token']
    joined_user_token = reg_user(1)['token']
    channel_name = basic_channel_name
    channel_id = channels_create_v2(token_1, channel_name, True)['channel_id']
    standup_length = 10
    channel_join_v2(joined_user_token, channel_id)
    standup_start_v1(token_1, channel_id, standup_length)
    
    with pytest.raises(InputError):
        standup_start_v1(joined_user_token, channel_id, standup_length) # standup already running in the channel
示例#14
0
def test_invalid_channel_id(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(InputError):
        standup_active_v1(token, channel_id + 1)
示例#15
0
def test_standup_start_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"]

    with pytest.raises(AccessError):
        standup_start_v1(auth_user_2_token, channel_id_1, 10)
示例#16
0
def test_standup_start_currently_running_standup(reg_user, basic_channel_name):
    clear_v2()
    token_1 = reg_user(0)['token']
    channel_name = basic_channel_name
    channel_id = channels_create_v2(token_1, channel_name, True)['channel_id']
    standup_length = 10
    
    is_active = standup_active_v1(token_1, channel_id)['is_active']
    assert is_active == False
    
    standup_start_v1(token_1, channel_id, standup_length)
    
    is_active = standup_active_v1(token_1, channel_id)['is_active']
    assert is_active == True #now that standup is running this should change to True 
示例#17
0
def test_standup_start_v1_standup_not_started_in_multiple_channels_with_same_user(reg_user, basic_channel_name):
    clear_v2()
    token_1 = reg_user(0)['token']
    channel_name = basic_channel_name
    channel_id_1 = channels_create_v2(token_1, channel_name, True)['channel_id']
    channel_id_2 = channels_create_v2(token_1, 'nice channel', True)['channel_id'] #second channel
    standup_length = 1

    standup_start_v1(token_1, channel_id_1, standup_length)
    
    is_active_channel_1 = standup_active_v1(token_1, channel_id_1)['is_active']
    assert is_active_channel_1 == True 
    
    is_active_channel_2 = standup_active_v1(token_1, channel_id_2)['is_active']
    assert is_active_channel_2 == False
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') == {}
示例#19
0
def test_standup_start_user_that_joined_channel_can_standup(reg_user, basic_channel_name):
    clear_v2()
    token_1 = reg_user(0)['token']
    joined_user_token = reg_user(1)['token']
    channel_name = basic_channel_name
    channel_id = channels_create_v2(token_1, channel_name, True)['channel_id']
    standup_length = 10
    
    channel_join_v2(joined_user_token, channel_id)
    is_active = standup_active_v1(joined_user_token, channel_id)['is_active']
    assert is_active == False
    
    standup_start_v1(joined_user_token, channel_id, standup_length)
    
    is_active = standup_active_v1(joined_user_token, channel_id)['is_active']
    assert is_active == True #now that standup is running this should change to True 
示例#20
0
def test_standup_start_v1_non_clash_between_channels_with_standup(reg_user, basic_channel_name):
    clear_v2()
    token_1 = reg_user(0)['token']
    token_2 = reg_user(1)['token']
    channel_name = basic_channel_name
    channel_id_1 = channels_create_v2(token_1, channel_name, True)['channel_id']
    channel_id_2 = channels_create_v2(token_2, 'nice channel', True)['channel_id'] #second channel
    standup_length = 5
    
    standup_start_v1(token_1, channel_id_1, standup_length)
    standup_start_v1(token_2, channel_id_2, standup_length)
    
    is_active_channel_1 = standup_active_v1(token_1, channel_id_1)['is_active']
    assert is_active_channel_1 == True 
    
    is_active_channel_2 = standup_active_v1(token_2, channel_id_2)['is_active']
    assert is_active_channel_2 == True 
示例#21
0
def standup_start():
    info = request.get_json()
    token = info["token"]
    channel_id = info["channel_id"]
    length = info["length"]

    standup_start = standup_start_v1(token, channel_id, length)

    return dumps(standup_start)
示例#22
0
def test_standup_start_v1(user_setup, channel_setup):

    dateTimeObj = datetime.now()
    timeStampStr = (dateTimeObj +
                    timedelta(seconds=1)).strftime("%d-%b-%Y (%H:%M)")

    assert standup_start_v1(make_token(1), 1, 1) == {
        "time_finish": timeStampStr
    }
示例#23
0
def standup_start():
    parameters = request.get_json()
    token = parameters['token']
    channel_id = parameters['channel_id']
    length = parameters['length']
    output = standup_start_v1(token, channel_id, length)
    standup_thread = threading.Thread(target=standup_handler, args=[token, channel_id, length])
    standup_thread.start()
    return dumps(output)
示例#24
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
示例#25
0
def test_active_standup(reg_user, crt_channel):
    clear_v2()

    token = reg_user(0)['token']

    channel_id = crt_channel(token)['channel_id']

    standup_length = 5
    finish_time = standup_start_v1(token, channel_id,
                                   standup_length)['time_finish']

    standup_info = standup_active_v1(token, channel_id)

    assert standup_info['is_active']
    assert standup_info['time_finish'] == finish_time
def test_standup_active_v1():
    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_status = standup_active_v1(auth_user_1_token, channel_id_1)

    assert standup_status["is_active"] == False
    assert standup_status["time_finish"] == None

    time_finish = standup_start_v1(auth_user_1_token, channel_id_1,
                                   10)["time_finish"]
    standup_status = standup_active_v1(auth_user_1_token, channel_id_1)

    assert standup_status["is_active"] == True
    assert standup_status["time_finish"] == time_finish
示例#27
0
def test_standup_start_v1_errors(user_setup, channel_setup, standup_setup):

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

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

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

    # Test 4:
    # active standup is running in channel
    with pytest.raises(InputError):
        standup_start_v1(make_token(2), 2, 5)
示例#28
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
    }
示例#29
0
def standup_setup():
    standup_start_v1(make_token(2), 2, 1)