Example #1
0
def test_handle_already_taken():
    """
    Tests with valid token and handle that is already in use.
    InputError will occur due to handle-already-in-use.
    """

    server_data = Server_data()

    #Generate user 1 (Jessica) with automatically generated handle "jessicawu"
    user_1 = generate_user_1(server_data)
    user_1_token = user_1["token"]
    user_1_id = user_1["u_id"]

    handle_str = "jessicawu"

    #Generate user 2 (Patrick) for second call
    user_2 = generate_user_2(server_data)
    user_2_token = user_2["token"]
    user_2_id = user_2["u_id"]

    #Attempt to assign the same handle to a different user.

    #InputError will occur as the handle is already in use.
    with pytest.raises(InputError):
        user_profile_sethandle(server_data, user_2_token, handle_str)

    #Verify that neither user (User 1 and 2) were not affected by the previous
    #attempt to set an already-in-use handle to a different user.
    updated_user_1 = user_profile(server_data, user_1_token, user_1_id)
    assert updated_user_1["user"]["handle_str"] == "jessicawu"

    updated_user_2 = user_profile(server_data, user_2_token, user_2_id)
    assert updated_user_2["user"]["handle_str"] == "patrickmacalin"
def test_user_profile_invalid_uid():

    clear()
    test_user0 = create_one_test_user()

    with pytest.raises(error.InputError):
        user_profile(test_user0['token'], 100)
Example #3
0
def test_access_other_logged_out_profiles(get_users):
    jwang_token, jwang_u_id, kli_token, kli_u_id = get_users

    # user kli accessing profile of user jwang
    assert user_profile(kli_token, jwang_u_id) == {
        "user": {
            "u_id": jwang_u_id,
            "email": "*****@*****.**",
            "name_first": "Joshua",
            "name_last": "Wang",
            "handle_str": "joshuawang",
            "profile_img_url": ""
        }
    }

    auth_logout(kli_token)

    assert user_profile(jwang_token, kli_u_id) == {
        "user": {
            "u_id": kli_u_id,
            "email": "*****@*****.**",
            "name_first": "Ken",
            "name_last": "Li",
            "handle_str": "kenli",
            "profile_img_url": ""
        }
    }
Example #4
0
def test_send_multiple():
    """
    Test if the standup_send can combine multiple message from send message
    """
    channel_creater = auth.auth_register("*****@*****.**", "password",
                                         "Quick", "Shadow")
    test_user1 = auth.auth_register("*****@*****.**", "password",
                                    "Optimus", "Prime")
    test_channel_id1 = channels.channels_create(channel_creater["token"],
                                                "test1", True)
    channel.channel_join(test_user1["token"], test_channel_id1["channel_id"])
    standup.standup_start(channel_creater["token"],
                          test_channel_id1["channel_id"], 1)
    creater_profile = user.user_profile(channel_creater["token"],
                                        channel_creater["u_id"])
    test_user_profile = user.user_profile(test_user1["token"],
                                          test_user1["u_id"])
    new_message = "Know the new message"
    new_message2 = "Second message"
    standup.standup_send(channel_creater["token"],
                         test_channel_id1["channel_id"], new_message)
    standup.standup_send(test_user1["token"], test_channel_id1["channel_id"],
                         new_message2)
    inserted_message = creater_profile["user"][
        "handle_str"] + ": " + new_message + "\n"
    inserted_message += test_user_profile["user"][
        "handle_str"] + ": " + new_message2 + "\n"
    time.sleep(2)
    message_from_channel = channel.channel_messages(
        channel_creater["token"], test_channel_id1["channel_id"], 0)
    assert inserted_message == message_from_channel["messages"][0]["message"]
    assert channel_creater["u_id"] == message_from_channel["messages"][0][
        "u_id"]
    other.clear()
def test_invalid_user():
    """
    testing with a user not in database should raise an error
    """
    user = auth_register("*****@*****.**", "password", "Donald", "Trump")
    with pytest.raises(InputError):
        user_profile(user['token'], 123)
