Esempio n. 1
0
def test_user_authorised_user(user_1, logout_user_1):
    """Test for returning profile of a non-registered/invalid user. (Invalid token
    and u_id)
    """
    with pytest.raises(AccessError):
        user.user_profile(user_1['token'], user_1['u_id'])
    clear()
Esempio n. 2
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()
def test_handle():
    """
    Testing the method of generating handles
    """
    user1 = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian',
                               'Ilagan')
    user2 = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian',
                               'Ilagan' * 3)
    details_1 = user.user_profile(user1['token'], user1['u_id'])
    details_2 = user.user_profile(user2['token'], user2['u_id'])

    assert details_1['user']['handle_str'] == 'cilagan0'
    assert details_2['user']['handle_str'] == 'cilaganilaganilaga' + '0'
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_user_id(user_1):
    """Test whether the user profile u_id matches the u_id returned by auth_register.
    """
    user_details = user.user_profile(user_1['token'], user_1['u_id'])

    assert user_1['u_id'] == user_details['user']['u_id']
    clear()
Esempio n. 6
0
def test_valid_user_email(user_1, user_2, user_3):
    """Test whether the user's email matches the email in user_profile.
    """
    user_1_list = users_all(user_3['token'])
    user_1_profile = user.user_profile(user_3['token'], user_3['u_id'])

    for account in user_1_list['users']:
        if account['u_id'] == user_1_profile['user']['u_id']:
            assert user_1_profile['user']['email'] == account['email']
Esempio n. 7
0
def test_email_varying_domain(user_1):
    """Test for a domain other than @gmail.com
    """
    user.user_profile_setemail(user_1['token'], '*****@*****.**')

    user_details = user.user_profile(user_1['token'], user_1['u_id'])

    assert '*****@*****.**' in user_details['user']['email']
    clear()
Esempio n. 8
0
def test_valid_email(user_1):
    """Test for basic functionality for updating user email.
    """
    user.user_profile_setemail(user_1['token'], '*****@*****.**')

    user_details = user.user_profile(user_1['token'], user_1['u_id'])

    assert '*****@*****.**' in user_details['user']['email']
    clear()
Esempio n. 9
0
def test_email_min_requirements(user_1):
    """Test for an email with very minimal requirements (2 letters in the personal
    part, a '@' symbol, at least 1 letter before and after the period in the domain).
    """
    user.user_profile_setemail(user_1['token'], '*****@*****.**')

    user_details = user.user_profile(user_1['token'], user_1['u_id'])

    assert '*****@*****.**' in user_details['user']['email']
    clear()
Esempio n. 10
0
def test_valid_user_handle_str(user_1, user_2, user_3):
    """Test whether the user's handle string matches the handle string in
    user_profile.
    """
    user_1_list = users_all(user_2['token'])
    user_1_profile = user.user_profile(user_2['token'], user_2['u_id'])

    for account in user_1_list['users']:
        if account['u_id'] == user_1_profile['user']['u_id']:
            assert user_1_profile['user']['handle_str'] == account[
                'handle_str']
Esempio n. 11
0
def test_update_email(user_1):
    """Basic test for updating email twice and checking if the current email is the
    last set.
    """
    user.user_profile_setemail(user_1['token'], '*****@*****.**')
    user.user_profile_setemail(user_1['token'], '*****@*****.**')

    user_details = user.user_profile(user_1['token'], user_1['u_id'])

    assert '*****@*****.**' in user_details['user']['email']
    clear()
Esempio n. 12
0
def test_valid_user_name(user_1, user_2, user_3):
    """Test whether the first and last name of a user is the same as the names in
    user_profile.
    """
    user_1_list = users_all(user_2['token'])
    user_1_profile = user.user_profile(user_2['token'], user_2['u_id'])

    for account in user_1_list['users']:
        if account['u_id'] == user_1_profile['user']['u_id']:
            assert user_1_profile['user']['name_first'] == account[
                'name_first']
            assert user_1_profile['user']['name_last'] == account['name_last']
Esempio n. 13
0
def test_multiple_update_email(user_1):
    """Test for multiple attempts at updating a user email.
    """
    user.user_profile_setemail(user_1['token'], '*****@*****.**')
    user.user_profile_setemail(user_1['token'], '*****@*****.**')
    user.user_profile_setemail(user_1['token'], '*****@*****.**')
    user.user_profile_setemail(user_1['token'], '*****@*****.**')

    user_details = user.user_profile(user_1['token'], user_1['u_id'])

    assert '*****@*****.**' in user_details['user']['email']
    clear()
Esempio n. 14
0
def route_user_profile():
    """For a valid user, returns information about their user_id, email, first
    name, last name, and handle

    Args:
        token (string)
        u_id (int)

    Returns:
        (dict): { user }
    """
    token = request.args.get('token')
    u_id = int(request.args.get('u_id'))
    try:
        return dumps(user.user_profile(token, u_id))
    except (InputError, AccessError) as e:
        return e
Esempio n. 15
0
def test_user_u_id(user_1):
    """Test for returning the profile of a non-existant user.
    """
    with pytest.raises(InputError):
        user.user_profile(user_1['token'], user_1['u_id'] + 1)
    clear()