Example #1
0
def test_users_all_invalid_token_error():
    workspace_reset()
    user_ef = auth_register(
        "*****@*****.**", "12345687", "Edward", "Frankenstein")

    with pytest.raises(AccessError):
        users_all(user_ef["token"] + "invalid")
Example #2
0
def test_token_user_all():
    '''
    TOken invalid
    '''
    clear()
    auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    with pytest.raises(AccessError):
        users_all('invalid')
def test_users_all_invalid_token():
    """
    Check for AccessError when invalid token
    calls users_all
    """
    login_session = auth.auth_register("*****@*****.**", "password", "John",
                                       "Reese")
    auth.auth_logout(login_session.get('token'))
    with pytest.raises(error.AccessError):
        other.users_all(login_session.get('token'))
Example #4
0
def test_users_all_register_and_call_function_one_at_a_time():
    workspace_reset()
    user_gh = auth_register("*****@*****.**",
                            "ihaveadream", "Gregory", "Heidelberg")
    user_ef = auth_register(
        "*****@*****.**", "12345687", "Edward", "Frankenstein")

    assert users_all(user_ef["token"])["users"] == [
        {
            'u_id': user_gh["u_id"],
            'email': '*****@*****.**',
            'name_first': 'Gregory',
            'name_last': 'Heidelberg',
            'handle_str': 'gregoryheidelberg',
            "profile_img_url": ""
        },
        {
            'u_id': user_ef["u_id"],
            'email': '*****@*****.**',
            'name_first': 'Edward',
            'name_last': 'Frankenstein',
            'handle_str': 'edwardfrankenstein',
            "profile_img_url": ""
        }
    ]

    user_ij = auth_register(
        "*****@*****.**", "stretchy0urh4mstrinG5thr1c3", "Ian", "Jacobs")
    assert users_all(user_ij["token"])["users"] == [
        {
            'u_id': user_gh["u_id"],
            'email': '*****@*****.**',
            'name_first': 'Gregory',
            'name_last': 'Heidelberg',
            'handle_str': 'gregoryheidelberg',
            "profile_img_url": ""
        },
        {
            'u_id': user_ef["u_id"],
            'email': '*****@*****.**',
            'name_first': 'Edward',
            'name_last': 'Frankenstein',
            'handle_str': 'edwardfrankenstein',
            "profile_img_url": ""
        },
        {
            'u_id': user_ij["u_id"],
            'email': '*****@*****.**',
            'name_first': 'Ian',
            'name_last': 'Jacobs',
            'handle_str': 'ianjacobs',
            "profile_img_url": ""
        }
    ]
Example #5
0
def test_users_all():
    '''
    Testing base case of showing registered user
    '''
    clear()
    user1 = auth_register("*****@*****.**", "user1pass", "user1", "last1", None)
    token1 = user1['token']

    print(users_all(token1))

    assert 'users' in users_all(token1)
Example #6
0
def test_users_all_logged_out():
    reset_data()
    user1_info = auth_register('*****@*****.**', 'sadsad', 'aName', 'aLastname')
    user2_info = auth_register('*****@*****.**', 'sadsad', 'bName', 'bLastname')
    # User2 logs out
    auth_logout(user2_info['token'])
    # Giving all the users' profile details
    assert users_all(user1_info['token']) == {
        'users': [
            {
                'u_id': 1,
                'email': '*****@*****.**',
                'name_first': 'aName',
                'name_last': 'aLastname',
                'handle_str': 'anamealastname',
            },
            {
                'u_id': 2,
                'email': '*****@*****.**',
                'name_first': 'bName',
                'name_last': 'bLastname',
                'handle_str': 'bnameblastname',
            },
        ],
    }
Example #7
0
def test_users_all_complex():
    user1_info = auth.auth_register('a@gmail', 'sadsad', 'aName', 'aLastname')
    user2_info = auth.auth_register('b@gmail', 'sadsad', 'bName', 'bLastname')
    user3_info = auth.auth_register('c@gmail', 'sadsad', 'cName', 'cLastname')
    # Giving all the users' profile details
    assert other.users_all(user1_info['token']) == {
        'users': [
            {
                'u_id': 1,
                'email': 'a@gmail',
                'name_first': 'aName',
                'name_last': 'aLastname',
                'handle_str': 'anamealastname',
            },
            {
                'u_id': 2,
                'email': 'b@gmail',
                'name_first': 'bName',
                'name_last': 'bLastname',
                'handle_str': 'bnameblastname',
            },
            {
                'u_id': 3,
                'email': 'c@gmail',
                'name_first': 'cName',
                'name_last': 'cLastname',
                'handle_str': 'cnameclastname',
            }
        ],

    }
