Exemple #1
0
def test_fetch_fetch_users(username1, username2):
    """Test to make sure the users fetch behaves as expected"""
    body1 = {'data': {'users': [{'userId': 1, 'username': username1}]}}
    body2 = {'data': {'users': [{'userId': 2, 'username': username2}]}}
    httpretty.register_uri(httpretty.GET,
                           'http://test.com:7777/api/User',
                           responses=[
                               httpretty.Response(body=json.dumps(body1),
                                                  status=200),
                               httpretty.Response(body=json.dumps(body2),
                                                  status=200),
                               httpretty.Response(body='{}', status=200),
                           ])
    user_id = 1
    # pylint: disable=protected-access
    for user in c42api.fetch_users(basic_server()):
        assert 'userId' in user
        assert 'username' in user
        assert 'schema_version' in user
        assert user['schema_version'] == c42api.users.SCHEMA_VERSION
        assert user['userId'] == user_id
        if user_id == 1:
            assert user['username'] == username1
        if user_id == 2:
            assert user['username'] == username2
        user_id += 1
    assert user_id == 3
Exemple #2
0
def _run():
    """Initializes the state for the script based on command line input."""
    arg_parser = argparse.ArgumentParser()
    args = _setup_args(arg_parser)
    if args.logfile:
        c42api.set_log_file(args.logfile)

    if args.output or args.logfile:
        c42api.set_log_level(logging.DEBUG)
    else:
        c42api.set_log_level(logging.ERROR)
    server = argutil.server_from_args(args)
    is_json = args.format == 'json'
    with c42api.common.smart_open(args.output, overwrite=True) as out:
        if is_json:
            c42api.write_json(out, c42api.fetch_users(server))
        else:
            c42api.write_csv(out, c42api.fetch_users(server), args.header, shallow=True)
Exemple #3
0
def test_fetch_no_fetch_users():
    """Test behavior of users fetch with no results"""
    httpretty.register_uri(httpretty.GET, 'http://test.com:7777/api/User',
                           responses=[
                               httpretty.Response(body='{}', status=200),
                           ])
    # pylint: disable=protected-access
    for user in c42api.fetch_users(basic_server()):
        assert user is None
        assert False
Exemple #4
0
def test_fetch_no_fetch_users():
    """Test behavior of users fetch with no results"""
    httpretty.register_uri(httpretty.GET,
                           'http://test.com:7777/api/User',
                           responses=[
                               httpretty.Response(body='{}', status=200),
                           ])
    # pylint: disable=protected-access
    for user in c42api.fetch_users(basic_server()):
        assert user is None
        assert False
Exemple #5
0
def _run():
    """
    The script's body. Creates/Updates Splunk user lookup table.
    """
    app_home = common.app_home()

    lookups_dir = os.path.join(app_home, "lookups")
    old_user_lookup_table = os.path.join(lookups_dir, "user_lookup.csv")
    tmp_user_lookup_table = os.path.join(lookups_dir, "user_lookup_tmp.csv")

    if not os.path.exists(lookups_dir):
        os.makedirs(lookups_dir)

    server, _ = common.setup()

    # write user lookup table
    user_results = c42api.fetch_users(server)
    splunk_lookup_table.write_lookup_table(old_user_lookup_table, tmp_user_lookup_table, user_results,
                                           USER_UID_KEY, USER_KEYS_TO_IGNORE, TIME_KEY)
Exemple #6
0
def test_fetch_fetch_users(username1, username2):
    """Test to make sure the users fetch behaves as expected"""
    body1 = {'data': {'users': [{'userId': 1, 'username': username1}]}}
    body2 = {'data': {'users': [{'userId': 2, 'username': username2}]}}
    httpretty.register_uri(httpretty.GET, 'http://test.com:7777/api/User',
                           responses=[
                               httpretty.Response(body=json.dumps(body1), status=200),
                               httpretty.Response(body=json.dumps(body2), status=200),
                               httpretty.Response(body='{}', status=200),
                           ])
    user_id = 1
    # pylint: disable=protected-access
    for user in c42api.fetch_users(basic_server()):
        assert 'userId' in user
        assert 'username' in user
        assert 'schema_version' in user
        assert user['schema_version'] == c42api.users.SCHEMA_VERSION
        assert user['userId'] == user_id
        if user_id == 1:
            assert user['username'] == username1
        if user_id == 2:
            assert user['username'] == username2
        user_id += 1
    assert user_id == 3