def test_user_profile_invalid_token():

    clear()
    test_user0 = create_one_test_user()

    with pytest.raises(error.AccessError):
        user_profile('invalid_token', test_user0['u_id'])
def test_user_profile_ivt():
    """
    testing with invalid token, should raise an error
    """
    user = auth_register("*****@*****.**", "password", "Donald", "Trump")
    with pytest.raises(AccessError):
        user_profile('THISISNOTATOKEN', user['u_id'])
Example #8
0
def test_user_profile_sethandle_length():
    string_3 = "aaa"
    string_20 = "x" * 20

    string_2 = "aa"
    string_21 = "q" * 21
    string_long = "w" * 50

    details = auth_register("*****@*****.**", "password1", "Varun", "Kashyap")
    token = details['token']
    uid = details['u_id']

    assert (user_profile_sethandle(token, string_3) == {})
    #check handle has been changed
    assert (user_profile(token, ["handle_str"] == string_3))
    assert (user_profile_sethandle(token, string_20) == {})
    assert (user_profile(token, ["handle_str"] == string_20))

    with pytest.raises(InputError):
        user_profile_sethandle(token, string_2)

    with pytest.raises(InputError):
        user_profile_sethandle(token, string_21)

    with pytest.raises(InputError):
        user_profile_sethandle(token, string_long)
Example #9
0
def test_handle_length():
    '''
    User registers and tries to change handle to 2 character and 27 character
    handles.
    '''
    clear()
    user = auth_register('*****@*****.**', 'uaefhuasfnf',
                         'Peter', 'Peterson')
    profile = user_profile(user['token'], user['u_id'])

    # User tries to change to short handle
    with pytest.raises(InputError):
        user_profile_sethandle(user['token'], 'h')
    with pytest.raises(InputError):
        user_profile_sethandle(user['token'], 'hi')

    # Whitespace handle
    with pytest.raises(InputError):
        user_profile_sethandle(user['token'], '   ')

    # User tries to change to long handle
    with pytest.raises(InputError):
        user_profile_sethandle(user['token'], 'thisistwentyonechars!')

    # Make sure handle is still the same (default handle)
    user_profile_sethandle(user['token'], 'dog')
    profile = user_profile(user['token'], user['u_id'])
    assert len(profile['user']['handle_str']) == 3
Example #10
0
def test_user_profile_sethandle_length():
    workspace_reset()

    string_3 = "aaa"
    string_20 = "x" * 20

    string_2 = "aa"
    string_21 = "q" * 21
    string_long = "w" * 50

    details = reg_user1()
    token = details['token']
    uid = details['u_id']

    assert (user_profile_sethandle(token, string_3) == {})
    #check handle has been changed
    assert (user_profile(token, ["handle_str"] == string_3))
    assert (user_profile_sethandle(token, string_20) == {})
    assert (user_profile(token, ["handle_str"] == string_20))

    with pytest.raises(InputError):
        user_profile_sethandle(token, string_2)

    with pytest.raises(InputError):
        user_profile_sethandle(token, string_21)

    with pytest.raises(InputError):
        user_profile_sethandle(token, string_long)
Example #11
0
def test_standup_start_simple():
    clear()
    user1, user2 = register_n_users(2)

    # Create channel and join
    channel = channels_create(user1["token"], "channel1", is_public=True)
    channel_join(user2["token"], channel["channel_id"])

    # Start the standup period
    standup = standup_start(user1["token"], channel["channel_id"], 1)
    assert standup["time_finish"] == round(time() + 1)

    # Send two standup message
    standup_send(user1["token"], channel["channel_id"], "test1")
    standup_send(user2["token"], channel["channel_id"], "test2")

    # Assert the messages are empty
    messages = channel_messages(user1["token"], channel["channel_id"],
                                0)["messages"]
    assert len(messages) == 0

    # Assert the two message has been sent when the standup period finishes
    sleep(2)
    messages = channel_messages(user1["token"], channel["channel_id"],
                                0)["messages"]
    assert len(messages) == 1

    user1_profile = user_profile(user1["token"], user1["u_id"])["user"]
    user1_handle = user1_profile["handle_str"]
    user2_handle = user_profile(user2["token"],
                                user2["u_id"])["user"]["handle_str"]
    assert messages[0][
        "message"] == f"{user1_handle}: test1\n{user2_handle}: test2"
    assert messages[0]["u_id"] == user1_profile["u_id"]