Example #8
0
def test_all_users_multiple_users():
    '''
    Test that users_all works for multiple users
    '''
    other.clear()
    user_1 = {
        'u_id' : 1,
        'email' : '*****@*****.**',
        'name_first' : 'firstname',
        'name_last' : 'lastname',
        'handle_str' : 'firstnamelastname',
        'profile_img_url' : ""
    }
    
    user_2 = {
        'u_id' : 2,
        'email' : '*****@*****.**',
        'name_first' : 'Newfirstname',
        'name_last' : 'Newlastname',
        'handle_str' : 'newfirstnamenewlastn',
        'profile_img_url' : ""     
    }
    first_user = auth.auth_register('*****@*****.**', 'password', 'firstname', 'lastname')
    auth.auth_register('*****@*****.**', 'Newpassword', 'Newfirstname', 'Newlastname')
    all_users = other.users_all(first_user['token'])
    assert all_users['users'][0] == user_1
    assert all_users['users'][1] == user_2 
def test_users_all_valid_order():

    clear()
    user1 = create_two_test_users()[1]

    assert (users_all(user1['token']) != {
        'users': [
            {
                "u_id": 1,
                "email": "*****@*****.**",
                "name_first": "Jayden",
                "name_last": "Haycobs",
                "handle_str": "jaydenhaycobs",
                "profile_img_url": '',
            },
            {
                "u_id": 0,
                "email": "*****@*****.**",
                "name_first": "Hayden",
                "name_last": "Jacobs",
                "handle_str": "haydenjacobs",
                "profile_img_url": '',
            },
        ]
    })
Example #10
0
def test_clear():
    boyu_dict, _ = initialise_data()
    channel_1 = channels_create(boyu_dict['token'], 'channel_1', True)
    id_1 = message_send(boyu_dict['token'], channel_1['channel_id'], '1')
    message_send(boyu_dict['token'], channel_1['channel_id'], '2')
    message_send(boyu_dict['token'], channel_1['channel_id'], '3')
    # clear original data
    clear()
    # initialise data
    boyu_dict, _ = initialise_data()
    users_dict = users_all(boyu_dict['token'])
    # check user details already update
    assert len(users_dict['users']) == 2
    assert users_dict['users'][0]['u_id'] == boyu_dict['u_id']
    assert users_dict['users'][0]['email'] == '*****@*****.**'
    assert users_dict['users'][0]['name_first'] == 'Boyu'
    assert users_dict['users'][0]['name_last'] == 'Cai'
    # check channels list is already update
    channel_1_id = channels_create(boyu_dict['token'], 'channel_1', True)
    assert channels_listall(boyu_dict['token']) == channels_list(
        boyu_dict['token'])
    # send two message in a channel
    id_1 = message_send(boyu_dict['token'], channel_1_id['channel_id'],
                        'hello!')
    message_send(boyu_dict['token'], channel_1_id['channel_id'], 'he_llo')
    message_send(boyu_dict['token'], channel_1_id['channel_id'], 'hi there')
    search_result = search(boyu_dict['token'], "hello")
    # search message order is correct
    assert len(search_result['messages']) == 1
    assert search_result['messages'][0]["message"] == 'hello!'
    assert search_result['messages'][0]["u_id"] == boyu_dict['u_id']
    assert search_result['messages'][0]["message_id"] == id_1['message_id']
Example #11
0
def http_users_all():
    '''
    Wrapper function for users_all (retrieves all users)
    GET: JSON containing "token" (str)
    Returns JSON containing 'users' (list of dicts)
    '''
    return dumps(users_all(request.args.get('token')))
Example #12
0
def users_all_http():
    """Shows all users based on token passed in"""
    token = request.args.get("token")
    if not check_token_exists(token):
        return "Invalid Token passed", 400
    response = users_all(token)
    return jsonify(response)
Example #13
0
def test_users_all():
    boyu_token, _ = initialise_data()
    users_dict = users_all(boyu_token['token'])
    assert len(users_dict['users']) == 2
    assert users_dict['users'][0]['u_id'] == boyu_token['u_id']
    assert users_dict['users'][0]['email'] == '*****@*****.**'
    assert users_dict['users'][0]['name_first'] == 'Boyu'
    assert users_dict['users'][0]['name_last'] == 'Cai'
