def test_search_profiles(testing_server):
    users = utils.load_csv(USERS_PATH, use_unicode=True)
    for user in users[0:4]:
        session = assert_verify_login(user)[1]
        profile_data = build_profile_dict(user)
        assert_update_profile(user, session, profile_data)

    for user in users[4:8]:
        session = assert_verify_login(user)[1]
        profile_data = build_profile_dict(user)
        profile_data.update({"majors": "Physics"})
        assert_update_profile(user, session, profile_data)

    physics_nursing_user = users[8]
    session = assert_verify_login(physics_nursing_user)[1]
    profile_data = build_profile_dict(physics_nursing_user)
    profile_data.update({"majors": "Physics,Nursing"})
    assert_update_profile(physics_nursing_user, session, profile_data)

    expected_search_response = [{
        "username": user["username"],
        "photo": DEFAULT_MASK_PHOTO,
        "email": user["email"],
        "full_name": user["full_name"],
        "views": "0",
    } for user in users[4:9]]
    search_response = mask_requests.get_profile_search(
        CURRENT_YEAR, dictionary_query={"majors": "physics"})
    assert search_response.status_code == 200
    actual_search_response = json.loads(search_response.text)["results"]
    for result in actual_search_response:
        assert result in expected_search_response
    assert len(actual_search_response) == len(expected_search_response)
def test_list_photos(testing_server):
    users = utils.load_csv(USERS_PATH)[0:3]

    photos = [
        settings.environment["current_year"] + "/a01-" + users[1]["wwuid"] +
        ".jpg",
        settings.environment["current_year"] + "/a02-" + users[2]["wwuid"] +
        ".jpg",
        "1718" + "/a03-" + users[2]["wwuid"] + ".jpg",
    ]

    distutils.dir_util.create_tree(
        settings.environment["profile_photos_location"], photos)
    for photo in photos:
        utils.touch(settings.environment["profile_photos_location"] + "/" +
                    photo)

    expected_empty_photos = []
    session = assert_verify_login(users[0])[1]
    empty_response = mask_requests.get_list_profile_photos(session)
    actual_empty_response = json.loads(empty_response.text)["photos"]
    assert empty_response.status_code == 200
    assert actual_empty_response == expected_empty_photos

    expected_many_photos = ["profiles/" + photo for photo in photos[1:3]]
    session = assert_verify_login(users[2])[1]
    many_response = mask_requests.get_list_profile_photos(session)
    actual_many_response = json.loads(many_response.text)["photos"]
    assert many_response.status_code == 200
    assert len(actual_many_response) == 2
    assert set(actual_many_response) == set(expected_many_photos)
def test_search_names(testing_server):
    users = utils.load_csv(USERS_PATH)
    for user in users:
        assert_verify_login(user)

    empty_response_query = "abcd"
    expected_empty_response = []
    empty_query_response = mask_requests.get_search_names_fast(
        name_query=empty_response_query)
    actual_empty_response = json.loads(empty_query_response.text)["results"]
    assert empty_query_response.status_code == 200
    assert len(actual_empty_response) == 0
    assert actual_empty_response == expected_empty_response

    many_response_query = "e"
    expected_many_response = [
        {
            'username': '******',
            'full_name': 'Delcie Lauer'
        },
        {
            'username': '******',
            'full_name': 'Eugene Burnette'
        },
        {
            'username': '******',
            'full_name': 'Lashay Semien'
        },
        {
            'username': '******',
            'full_name': 'Melva Woullard'
        },
        {
            'username': '******',
            'full_name': 'Raeann Castor'
        },
    ]
    many_query_response = mask_requests.get_search_names_fast(
        name_query=many_response_query)
    actual_many_response = json.loads(many_query_response.text)["results"]
    assert many_query_response.status_code == 200
    assert len(actual_many_response) == len(expected_many_response)
    expected_many_response = sorted(expected_many_response,
                                    key=lambda user: user["username"])
    actual_many_response = sorted(actual_many_response,
                                  key=lambda user: user["username"])
    assert actual_many_response == expected_many_response

    unique_response_query = "arm"
    expected_unique_response = [{
        "username": "******",
        "full_name": "Armanda Woolston"
    }]
    unique_query_response = mask_requests.get_search_names_fast(
        name_query=unique_response_query)
    actual_unique_response = json.loads(unique_query_response.text)["results"]
    assert unique_query_response.status_code == 200
    assert len(actual_unique_response) == 1
    assert actual_unique_response == expected_unique_response