Example #12
0
def test_profile_unregistered_user():
    '''
    Testing when user is unregistered.
    '''
    clear()
    with pytest.raises(error.AccessError):
        user.user_profile('invalid_token', "invalid_u_id")
Example #13
0
def test_valid_user():
    '''
    Create a valid user
    Return the user detail associated with
    given token and u_id
    '''
    clear()
    # standard user
    user = auth_register('*****@*****.**', 'password', 'Steven',
                         'Nguyen')
    user_profile_sethandle(user['token'], 'Stevenson')
    profile = user_profile(user['token'], user['u_id'])
    assert profile['user']['name_first'] == "Steven"
    assert profile['user']['name_last'] == "Nguyen"
    assert profile['user']['u_id'] == user['u_id']
    assert profile['user']['email'] == '*****@*****.**'
    assert profile['user']['handle_str'] == 'Stevenson'

    # another regular user
    user2 = auth_register('*****@*****.**', 'madeulook',
                          'Verylongfirstname', 'Verylonglastname')
    user_profile_sethandle(user2['token'], 'LongHandleName')
    profile = user_profile(user2['token'], user2['u_id'])
    assert profile['user']['name_first'] == "Verylongfirstname"
    assert profile['user']['name_last'] == "Verylonglastname"
    assert profile['user']['u_id'] == user2['u_id']
    assert profile['user']['email'] == '*****@*****.**'
    assert profile['user']['handle_str'] == 'LongHandleName'
Example #14
0
def test_valid_u_id_but_not_token():
    """Registering a user but passing an invalid token"""
    clear()
    new_user = auth_register("*****@*****.**", "password", "name_first",
                             "name_last")
    with pytest.raises(AccessError):
        user_profile("112132", new_user["u_id"])
Example #15
0
def test_set_name_exactly_fifty(get_users):
    jwang_token, jwang_u_id = get_users[:2]

    user_profile_setname(jwang_token, "f" * 50, "l" * 50)
    assert user_profile(jwang_token,
                        jwang_u_id)["user"]["name_first"] == "f" * 50
    assert user_profile(jwang_token,
                        jwang_u_id)["user"]["name_last"] == "l" * 50
Example #16
0
def test_token_incorrect():
    reset_data()
    login = auth.auth_register("*****@*****.**", "123456", "Hayden",
                               "Jacobs")
    token = login['token']

    with pytest.raises(AccessError):
        user.user_profile("".join((token, 'wrong')), "u_id")
Example #17
0
def test_wrong_u_id():
    '''
    Testing when u_id is invalid.
    '''
    clear()
    user_1 = auth.auth_register("*****@*****.**", "password", "User_1",
                                "User_last_1")
    with pytest.raises(error.InputError):
        user.user_profile(user_1.get('token'), 'invalid_u_id')
Example #18
0
def test_profile_invalid_uID3():
    workspace_reset()

    details = reg_user1()

    payload = {'token': details['token'], 'u_id': "126261261----22322323"}

    with pytest.raises(InputError):
        user_profile(payload)
Example #19
0
def test_user_profile_setemail_unique_changes(get_users):
    jwang_token, jwang_u_id, kli_token, kli_u_id = get_users

    user_profile_setemail(kli_token, "*****@*****.**")
    user_profile_setemail(jwang_token, "*****@*****.**")
    assert user_profile(jwang_token,
                        kli_u_id)["user"]["email"] == "*****@*****.**"
    assert user_profile(
        kli_token, jwang_u_id)["user"]["email"] == "*****@*****.**"
