<commit_before>import pytest
from pnc_cli import licenses
from pnc_cli.swagger_client.apis.licenses_api import LicensesApi
from pnc_cli import utils
from test import testutils

licenses_api = LicensesApi(utils.get_api_client())


@pytest.fixture(scope='function')
def new_license(request):
    license = licenses_api.create_new(body=licenses._create_license_object(full_name=testutils.gen_random_name(),
                                                                        full_content="pnc_cli-cli test license")).content
    def teardown():
        existing_licenses = licenses_api.get_all().content
        if existing_licenses and license.id in [x.id for x in existing_licenses]:
            licenses_api.delete(id=license.id)
    request.addfinalizer(teardown)
    return license

def test_get_all(new_license):
    # empty at first. create one to test.
    l = licenses_api.get_all().content
    assert l is not None


def test_create_license(new_license):
    license_ids = [x.id for x in licenses_api.get_all().content]
    assert new_license.id in license_ids


def test_get_specific(new_license):
    assert licenses_api.get_specific(new_license.id) is not None


def test_delete(new_license):
    licenses_api.delete(new_license.id)
    assert not licenses_api.get_all().content


def test_update(new_license):
    licenses_api.update(id=new_license.id, body=licenses._create_license_object(full_name='PNC-CLI updated license',                                                                                full_content='updated content'))
    updated_license = licenses_api.get_specific(new_license.id).content
    assert updated_license.full_name == 'PNC-CLI updated license' and updated_license.full_content == 'updated content'<commit_msg>increase licenses_api test coverage<commit_after>import pytest
from pnc_cli import licenses
from pnc_cli.swagger_client.apis.licenses_api import LicensesApi
from pnc_cli import utils
from test import testutils

licenses_api = LicensesApi(utils.get_api_client())


@pytest.fixture(scope='function')
def new_license(request):
    license = licenses_api.create_new(body=licenses._create_license_object(full_name=testutils.gen_random_name(),
                                                                           full_content="pnc_cli-cli test license")).content

    def teardown():
        existing_licenses = licenses_api.get_all().content
        if existing_licenses and license.id in [x.id for x in existing_licenses]:
            licenses_api.delete(id=license.id)

    request.addfinalizer(teardown)
    return license


def test_get_all_invalid_param():
    testutils.assert_raises_typeerror(licenses_api, 'get_all')


def test_get_all(new_license):
    # empty at first. create one to test.
    l = licenses_api.get_all(page_index=0, page_size=1000, sort='', q='').content
    assert l is not None


def test_create_new_invalid_param():
    testutils.assert_raises_typeerror(licenses_api, 'create_new')


def test_create_new(new_license):
    license_ids = [x.id for x in licenses_api.get_all().content]
    assert new_license.id in license_ids


def test_get_specific_no_id():
    testutils.assert_raises_valueerror(licenses_api, 'get_specific', id=None)


def test_get_specific_invalid_param():
    testutils.assert_raises_typeerror(licenses_api, 'get_specific', id=1)


def test_get_specific(new_license):
    assert licenses_api.get_specific(new_license.id) is not None


def test_update_no_id():
    testutils.assert_raises_valueerror(licenses_api, 'update', id=None)


def test_update_invalid_param():
    testutils.assert_raises_typeerror(licenses_api, 'update', id=1)


def test_update(new_license):
    licenses_api.update(id=new_license.id, body=licenses._create_license_object(full_name='PNC-CLI updated license',
                                                                                full_content='updated content'))
    updated_license = licenses_api.get_specific(new_license.id).content
    assert updated_license.full_name == 'PNC-CLI updated license' and updated_license.full_content == 'updated content'


def test_delete_no_id():
    testutils.assert_raises_valueerror(licenses_api, 'delete', id=None)


def test_delete_invalid_param():
    testutils.assert_raises_typeerror(licenses_api, 'delete', id=1)


def test_delete(new_license):
    licenses_api.delete(new_license.id)
    assert not licenses_api.get_all().content


{'fraction_non_alphanumeric': 0.08488003621548212, 'fraction_numerical': 0.0018107741059302852, 'mean_word_length': 3.792841648590022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7134546', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1304, 'n_words': 255}