def test_post_roles(testing_server):
    users = load_csv(USERS_PATH)
    for user in users:
        assert_verify_login(user)
        roles = ['demo_role_1', 'demo_role_2']
        response = auth_requests.post_roles(user['wwuid'], roles)
        assert (response.status_code == 201)
        response_roles_data = json.loads(response.text)['user']['roles']
        expected_roles_data = ','.join(roles)
        assert (response_roles_data == expected_roles_data)
def test_profile_noauth_private(testing_server):
    """
    If a user's privacy is set to 0, then only base info should be returned to a viewer not logged in.
    :return:
    """
    viewee = utils.load_csv(USERS_PATH, use_unicode=True)[0]
    profile_data = build_profile_dict(viewee, {"privacy": "0"})

    viewee_session = assert_verify_login(viewee)[1]
    assert_update_profile(viewee, viewee_session, profile_data)

    profile_response = mask_requests.get_profile(CURRENT_YEAR,
                                                 viewee["username"])
    expected_profile = {
        "email": viewee["email"],
        "full_name": viewee["full_name"],
        "photo": BASE_PROFILE["photo"],
        "username": viewee["username"],
    }

    actual_profile = json.loads(profile_response.text)

    assert profile_response.status_code == 200
    utils.assert_is_equal_sub_dict(expected_profile, actual_profile)
    hidden_keys = SELF_FIELDS.union(PERSONAL_FIELDS).union(IMPERSONAL_FIELDS)
    utils.assert_does_not_contain_keys(actual_profile, hidden_keys)
def test_profile_auth_other(testing_server):
    """
    If a viewer is logged in and views someone else's profile they should receive the view_other model.
    :return:
    """
    viewee, viewer = utils.load_csv(USERS_PATH, use_unicode=True)[0:2]
    profile_data = build_profile_dict(viewee)

    viewee_session = assert_verify_login(viewee)[1]
    assert_update_profile(viewee, viewee_session, profile_data)
    viewer_session = assert_verify_login(viewer)[1]

    profile_response = mask_requests.get_profile(CURRENT_YEAR,
                                                 viewee["username"],
                                                 viewer_session)

    hidden_keys = SELF_FIELDS
    expected_profile = build_profile_dict(viewee, remove_keys=hidden_keys)
    actual_profile = json.loads(profile_response.text)

    assert profile_response.status_code == 200
    utils.assert_is_equal_sub_dict(expected_profile, actual_profile)
    utils.assert_does_not_contain_keys(actual_profile, hidden_keys)
def test_search_all(testing_server):
    users = utils.load_csv(USERS_PATH, use_unicode=True)
    expected_results = []
    for user in users:
        user_session = assert_verify_login(user)[1]
        profile_data = build_profile_dict(user)
        assert_update_profile(user, user_session, profile_data)
        expected_result = dict()
        expected_result.update(user)
        expected_result.update({u"photo": BASE_PROFILE[u"photo"]})
        del (expected_result[u"wwuid"])
        expected_results.append(expected_result)
    all_response = mask_requests.get_search_all()
    expected_results = sorted(expected_results,
                              key=lambda user: user[u"username"])
    actual_results = sorted(json.loads(all_response.text)[u"results"],
                            key=lambda user: user[u"username"])
    assert all_response.status_code == 200
    assert actual_results == expected_results
