Esempio 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()
Esempio n. 2
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()
Esempio n. 3
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()
Esempio n. 4
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()
Esempio n. 5
0
def test_change_channel_data(user_1, user_2):
    """ Testing that name is updated in channels section in data structure.
    """
    # creating a new channel
    new_channel = channels.channels_create(user_1['token'], 'Group 1', True)
    channel.channel_invite(user_1['token'], new_channel['channel_id'],
                           user_2['u_id'])
    channel.channel_join(user_2['token'], new_channel['channel_id'])
    channel.channel_addowner(user_1['token'], new_channel['channel_id'],
                             user_2['u_id'])
    details = channel.channel_details(user_1['token'],
                                      new_channel['channel_id'])
    for member in details['all_members']:
        if member['u_id'] == user_1['u_id']:
            assert member['name_first'] == 'John'
            assert member['name_last'] == 'Smith'
        if member['u_id'] == user_2['u_id']:
            assert member['name_first'] == 'Jane'
            assert member['name_last'] == 'Smith'

    for owner in details['owner_members']:
        if owner['u_id'] == user_1['u_id']:
            assert owner['name_first'] == 'John'
            assert owner['name_last'] == 'Smith'
        if owner['u_id'] == user_2['u_id']:
            assert owner['name_first'] == 'Jane'
            assert owner['name_last'] == 'Smith'

    user.user_profile_setname(user_2['token'], 'Bobby', 'Wills')
    details = channel.channel_details(user_1['token'],
                                      new_channel['channel_id'])
    for member in details['all_members']:
        if member['u_id'] == user_2['u_id']:
            assert member['name_first'] == 'Bobby'
            assert member['name_last'] == 'Wills'

    for owner in details['owner_members']:
        if owner['u_id'] == user_2['u_id']:
            assert owner['name_first'] == 'Bobby'
            assert owner['name_last'] == 'Wills'
    clear()
Esempio n. 6
0
def route_channel_invite():
    """Invites a user (with user id u_id) to join a channel with ID channel_id.
    Once invited the user is added to the channel immediately

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

    Returns:
        (dict): {}
    """
    payload = request.get_json()
    channel_id = int(payload['channel_id'])
    u_id = int(payload['u_id'])
    try:
        return dumps(channel.channel_invite(payload['token'], channel_id,
                                            u_id))
    except (InputError, AccessError) as e:
        return e