Exemple #1
0
def test_standup_active_not_active(user_1, user_2, user_3, public_channel_1):
    """Testing when standup is not active
    """
    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 = 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)
    time.sleep(4)

    information = standup.standup_active(user_1['token'], public_channel_1['channel_id'])
    assert not information['is_active']
    assert information['time_finish'] == None

    information = standup.standup_active(user_2['token'], public_channel_1['channel_id'])
    assert not information['is_active']
    assert information['time_finish'] == None

    information = standup.standup_active(user_3['token'], public_channel_1['channel_id'])
    assert not information['is_active']
    assert information['time_finish'] == None
    clear()
Exemple #2
0
def test_standup_active_invalid_channel(user_1, user_2):
    """Testing invalid channel_ids
    """
    with pytest.raises(InputError):
        standup.standup_active(user_1['token'], -122)
    with pytest.raises(InputError):
        standup.standup_active(user_1['token'], -642)
    with pytest.raises(InputError):
        standup.standup_active(user_2['token'], '@#@!')
    with pytest.raises(InputError):
        standup.standup_active(user_2['token'], 212.11)
    clear()
Exemple #3
0
def test_standup_active_unauthorized_user(user_1, user_2, user_3, public_channel_1):
    """(Assumption testing) Testing when a user who is not part of the channel
       tries to see if a standup is active in 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_active(user_2['token'], public_channel_1['channel_id'])
    with pytest.raises(AccessError):
        standup.standup_active(user_3['token'], public_channel_1['channel_id'])
    clear()
Exemple #4
0
def test_standup_active_expired_token(user_1, user_2, user_3, user_4, public_channel_1):
    """Testing invalid 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_active(user_1['token'], public_channel_1['channel_id'])
    with pytest.raises(AccessError):
        standup.standup_active(user_2['token'], public_channel_1['channel_id'])
    with pytest.raises(AccessError):
        standup.standup_active(user_3['token'], public_channel_1['channel_id'])
    with pytest.raises(AccessError):
        standup.standup_active(user_4['token'], public_channel_1['channel_id'])
    clear()
Exemple #5
0
def test_standup_active_invalid_token(public_channel_1):
    """Testing invalid token for users
    """
    with pytest.raises(AccessError):
        standup.standup_active(-1, public_channel_1['channel_id'])
    with pytest.raises(AccessError):
        standup.standup_active('@#&!', public_channel_1['channel_id'])
    with pytest.raises(AccessError):
        standup.standup_active(43.333, public_channel_1['channel_id'])
    clear()
Exemple #6
0
def route_standup_active():
    """For a given channel, return whether a standup is active in it, and what
    time the standup finishes. If no standup is active, then time_finish
    returns None

    Args:
        token (string)
        channel_id (int)

    Returns:
        (dict): { is_active, time_finish }
    """
    token = request.args.get('token')
    channel_id = int(request.args.get('channel_id'))
    try:
        return dumps(standup.standup_active(token, channel_id))
    except (InputError, AccessError) as e:
        return e