Example #14
0
def users_all():
    """
    Function users all route
    """
    input_data = request.args.get('token')

    users_list = other.users_all(input_data)

    return dumps(users_list)
Example #15
0
def test_users_all_invalid_token(user1):
    """
    Tests unsuccessful uses of users_all,
    focusing on invalid tokens
    """
    with pytest.raises(AccessError):
        assert other.users_all("invalid_token")

    other.clear()
Example #16
0
def test_remove():
    boyu_dict, wenyao_dict = initialise_data()
    admin_user_remove(boyu_dict['token'], wenyao_dict['u_id'])
    users_dict = users_all(boyu_dict['token'])
    assert len(users_dict['users']) == 1
    assert users_dict['users'][0]['u_id'] == boyu_dict['u_id']
    assert users_dict['users'][0]['email'] == '*****@*****.**'
    assert users_dict['users'][0]['name_first'] == 'Boyu'
    assert users_dict['users'][0]['name_last'] == 'Cai'
Example #17
0
def test_users_all():
    '''
    Test that users_all correctly shows the details of all users
    '''
    clear()
    # Invalid token
    with pytest.raises(AccessError):
        users_all('')

    # Register three users
    f_owner = auth_register('*****@*****.**', 'password', 'Mark',
                            'Zuckerberg')
    random_user1 = auth_register('*****@*****.**', 'password', 'Brian',
                                 'Paul')
    random_user2 = auth_register('*****@*****.**', 'password', 'Greg',
                                 'Stevens')

    # Set handles of the users
    user_profile_sethandle(f_owner['token'], 'MARKZUCKERBERG')
    user_profile_sethandle(random_user1['token'], 'BRIANPAUL')
    user_profile_sethandle(random_user2['token'], 'GREGSTEVENS')

    # Check users_all correctly returns details of all three users
    users_details = users_all(f_owner['token'])
    assert len(users_details['users']) == 3
    # Check details of first user
    assert users_details['users'][0]['u_id'] == f_owner['u_id']
    assert users_details['users'][0]['email'] == '*****@*****.**'
    assert users_details['users'][0]['name_first'] == 'Mark'
    assert users_details['users'][0]['name_last'] == 'Zuckerberg'
    assert users_details['users'][0]['handle_str'] == 'MARKZUCKERBERG'
    # Check details of second user
    assert users_details['users'][1]['u_id'] == random_user1['u_id']
    assert users_details['users'][1]['email'] == '*****@*****.**'
    assert users_details['users'][1]['name_first'] == 'Brian'
    assert users_details['users'][1]['name_last'] == 'Paul'
    assert users_details['users'][1]['handle_str'] == 'BRIANPAUL'
    # Check details of third user
    assert users_details['users'][2]['u_id'] == random_user2['u_id']
    assert users_details['users'][2]['email'] == '*****@*****.**'
    assert users_details['users'][2]['name_first'] == 'Greg'
    assert users_details['users'][2]['name_last'] == 'Stevens'
    assert users_details['users'][2]['handle_str'] == 'GREGSTEVENS'
def get_all_users():
    # Get current data inside store
    data = request.get_json()
    token = data['token']
    if not token_check(token):
        raise InputError(description="Invalid_token")
    user_list = users_all(token)
    return dumps({
        'users': user_list['users']
    })
Example #19
0
def test_users_all_single():
    clear()

    user = register_n_users(1, include_admin=True)

    all_users = users_all(user["token"])["users"]
    all_users_info = []
    all_users_info.append(get_user_details_from_user_id(user["u_id"]))

    assert all_users == all_users_info
Example #20
0
def test_users_all_expected_data5():
    clear()
    # create users
    user = auth_register('*****@*****.**', '123abc!@#', 'Cosmo', 'Kearns')
    auth_register('*****@*****.**', '123abc!@#', 'Abida', 'Zhang')
    auth_register("*****@*****.**", '123abc!@#', 'Brenden', 'Partridge')
    copyexpected = copy.deepcopy(expected_data5['users'])
    for users1 in copyexpected:
        del users1['permission_id']

    assert users_all(user['token']) == {'users': copyexpected}
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
Example #22
0
def users_all():
    '''
    Wrapper for users_all
    '''
    token = request.args.get('token')

    if not token:
        raise RequestError(description="Missing data in request body")

    every_user = other.users_all(token)
    return json.dumps(every_user)
