Ejemplo n.º 1
0
def test_standup_send_working_example(user_1, user_2, user_3, public_channel_1):
    """Testing when standup send is working, via message collation
    """
    assert channel.channel_invite(user_1['token'], public_channel_1['channel_id'], user_2['u_id']) == {}
    assert channel.channel_invite(user_2['token'], public_channel_1['channel_id'], user_3['u_id']) == {}

    standup_duration = 5
    curr_time = int(datetime.now(tz=timezone.utc).timestamp())
    information = standup.standup_start(user_1['token'], public_channel_1['channel_id'], 2)
    assert (curr_time + standup_duration - STANDUP_DELAY) <= information['time_finish'] and\
    information['time_finish'] <= (curr_time + standup_duration + STANDUP_DELAY)

    on_list = False
    user_one_handle = user.user_profile(user_1['token'], user_1['u_id'])['user']['handle_str']
    assert standup.standup_send(user_1['token'], public_channel_1['channel_id'], 'Pizza!') == {}
    message_data = channel.channel_messages(user_1['token'], public_channel_1['channel_id'], 0)
    for messages in message_data['messages']:
        if messages['message'] == f'{user_one_handle}: Pizza!':
            on_list = True
    assert not on_list
    
    assert standup.standup_send(user_2['token'], public_channel_1['channel_id'], 'Water!') == {}
    assert standup.standup_send(user_3['token'], public_channel_1['channel_id'], 'Melon!') == {}
    time.sleep(7)

    on_list = False
    user_two_handle = user.user_profile(user_2['token'], user_2['u_id'])['user']['handle_str']
    user_three_handle = user.user_profile(user_3['token'], user_3['u_id'])['user']['handle_str']
    message_data = channel.channel_messages(user_1['token'], public_channel_1['channel_id'], 0)
    for messages in message_data['messages']:
        if messages['message'] == f'{user_one_handle}: Pizza!\n{user_two_handle}: Water!\n{user_three_handle}: Melon!':
            on_list = True
    assert on_list
    clear()
Ejemplo n.º 2
0
def test_standup_send_empty_string(user_1, public_channel_1):
    """Testing when the message to send via standup send is empty string
    """
    standup_duration = 2
    curr_time = int(datetime.now(tz=timezone.utc).timestamp())
    information = standup.standup_start(user_1['token'], public_channel_1['channel_id'], standup_duration)
    assert (curr_time + standup_duration - STANDUP_DELAY) <= information['time_finish'] and\
    information['time_finish'] <= (curr_time + standup_duration + STANDUP_DELAY)

    with pytest.raises(InputError):
        standup.standup_send(user_1['token'], public_channel_1['channel_id'], '')
    with pytest.raises(InputError):
        standup.standup_send(user_1['token'], public_channel_1['channel_id'], "")
    clear()
Ejemplo n.º 3
0
def test_standup_start_working_example(user_1, user_2, user_3, public_channel_1):
    """Testing when standup is working, via message collation
    """
    assert channel.channel_invite(user_1['token'], public_channel_1['channel_id'], user_2['u_id']) == {}
    assert channel.channel_invite(user_2['token'], public_channel_1['channel_id'], user_3['u_id']) == {}

    standup_duration = 5
    curr_time = int(datetime.now(tz=timezone.utc).timestamp())
    information = standup.standup_start(user_1['token'], public_channel_1['channel_id'], standup_duration)
    assert (curr_time + standup_duration - STANDUP_DELAY) <= information['time_finish'] and\
    information['time_finish'] <= (curr_time + standup_duration + STANDUP_DELAY)
    
    data = pickle.load(open("data.p", "rb"))
    assert data.specify_standup_status(public_channel_1['channel_id'])['is_active'] == True

    on_list = False
    user_one_handle = user.user_profile(user_1['token'], user_1['u_id'])['user']['handle_str']
    assert standup.standup_send(user_1['token'], public_channel_1['channel_id'], 'Hey guys!') == {}
    message_data = channel.channel_messages(user_1['token'], public_channel_1['channel_id'], 0)
    for messages in message_data['messages']:
        if messages['message'] == f'{user_one_handle}: Hey guys!':
            on_list = True
    assert not on_list

    on_list = False
    user_two_handle = user.user_profile(user_2['token'], user_2['u_id'])['user']['handle_str']
    assert standup.standup_send(user_2['token'], public_channel_1['channel_id'], 'Its working!') == {}
    message_data = channel.channel_messages(user_1['token'], public_channel_1['channel_id'], 0)
    for messages in message_data['messages']:
        if messages['message'] == f'{user_one_handle}: Hey guys!\n{user_two_handle}: Its working!':
            on_list = True
    assert not on_list

    assert standup.standup_send(user_3['token'], public_channel_1['channel_id'], 'Wohoo!') == {}
    
    data = pickle.load(open("data.p", "rb"))
    assert data.specify_standup_status(public_channel_1['channel_id'])['is_active'] == True
    time.sleep(8)
    
    data = pickle.load(open("data.p", "rb"))
    assert data.specify_standup_status(public_channel_1['channel_id'])['is_active'] == False

    on_list = False
    user_three_handle = user.user_profile(user_3['token'], user_3['u_id'])['user']['handle_str']
    message_data = channel.channel_messages(user_1['token'], public_channel_1['channel_id'], 0)
    for messages in message_data['messages']:
        if messages['message'] == f'{user_one_handle}: Hey guys!\n{user_two_handle}: Its working!\n{user_three_handle}: Wohoo!':
            on_list = True
    assert on_list
    clear()
