<commit_before>import arcgis_sdk
import json
import pytest
import responses


@responses.activate
def test_refresh_token(client):
    responses.add(
        responses.GET,
        arcgis_sdk.ARCGIS_API_URL + 'oauth2/token/',
        body=json.dumps({
            'access_token': '<PASSWORD>!'
        }),
        status=200,
        content_type='application/json'
    )

    assert client.refresh_token(
        client_id='client_id',
        refresh_token='<PASSWORD>'
    )['access_token'] == 'new!'


@responses.activate
def test_self(client):
    responses.add(
        responses.GET,
        arcgis_sdk.ARCGIS_API_URL + 'portals/self',
        body=json.dumps({
            'name': 'test'
        }),
        status=200,
        content_type='application/json'
    )

    assert client.self()['name'] == 'test'


@responses.activate
def test_search_users(client):
    responses.add(
        responses.GET,
        arcgis_sdk.ARCGIS_API_URL + 'community/users',
        body=json.dumps({
            'total': 1
        }),
        status=200,
        content_type='application/json'
    )

    assert client.users(q='test')['total'] == 1


@responses.activate
def test_user_detail(client):
    responses.add(
        responses.GET,
        arcgis_sdk.ARCGIS_API_URL + 'community/users/test',
        body=json.dumps({
            'username': 'test'
        }),
        status=200,
        content_type='application/json'
    )

    assert client.user_detail('test')['username'] == 'test'


@responses.activate
def test_search_groups(client):
    responses.add(
        responses.GET,
        arcgis_sdk.ARCGIS_API_URL + 'community/groups',
        body=json.dumps({
            'total': 1
        }),
        status=200,
        content_type='application/json'
    )

    assert client.groups(q='test')['total'] == 1


@responses.activate
def test_create_group(client):
    responses.add(
        responses.POST,
        arcgis_sdk.ARCGIS_API_URL + 'community/createGroup',
        body=json.dumps({
            'success': True
        }),
        status=200,
        content_type='application/json'
    )

    assert client.create_group(
        title='test',
        access='public'
    )['success'] is True


@responses.activate
def test_update_group(client):
    responses.add(
        responses.POST,
        arcgis_sdk.ARCGIS_API_URL + 'community/groups/test/update',
        body=json.dumps({
            'success': True
        }),
        status=200,
        content_type='application/json'
    )

    assert client.update_group(
        group_id='test',
        title='edit'
    )['success'] is True


@responses.activate
def test_add_users_to_group(client, users):
    responses.add(
        responses.POST,
        arcgis_sdk.ARCGIS_API_URL + 'community/groups/test/addUsers',
        body=json.dumps({
            'added': users.split(',')
        }),
        status=200,
        content_type='application/json'
    )

    assert 'added' in client.add_users_to_group(
        group_id='test',
        users=users
    )


@responses.activate
def test_invite_to_group(client, users):
    responses.add(
        responses.POST,
        arcgis_sdk.ARCGIS_API_URL + 'community/groups/test/invite',
        body=json.dumps({
            'success': True
        }),
        status=200,
        content_type='application/json'
    )

    assert client.invite_to_group(
        group_id='test',
        users=users
    )['success'] is True<commit_msg>Add test cases<commit_after>import arcgis_sdk
import json
import pytest
import responses


@responses.activate
def test_refresh_token(client):
    responses.add(
        responses.GET,
        arcgis_sdk.ARCGIS_API_URL + 'oauth2/token/',
        body=json.dumps({
            'access_token': '<PASSWORD>!'
        }),
        status=200,
        content_type='application/json'
    )

    assert client.refresh_token(
        client_id='client_id',
        refresh_token='<PASSWORD>'
    )['access_token'] == 'new!'


@responses.activate
def test_self(client):
    responses.add(
        responses.GET,
        arcgis_sdk.ARCGIS_API_URL + 'portals/self',
        body=json.dumps({
            'name': 'test'
        }),
        status=200,
        content_type='application/json'
    )

    assert client.self()['name'] == 'test'


@responses.activate
def test_search_users(client):
    responses.add(
        responses.GET,
        arcgis_sdk.ARCGIS_API_URL + 'community/users',
        body=json.dumps({
            'total': 1
        }),
        status=200,
        content_type='application/json'
    )

    assert client.users(q='test')['total'] == 1


@responses.activate
def test_user_detail(client):
    responses.add(
        responses.GET,
        arcgis_sdk.ARCGIS_API_URL + 'community/users/test',
        body=json.dumps({
            'username': 'test'
        }),
        status=200,
        content_type='application/json'
    )

    assert client.user_detail('test')['username'] == 'test'


@responses.activate
def test_search_groups(client):
    responses.add(
        responses.GET,
        arcgis_sdk.ARCGIS_API_URL + 'community/groups',
        body=json.dumps({
            'total': 1
        }),
        status=200,
        content_type='application/json'
    )

    assert client.groups(q='test')['total'] == 1


@responses.activate
def test_create_group(client):
    responses.add(
        responses.POST,
        arcgis_sdk.ARCGIS_API_URL + 'community/createGroup',
        body=json.dumps({
            'success': True
        }),
        status=200,
        content_type='application/json'
    )

    assert client.create_group(
        title='test',
        access='public'
    )['success'] is True


@responses.activate
def test_update_group(client):
    responses.add(
        responses.POST,
        arcgis_sdk.ARCGIS_API_URL + 'community/groups/test/update',
        body=json.dumps({
            'success': True
        }),
        status=200,
        content_type='application/json'
    )

    assert client.update_group(
        group_id='test',
        title='edit'
    )['success'] is True


@responses.activate
def test_delete_group(client, users):
    responses.add(
        responses.POST,
        arcgis_sdk.ARCGIS_API_URL + 'community/groups/test/delete',
        body=json.dumps({
            'success': True
        }),
        status=200,
        content_type='application/json'
    )

    assert client.delete_group(
        group_id='test'
    )['success'] is True


@responses.activate
def test_add_users_to_group(client, users):
    responses.add(
        responses.POST,
        arcgis_sdk.ARCGIS_API_URL + 'community/groups/test/addUsers',
        body=json.dumps({
            'added': users.split(',')
        }),
        status=200,
        content_type='application/json'
    )

    assert 'added' in client.add_users_to_group(
        group_id='test',
        users=users
    )


@responses.activate
def test_invite_to_group(client, users):
    responses.add(
        responses.POST,
        arcgis_sdk.ARCGIS_API_URL + 'community/groups/test/invite',
        body=json.dumps({
            'success': True
        }),
        status=200,
        content_type='application/json'
    )

    assert client.invite_to_group(
        group_id='test',
        users=users
    )['success'] is True


@responses.activate
def test_add_item(client, users):
    responses.add(
        responses.POST,
        arcgis_sdk.ARCGIS_API_URL + 'content/users/test/addItem',
        body=json.dumps({
            'success': True
        }),
        status=200,
        content_type='application/json'
    )

    assert client.add_item(
        username='test',
        title='my item',
        type='Web Mapping Application'
    )['success'] is True
{'fraction_non_alphanumeric': 0.12496772527756261, 'fraction_numerical': 0.009036922282468371, 'mean_word_length': 2.277072758037225, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5171418', 'n_tokens_mistral': 2523, 'n_tokens_neox': 2469, 'n_words': 370}