Example #23
0
def test_users_all_multiple():
    '''
    Testing if function returns multiple users
    '''
    clear()
    user1 = auth_register("*****@*****.**", "user1pass", "user1", "last1", None)
    token1 = user1['token']

    auth_register("*****@*****.**", "user2pass", "user2", "last2", None)
    auth_register("*****@*****.**", "meep12", "name3", "last3", None)

    assert 'users' in users_all(token1)
Example #24
0
def test_users_all_simple():
    reset_data()
    user_info = auth_register('*****@*****.**', 'sadsad', 'name', 'lastname')
    # Giving all the users' profile details
    assert users_all(user_info['token']) == {
        'users': [{
            'u_id': 1,
            'email': '*****@*****.**',
            'name_first': 'name',
            'name_last': 'lastname',
            'handle_str': 'namelastname',
        }],
    }
Example #25
0
def test_working():
    '''
    Testing if users_all works.
    '''
    clear()
    user_1 = auth_register("*****@*****.**", "password", "Firstname", "Lastname")
    all_users = users_all(user_1.get('token')).get('users')

    assert all_users[0]['u_id'] == user_1.get('u_id')
    assert all_users[0]['email'] == "*****@*****.**"
    assert all_users[0]['name_first'] == "Firstname"
    assert all_users[0]['name_last'] == "Lastname"
    assert all_users[0]['handle_str'] == 'firstnamelastname'
Example #26
0
def test_auth_register_handle():
    clear()
    user1 = auth_register("*****@*****.**", "boyu_pass", "Boyu", "Cai")
    auth_register("*****@*****.**", "boyu_pass", "Boyu", "Cai")
    auth_register("*****@*****.**", "boyu_pass", "Boyu", "Caiiiiiiiiiiiiiiiiii")
    auth_register("*****@*****.**", "boyu_pass", "Boyu", "Caiiiiiiiiiiiiiiiiii")

    user_dict = users_all(user1['token'])
    assert len(user_dict['users'][0]['handle_str']) <= 20
    assert len(user_dict['users'][1]['handle_str']) <= 20
    assert len(user_dict['users'][2]['handle_str']) <= 20
    assert len(user_dict['users'][3]['handle_str']) <= 20
    assert user_dict['users'][0]['handle_str'] != user_dict['users'][1]['handle_str']
    assert user_dict['users'][2]['handle_str'] != user_dict['users'][3]['handle_str']
Example #27
0
def test_users_all_one_user():
    workspace_reset()
    user_ef = auth_register(
        "*****@*****.**", "12345687", "Edward", "Frankenstein")

    assert users_all(user_ef["token"])["users"] == [
        {
            'u_id': user_ef["u_id"],
            'email': '*****@*****.**',
            'name_first': 'Edward',
            'name_last': 'Frankenstein',
            'handle_str': 'edwardfrankenstein',
            "profile_img_url": ""
        }
    ]
Example #28
0
def test_users_all_single():
    other.clear()

    # register and view a single user
    u0 = auth.auth_register('*****@*****.**', 'youshallpass', 'King',
                            'Kingson')
    u0_info = {
        'u_id': u0['u_id'],
        'email': '*****@*****.**',
        'name_first': 'King',
        'name_last': 'Kingson',
        'handle_str': 'kingkingson'
    }

    users_list = other.users_all(u0['token'])
    assert users_list == {'users': [u0_info]}
Example #29
0
def test_users_all_one_user():
    clear()
    user = auth_register("*****@*****.**", 'Monkey354rahh', 'Ron', 'Weasleton')
    expected_data = {'users': [{}]}
    user1 =  {
            'u_id': 0,
            'email': '*****@*****.**',
            'name_first': 'Ron',
            'name_last': 'Weasleton',
            'handle_str': 'ronweasleton',
            'profile_img_url': ""
    }

    expected_data['users'][0] = user1

    assert users_all(user['token']) == expected_data
Example #30
0
def test_all_users_one_user():
    '''
    Test users_all works for one user
    '''
    other.clear()
    user = {
        'u_id' : 1,
        'email' : '*****@*****.**',
        'name_first' : 'firstname',
        'name_last' : 'lastname',
        'handle_str' : 'firstnamelastname',
        'profile_img_url' : ""
    }
    new_user = auth.auth_register('*****@*****.**', 'password', 'firstname', 'lastname')
    all_users = other.users_all(new_user['token'])
    assert all_users['users'][0] == user