def test_profile_auth_self(testing_server):
    """
    If a viewer is logged in and views their own profile they should receive the whole profile model.
    :return:
    """
    user = utils.load_csv(USERS_PATH, use_unicode=True)[0]
    profile_data = build_profile_dict(user)

    user_session = assert_verify_login(user)[1]
    assert_update_profile(user, user_session, profile_data)
    profile_response = mask_requests.get_profile(CURRENT_YEAR,
                                                 user["username"],
                                                 user_session)

    expected_profile = build_profile_dict(user)
    actual_profile = json.loads(profile_response.text)

    assert profile_response.status_code == 200
    utils.assert_is_equal_sub_dict(expected_profile, actual_profile)
def test_get_vote(testing_server):
    admin_session = election_subtests.create_elections_admin()
    election_id = election_subtests.assert_post_dynamic_election(
        admin_session)['id']
    position_resp = position_requests.post_position(
        admin_session, POSITION_DATA['position'],
        POSITION_DATA['election_type'], POSITION_DATA['active'],
        POSITION_DATA['order'])
    position_id = json.loads(position_resp.text)['id']
    vote_data = vote_subtests.create_votes(admin_session, election_id,
                                           position_id)
    users = utils.load_csv(paths.USERS_PATH)

    for count, user in enumerate(users):
        user_session = auth_subtests.assert_verify_login(user)[1]
        resp = vote_requests.get_vote(user_session, position_id,
                                      user['username'])
        assert (resp.status_code == 200)
        resp_text = json.loads(resp.text)['votes']
        for vote in resp_text:
            vote_subtests.assert_vote_data(vote, vote_data[user['username']])
Example #10
0
def create_votes(session, election_id, position_id):
    time.sleep(3)
    vote_data = {}

    users = utils.load_csv(paths.USERS_PATH)
    for count, user in enumerate(users):
        auth_requests.post_verify(user['wwuid'], user['full_name'],
                                  user['email'])
        user_session = auth_subtests.assert_verify_login(user)[1]
        vote = {
            'election': election_id,
            'position': position_id,
            "vote": user['username']
        }
        resp = vote_requests.post_vote(user_session,
                                       election=election_id,
                                       position=position_id,
                                       vote=user['username'])
        resp_text = json.loads(resp.text)
        assert (resp.status_code == 201)
        assert_vote_data(resp_text, vote)
        vote_data[resp_text['username']] = resp_text
    return vote_data
Example #11
0
def test_profile_noauth_public(testing_server):
    """
    If a user's privacy is set to 1, then impersonal info should be returned to a viewer not logged in.
    :return:
    """
    viewee = utils.load_csv(USERS_PATH, use_unicode=True)[0]
    profile_data = build_profile_dict(viewee, {"privacy": "1"})

    viewee_session = assert_verify_login(viewee)[1]
    assert_update_profile(viewee, viewee_session, profile_data)

    profile_response = mask_requests.get_profile(CURRENT_YEAR,
                                                 viewee["username"])

    hidden_keys = SELF_FIELDS.union(PERSONAL_FIELDS).union({"email"})
    expected_profile = build_profile_dict(viewee, {"privacy": "1"},
                                          hidden_keys)

    actual_profile = json.loads(profile_response.text)

    assert profile_response.status_code == 200
    utils.assert_is_equal_sub_dict(expected_profile, actual_profile)
    utils.assert_does_not_contain_keys(actual_profile, hidden_keys)
Example #12
0
def test_get_verify(testing_server):
    users = load_csv(USERS_PATH)
    for user in users:
        assert_verify_login(user)
Example #13
0
def test_update_profile(testing_server):
    users = utils.load_csv(USERS_PATH, use_unicode=True)
    for user in users:
        login_response_text, session = assert_verify_login(user)
        profile_data = build_profile_dict(user)
        assert_update_profile(user, session, profile_data)
def create_elections_admin():
    session = auth_subtests.assert_verify_login(POST_ELECTIONS_USER)[1]
    auth_requests.post_roles(POST_ELECTIONS_USER['wwuid'],
                             POST_ELECTIONS_USER['roles'])
    return session