Example #20
0
def test_profile_invalid_token():
    '''
    Testing when token is invalid.
    '''
    clear()
    user_1 = auth.auth_register("*****@*****.**", "password", "User_1",
                                "User_last_1")
    with pytest.raises(error.AccessError):
        user.user_profile('invalid_token', user_1.get('u_id'))
Example #21
0
def test_profile_invalid_uID2():
    workspace_reset()

    details = reg_user1()

    payload = {'token': details['token'], 'u_id': "22tt3t3tt3r4r"}

    with pytest.raises(InputError):
        user_profile(payload)
Example #22
0
def test_user_remove_all_details(reset, make_user_ab, make_user_cd):
    '''
    Testing that no details are left after removal
    '''
    # creating admin and user
    admin_info = make_user_ab
    user_info = make_user_cd
    user_remove(admin_info['token'], user_info['u_id'])
    with pytest.raises(InputError):
        user_profile(admin_info['token'], user_info['u_id'])
Example #23
0
def test_profile_invalid_uID1():

    workspace_reset()

    details = reg_user1()

    payload = {'token': details['token'], 'u_id': "NOT_VALID_UID"}

    with pytest.raises(InputError):
        user_profile(payload)
Example #24
0
def test_user_profile_invalid_user_id():
    """
    Tests that given a registered user and a valid token,
    the user_profile function raises an Acces Error if the u_id
    does not belong to an existing user
    """
    clear()
    user = auth_register("*****@*****.**", "password", "firstName", "lastName")
    with pytest.raises(InputError):
        user_profile(user['token'], -1)
Example #25
0
def test_profile_fail():
    reset_data()
    login = auth.auth_register("*****@*****.**", "123456", "robbie",
                               "caldwell")
    token = login['token']
    u_id = login['u_id']
    user.user_profile_sethandle(token, "Robbae01")

    with pytest.raises(InputError):
        user.user_profile(token, u_id + 1)
Example #26
0
def test_setname_invalid_token_2():
    '''
    Testing when token is invalid.
    '''
    clear()
    user_1 = auth.auth_register("*****@*****.**", "password", "Firstname",
                                "Lastname")
    user_id = user_1.get("u_id")
    with pytest.raises(error.AccessError):
        user.user_profile('invalid_token', user_id)
Example #27
0
def test_invalid_token_user_profile():
    """Passing an invalid token into user_profile"""
    # clear()
    # new_user = auth_register("*****@*****.**", "password", "name_first", "name_last")
    # with pytest.raises(InputError):
    #     user_profile("11112", 2)
    clear()
    new_user = auth_register("*****@*****.**", "password", "name_first",
                             "name_last")
    with pytest.raises(AccessError):
        user_profile(11112, new_user["u_id"])
Example #28
0
def test_user_profile_setemail_contains_nums_symbols(get_users):
    jwang_token, jwang_u_id = get_users[:2]

    user_profile_setemail(jwang_token, "*****@*****.**")
    assert user_profile(jwang_token,
                        jwang_u_id)["user"]["email"] == "*****@*****.**"

    user_profile_setemail(jwang_token, "*****@*****.**")
    assert user_profile(
        jwang_token,
        jwang_u_id)["user"]["email"] == "*****@*****.**"
Example #29
0
def test_user_profile_invalid_token():
    """
    Tests that given a registered user and an invalid token,
    the user_profile function raises an access error
    """
    clear()
    user = auth_register("*****@*****.**", "password", "firstName", "lastName")
    # Logging out invalidates your token
    auth_logout(user['token'])
    with pytest.raises(AccessError):
        user_profile(user['token'], user['u_id'])
def test_users_all():
    assert(users_all(hamish['token']) == { 
        'users': [ 

    user_profile(hamish['token'], hamish['u_id']), 

    user_profile(zach['token'], zach['u_id']),

    user_profile(kelly['token'], kelly['u_id']),

       ]   }) # Valid Display