Ejemplo n.º 4
0
def test_standup_send_invalid_channel(user_1, user_2):
    """Testing invalid channel_ids
    """
    with pytest.raises(InputError):
        standup.standup_send(user_1['token'], -122, 'Hey')
    with pytest.raises(InputError):
        standup.standup_send(user_1['token'], -642, 'Hey')
    with pytest.raises(InputError):
        standup.standup_send(user_2['token'], '@#@!', 'Hey')
    with pytest.raises(InputError):
        standup.standup_send(user_2['token'], 212.11, 'Hey')
    clear()
Ejemplo n.º 5
0
def test_standup_send_unauthorized_user(user_1, user_2, user_3, public_channel_1):
    """Testing when a user who is not part of the channel tries to send a standup to
       that channel
    """
    standup_duration = 2
    curr_time = int(datetime.now(tz=timezone.utc).timestamp())
    information = standup.standup_start(user_1['token'], public_channel_1['channel_id'], standup_duration)
    assert (curr_time + standup_duration - STANDUP_DELAY) <= information['time_finish'] and\
    information['time_finish'] <= (curr_time + standup_duration + STANDUP_DELAY)

    information = standup.standup_active(user_1['token'], public_channel_1['channel_id'])
    assert information['is_active']
    assert (curr_time + standup_duration - STANDUP_DELAY) <= information['time_finish'] and\
    information['time_finish'] <= (curr_time + standup_duration + STANDUP_DELAY)

    with pytest.raises(AccessError):
        standup.standup_send(user_2['token'], public_channel_1['channel_id'], 'Hey')
    with pytest.raises(AccessError):
        standup.standup_send(user_3['token'], public_channel_1['channel_id'], 'Hey')
    clear()
Ejemplo n.º 6
0
def test_standup_send_expired_token(user_1, user_2, user_3, user_4, public_channel_1):
    """Testing expired token for users which have logged out
    """
    auth.auth_logout(user_1['token'])
    auth.auth_logout(user_2['token'])
    auth.auth_logout(user_3['token'])
    auth.auth_logout(user_4['token'])

    with pytest.raises(AccessError):
        standup.standup_send(user_1['token'], public_channel_1['channel_id'], 'Hey')
    with pytest.raises(AccessError):
        standup.standup_send(user_2['token'], public_channel_1['channel_id'], 'Hey')
    with pytest.raises(AccessError):
        standup.standup_send(user_3['token'], public_channel_1['channel_id'], 'Hey')
    with pytest.raises(AccessError):
        standup.standup_send(user_4['token'], public_channel_1['channel_id'], 'Hey')
    clear()
Ejemplo n.º 7
0
def test_standup_send_invalid_token(public_channel_1):
    """Testing invalid token for users
    """
    with pytest.raises(AccessError):
        standup.standup_send(-1, public_channel_1['channel_id'], 'Hey')
    with pytest.raises(AccessError):
        standup.standup_send('@#&!', public_channel_1['channel_id'], 'Hey')
    with pytest.raises(AccessError):
        standup.standup_send(43.333, public_channel_1['channel_id'], 'Hey')
    clear()
Ejemplo n.º 8
0
def test_standup_send_no_standup(user_1, user_2, user_3, public_channel_1):
    """Testing when no standup is currently running in channel specified
    """
    assert channel.channel_invite(user_1['token'], public_channel_1['channel_id'], user_2['u_id']) == {}
    assert channel.channel_invite(user_2['token'], public_channel_1['channel_id'], user_3['u_id']) == {}

    with pytest.raises(InputError):
        standup.standup_send(user_1['token'], public_channel_1['channel_id'], 'Hey')
    with pytest.raises(InputError):
        standup.standup_send(user_2['token'], public_channel_1['channel_id'], 'Hey')
    with pytest.raises(InputError):
        standup.standup_send(user_3['token'], public_channel_1['channel_id'], 'Hey')
    clear()
Ejemplo n.º 9
0
def route_standup_send():
    """Sending a message to get buffered in the standup queue, assuming a
    standup is currently active

    Args:
        token (string)
        channel_id (int)
        message (string)

    Returns:
        (dict): {}
    """
    payload = request.get_json()
    token = payload['token']
    channel_id = int(payload['channel_id'])
    message = payload['message']
    try:
        return dumps(standup.standup_send(token, channel_id, message))
    except (InputError, AccessError) as e:
        return e
Ejemplo n.º 10
0
def test_standup_send_more_than_1000_char(user_1, public_channel_1):
    """Testing when the message to send via standup send is over 1000 characters
    """
    message_str_1 = ("Hello" * 250)
    message_str_2 = ("HI " * 500)
    message_str_3 = ("My name is blah" * 100)

    standup_duration = 2
    curr_time = int(datetime.now(tz=timezone.utc).timestamp())
    information = standup.standup_start(user_1['token'], public_channel_1['channel_id'], standup_duration)
    assert (curr_time + standup_duration - STANDUP_DELAY) <= information['time_finish'] and\
    information['time_finish'] <= (curr_time + standup_duration + STANDUP_DELAY)

    with pytest.raises(InputError):
        standup.standup_send(user_1['token'], public_channel_1['channel_id'], message_str_1)
    with pytest.raises(InputError):
        standup.standup_send(user_1['token'], public_channel_1['channel_id'], message_str_2)
    with pytest.raises(InputError):
        standup.standup_send(user_1['token'], public_channel_1['channel_id'], message_str_3)
    clear()