diff --git a/tenable/io/tags.py b/tenable/io/tags.py index f77218a75..50327b7a6 100644 --- a/tenable/io/tags.py +++ b/tenable/io/tags.py @@ -573,10 +573,7 @@ def edit( payload['filters'] = current['filters'] return self._api.put( - 'tags/values/{}'.format( - scrub(self._check('tag_value_uuid', tag_value_uuid, 'uuid')), - json=payload, - ) + f'tags/values/{scrub(tag_value_uuid)}', json=payload ).json() def edit_category(self, tag_category_uuid, name=None, description=None): @@ -606,10 +603,7 @@ def edit_category(self, tag_category_uuid, name=None, description=None): if description: payload['description'] = self._check('description', description, str) return self._api.put( - 'tags/categories/{}'.format( - scrub(self._check('tag_category_uuid', tag_category_uuid, 'uuid')), - json=payload, - ) + f'tags/categories/{scrub(tag_category_uuid)}', json=payload ).json() def _tag_list_constructor(self, filters, filterdefs, filter_type, sort): diff --git a/tests/io/test_tags.py b/tests/io/test_tags.py index ddb53d259..0ff71258e 100644 --- a/tests/io/test_tags.py +++ b/tests/io/test_tags.py @@ -1,52 +1,55 @@ -''' +""" test tags -''' +""" + import uuid + import pytest -from tests.checker import check, single + +from tenable.errors import UnexpectedValueError from tenable.io.tags import TagsIterator +from tests.checker import check, single from tests.pytenable_log_handler import log_exception -from tenable.errors import UnexpectedValueError @pytest.fixture(name='tagfilters') def fixture_tagfilters(): - ''' + """ Returns tag filter structure - ''' + """ return [('ipv4', 'eq', ['192.168.0.0/24'])] @pytest.fixture(name='filterdefs') def fixture_filterdefs(): - ''' + """ Returns filter definition of ipv4 type filter - ''' + """ return { 'ipv4': { 'choices': None, 'operators': ['eq'], - 'pattern': - '^(\\s*((?=\\d+\\.\\d+\\.\\d+\\.\\d+(?:\\/|-|\\s*,|$))' - '(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.?){4})' - '(?:(?:\\/(?:3[0-2]|[12]+\\d|[1-9]))|((?:-(?=\\d+\\.\\d+\\.\\d+\\.\\d+)' - '(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.?){4})|(?:\\s*,(?:\\s*)))?)+)+$'}, + 'pattern': '^(\\s*((?=\\d+\\.\\d+\\.\\d+\\.\\d+(?:\\/|-|\\s*,|$))' + '(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.?){4})' + '(?:(?:\\/(?:3[0-2]|[12]+\\d|[1-9]))|((?:-(?=\\d+\\.\\d+\\.\\d+\\.\\d+)' + '(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.?){4})|(?:\\s*,(?:\\s*)))?)+)+$', + }, } @pytest.fixture(name='tagvalue') @pytest.mark.vcr() def fixture_tagvalue(request, api): - ''' + """ Fixture to create tag value. Please note that If the tag value already exist in the instance, it deletes that tag and create one - ''' + """ tag = api.tags.create('Example', str(uuid.uuid4())) def teardown(): - ''' + """ cleanup function to delete tag value - ''' + """ api.tags.delete(tag['uuid']) assert not tag_exists(api, tag['uuid']) @@ -57,15 +60,15 @@ def teardown(): @pytest.fixture(name='tagcat') @pytest.mark.vcr() def fixture_tagcat(request, api): - ''' + """ Fixture to create tag category - ''' + """ tag = api.tags.create_category('Example category') def teardown(): - ''' + """ cleanup function to delete tag category - ''' + """ api.tags.delete_category(tag['uuid']) request.addfinalizer(teardown) @@ -75,20 +78,25 @@ def teardown(): @pytest.fixture(name='custom_tagvalue') @pytest.mark.vcr() def fixture_custom_tagvalue(request, api, user, tagfilters): - ''' + """ Fixture to create tag value. Please note that If the tag value already exist in the instance, it deletes that tag and create one - ''' + """ value_uuid = 'tag value uuid: {}'.format(str(uuid.uuid4())) - tag = api.tags.create('Example', value=value_uuid, - all_users_permissions=['CAN_EDIT'], - current_domain_permissions=[(user['uuid'], user['username'], 'user', ['CAN_EDIT'])], - filters=tagfilters) + tag = api.tags.create( + 'Example', + value=value_uuid, + all_users_permissions=['CAN_EDIT'], + current_domain_permissions=[ + (user['uuid'], user['username'], 'user', ['CAN_EDIT']) + ], + filters=tagfilters, + ) def teardown(): - ''' + """ cleanup function to delete tag value - ''' + """ api.tags.delete(tag['uuid']) assert not tag_exists(api, tag['uuid']) @@ -98,292 +106,337 @@ def teardown(): def test_tags_permission_constructor_id_typeerror(api): - ''' + """ test to raise exception when type of id param does not match the expected type. - ''' + """ with pytest.raises(TypeError): getattr(api.tags, '_permission_constructor')([(1, 'something', 'user')]) def test_tags_permission_constructor_id_unexpectedvalueerror(api): - ''' + """ test to raise exception when id param value does not match the pattern. - ''' + """ with pytest.raises(UnexpectedValueError): - getattr(api.tags, '_permission_constructor')([('something', 'something', 'user')]) + getattr(api.tags, '_permission_constructor')( + [('something', 'something', 'user')] + ) def test_tags_permission_constructor_name_typeerror(api): - ''' + """ test to raise exception when type of name param does not match the expected type. - ''' + """ with pytest.raises(TypeError): getattr(api.tags, '_permission_constructor')([(str(uuid.uuid4()), 1, 'user')]) def test_tags_permission_constructor_type_typeerror(api): - ''' + """ test to raise exception when type of type param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - getattr(api.tags, '_permission_constructor')([(str(uuid.uuid4()), 'something', 1)]) + getattr(api.tags, '_permission_constructor')( + [(str(uuid.uuid4()), 'something', 1)] + ) def test_tags_permission_constructor_type_unexpectedvalueerror(api): - ''' + """ test to raise exception when type param value does not match the choices. - ''' + """ with pytest.raises(UnexpectedValueError): - getattr(api.tags, '_permission_constructor')([ - (str(uuid.uuid4()), 'something', 'something')]) + getattr(api.tags, '_permission_constructor')( + [(str(uuid.uuid4()), 'something', 'something')] + ) def test_tags_permission_constructor_permissions_typeerror(api): - ''' + """ test to raise exception when type of permissions param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - getattr(api.tags, '_permission_constructor')([ - (str(uuid.uuid4()), 'something', 'user', 1)]) + getattr(api.tags, '_permission_constructor')( + [(str(uuid.uuid4()), 'something', 'user', 1)] + ) def test_tags_permission_constructor_permissions_unexpectedvalueerror(api): - ''' + """ test to raise exception when permissions param value does not match the choices. - ''' + """ with pytest.raises(UnexpectedValueError): - getattr(api.tags, '_permission_constructor')([ - (str(uuid.uuid4()), 'something', 'user', ['something'])]) + getattr(api.tags, '_permission_constructor')( + [(str(uuid.uuid4()), 'something', 'user', ['something'])] + ) def test_tags_permission_constructor_dict_id_typeerror(api): - ''' + """ test to raise exception when type of id param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - getattr(api.tags, '_permission_constructor')([{ - 'id': 1, - "name": 'something', - "type": 'something', - "permissions": [], - }]) + getattr(api.tags, '_permission_constructor')( + [ + { + 'id': 1, + 'name': 'something', + 'type': 'something', + 'permissions': [], + } + ] + ) def test_tags_permission_constructor_dict_id_unexpectedvalueerror(api): - ''' + """ test to raise exception when id param value does not match the pattern. - ''' + """ with pytest.raises(UnexpectedValueError): - getattr(api.tags, '_permission_constructor')([{ - 'id': 'something', - "name": 'something', - "type": 'something', - "permissions": [], - }]) + getattr(api.tags, '_permission_constructor')( + [ + { + 'id': 'something', + 'name': 'something', + 'type': 'something', + 'permissions': [], + } + ] + ) def test_tags_permission_constructor_dict_name_typeerror(api): - ''' + """ test to raise exception when type of name param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - getattr(api.tags, '_permission_constructor')([{ - 'id': str(uuid.uuid4()), - "name": 1, - "type": 'something', - "permissions": [], - }]) + getattr(api.tags, '_permission_constructor')( + [ + { + 'id': str(uuid.uuid4()), + 'name': 1, + 'type': 'something', + 'permissions': [], + } + ] + ) def test_tags_permission_constructor_dict_type_typeerror(api): - ''' + """ test to raise exception when type of type param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - getattr(api.tags, '_permission_constructor')([{ - 'id': str(uuid.uuid4()), - "name": 'something', - "type": 1, - "permissions": [], - }]) + getattr(api.tags, '_permission_constructor')( + [ + { + 'id': str(uuid.uuid4()), + 'name': 'something', + 'type': 1, + 'permissions': [], + } + ] + ) def test_tags_permission_constructor_dict_type_unexpectedvalueerror(api): - ''' + """ test to raise exception when type param value does not match the choices. - ''' + """ with pytest.raises(UnexpectedValueError): - getattr(api.tags, '_permission_constructor')([{ - 'id': str(uuid.uuid4()), - "name": 'something', - "type": 'something', - "permissions": [], - }]) + getattr(api.tags, '_permission_constructor')( + [ + { + 'id': str(uuid.uuid4()), + 'name': 'something', + 'type': 'something', + 'permissions': [], + } + ] + ) def test_tags_permission_constructor_dict_permission_typeerror(api): - ''' + """ test to raise exception when type of permission param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - getattr(api.tags, '_permission_constructor')([{ - 'id': str(uuid.uuid4()), - "name": 'something', - "type": 'user', - "permissions": 1, - }]) + getattr(api.tags, '_permission_constructor')( + [ + { + 'id': str(uuid.uuid4()), + 'name': 'something', + 'type': 'user', + 'permissions': 1, + } + ] + ) def test_tags_permission_constructor_dict_permission_unexpectedvalueerror(api): - ''' + """ test to raise exception when permission param value does not match the choices. - ''' + """ with pytest.raises(UnexpectedValueError): - getattr(api.tags, '_permission_constructor')([{ - 'id': str(uuid.uuid4()), - "name": 'something', - "type": 'user', - "permissions": ['something'], - }]) + getattr(api.tags, '_permission_constructor')( + [ + { + 'id': str(uuid.uuid4()), + 'name': 'something', + 'type': 'user', + 'permissions': ['something'], + } + ] + ) def test_tags_permission_constructor_tuple_pass(api): - ''' + """ test to parse tuple type current_domain_permissions - ''' + """ user = str(uuid.uuid4()) - assert getattr(api.tags, '_permission_constructor')([ - (user, 'test', 'user', ['CAN_EDIT']) - ]) == [{'permissions': ['CAN_EDIT'], 'type': 'USER', 'name': 'test', 'id': user}] + assert getattr(api.tags, '_permission_constructor')( + [(user, 'test', 'user', ['CAN_EDIT'])] + ) == [{'permissions': ['CAN_EDIT'], 'type': 'USER', 'name': 'test', 'id': user}] # when permissions not passed - assert getattr(api.tags, '_permission_constructor')([ - (user, 'test', 'user') - ]) == [{'permissions': [], 'type': 'USER', 'name': 'test', 'id': user}] + assert getattr(api.tags, '_permission_constructor')([(user, 'test', 'user')]) == [ + {'permissions': [], 'type': 'USER', 'name': 'test', 'id': user} + ] def test_tags_permission_constructor_dict_pass(api): - ''' + """ test to parse dict type current_domain_permission - ''' + """ user = str(uuid.uuid4()) - assert getattr(api.tags, '_permission_constructor')([ - {'id': user, 'name': 'test', 'type': 'user', 'permissions': ['CAN_EDIT']} - ]) == [{'permissions': ['CAN_EDIT'], 'type': 'USER', 'name': 'test', 'id': user}] + assert getattr(api.tags, '_permission_constructor')( + [{'id': user, 'name': 'test', 'type': 'user', 'permissions': ['CAN_EDIT']}] + ) == [{'permissions': ['CAN_EDIT'], 'type': 'USER', 'name': 'test', 'id': user}] # when permissions not passed - assert getattr(api.tags, '_permission_constructor')([ - {'id': user, 'name': 'test', 'type': 'user'} - ]) == [{'permissions': [], 'type': 'USER', 'name': 'test', 'id': user}] + assert getattr(api.tags, '_permission_constructor')( + [{'id': user, 'name': 'test', 'type': 'user'}] + ) == [{'permissions': [], 'type': 'USER', 'name': 'test', 'id': user}] def test_tags_tag_value_constructor_filter_type_typeerror(api, tagfilters, filterdefs): - ''' + """ test to raise exception when type of filter_type param does not match the expected type. - ''' + """ with pytest.raises(TypeError): getattr(api.tags, '_tag_value_constructor')( - filters=tagfilters, filterdefs=filterdefs, filter_type=1) + filters=tagfilters, filterdefs=filterdefs, filter_type=1 + ) -def test_tags_tag_value_constructor_filter_type_unexpectedvalueerror(api, tagfilters, filterdefs): - ''' +def test_tags_tag_value_constructor_filter_type_unexpectedvalueerror( + api, tagfilters, filterdefs +): + """ test to raise exception when filter_type param value does not match the choices. - ''' + """ with pytest.raises(UnexpectedValueError): - getattr(api.tags, '_tag_value_constructor')(filters=tagfilters, - filterdefs=filterdefs, filter_type='nope') + getattr(api.tags, '_tag_value_constructor')( + filters=tagfilters, filterdefs=filterdefs, filter_type='nope' + ) def test_tags_tag_value_constructor_pass(api, tagfilters, filterdefs): - ''' + """ test to parse tag value filters - ''' + """ assert getattr(api.tags, '_tag_value_constructor')( filters=tagfilters, filterdefs=filterdefs, filter_type='and' - ) == {'asset': {'and': [{'field': 'ipv4', 'operator': 'eq', 'value': '192.168.0.0/24'}]}} + ) == { + 'asset': { + 'and': [{'field': 'ipv4', 'operator': 'eq', 'value': '192.168.0.0/24'}] + } + } @pytest.mark.vcr() def test_tags_create_category_typeerror(api): - ''' + """ test to raise exception when type of category param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.create(1, '') @pytest.mark.vcr() def test_tags_create_value_typerror(api): - ''' + """ test to raise exception when type of value param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.create('', 1) @pytest.mark.vcr() def test_tags_create_value_description_typerror(api): - ''' + """ test to raise exception when type of description param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.create('', '', description=1) @pytest.mark.vcr() def test_tags_create_value_category_description_typeerror(api): - ''' + """ test to raise exception when type of category_description param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - api.tags.create('a7b7ebf6-8aaf-4509-a5b3-872b7647fa86', '', category_description=1) + api.tags.create( + 'a7b7ebf6-8aaf-4509-a5b3-872b7647fa86', '', category_description=1 + ) @pytest.mark.vcr() def test_tags_create_all_users_permissions_typeerror(api): - ''' + """ test to raise exception when type of all_users_permissions param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.create('', '', all_users_permissions=1) @pytest.mark.vcr() def test_tags_create_all_users_permissions_unexpectedvalueerror(api): - ''' + """ test to raise exception when all_users_permission param value does not match the choices. - ''' + """ with pytest.raises(UnexpectedValueError): api.tags.create('', '', all_users_permissions=['something']) @pytest.mark.vcr() def test_tags_create_current_domain_permissions_typeerror(api): - ''' + """ test to raise exception when type of current_domain_permission param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.create('', '', current_domain_permissions=1) @pytest.mark.vcr() def test_tags_create_filters_typeerror(api): - ''' + """ test to raise exception when type of filters param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.create('', '', filters=1) @pytest.mark.vcr() def test_tags_create_success(tagvalue): - ''' + """ test to create tag value. - ''' + """ assert isinstance(tagvalue, dict) check(tagvalue, 'uuid', 'uuid') check(tagvalue, 'created_at', 'datetime') @@ -402,11 +455,13 @@ def test_tags_create_success(tagvalue): @pytest.mark.vcr() -def test_tags_create_filters_and_access_control_success(api, tagfilters, user, custom_tagvalue): - ''' +def test_tags_create_filters_and_access_control_success( + api, tagfilters, user, custom_tagvalue +): + """ test to create tag value and assign all_users_permissions, current_domain_permission and filters - ''' + """ assert isinstance(custom_tagvalue, dict) check(custom_tagvalue, 'uuid', 'uuid') check(custom_tagvalue, 'created_at', 'datetime') @@ -423,17 +478,20 @@ def test_tags_create_filters_and_access_control_success(api, tagfilters, user, c check(custom_tagvalue['access_control'], 'defined_domain_permissions', list) check(custom_tagvalue, 'filters', dict, allow_none=True) assert custom_tagvalue['access_control']['all_users_permissions'] == ['CAN_EDIT'] - assert any(v['id'] == user['uuid'] - for v in custom_tagvalue['access_control']['current_domain_permissions']) + assert any( + v['id'] == user['uuid'] + for v in custom_tagvalue['access_control']['current_domain_permissions'] + ) assert custom_tagvalue['filters'] == { - 'asset': '{"and":[{"field":"ipv4","operator":"eq","value":"192.168.0.0/24"}]}'} + 'asset': '{"and":[{"field":"ipv4","operator":"eq","value":"192.168.0.0/24"}]}' + } @pytest.mark.vcr() def test_tags_create_category_name_typeerror(api): - ''' + """ test to raise exception when type of name param does not match the expected type. - ''' + """ try: with pytest.raises(TypeError): api.tags.create_category(1) @@ -443,9 +501,9 @@ def test_tags_create_category_name_typeerror(api): @pytest.mark.vcr() def test_tags_create_category_description_typeerror(api): - ''' + """ test to raise exception when type of description param does not match the expected type. - ''' + """ try: with pytest.raises(TypeError): api.tags.create_category('', description=1) @@ -455,9 +513,9 @@ def test_tags_create_category_description_typeerror(api): @pytest.mark.vcr() def test_tags_create_category_success(tagcat): - ''' + """ test to create tag category. - ''' + """ assert isinstance(tagcat, dict) check(tagcat, 'uuid', 'uuid') check(tagcat, 'created_at', 'datetime') @@ -470,53 +528,53 @@ def test_tags_create_category_success(tagcat): @pytest.mark.vcr() def test_tags_delete_uuid_typeerror(api): - ''' + """ test to raise exception when type of tag_value_uuid param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.delete(1) @pytest.mark.vcr() def test_tags_delete_uuid_unexpectedvalueerror(api): - ''' + """ test to raise exception when type of tag_value_uuid param does not match the expected type. - ''' + """ with pytest.raises(UnexpectedValueError): api.tags.delete('1') @pytest.mark.vcr() def test_tags_delete_success(api, tagvalue): - ''' + """ test to delete tag value. - ''' + """ api.tags.delete(tagvalue['uuid']) @pytest.mark.vcr() def test_tags_delete_bulk_typeerror(api, tagvalue): - ''' + """ test to raise exception when type of tag_value_uuid param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.delete(tagvalue['uuid'], 1) @pytest.mark.vcr() def test_tags_delete_bulk_unexpectedvalueerror(api, tagvalue): - ''' + """ test to raise exception when type of tag_value_uuid param does not match the expected type. - ''' + """ with pytest.raises(UnexpectedValueError): api.tags.delete(tagvalue['uuid'], 'nope') @pytest.mark.vcr() def test_tags_delete_bulk_success(api): - ''' + """ test to delete multiple tags . - ''' + """ tag1 = api.tags.create('Example', str(uuid.uuid4())) tag2 = api.tags.create('Example', str(uuid.uuid4())) api.tags.delete(tag1['uuid'], tag2['uuid']) @@ -524,53 +582,53 @@ def test_tags_delete_bulk_success(api): @pytest.mark.vcr() def test_tags_delete_category_uuid_typeerror(api): - ''' + """ test to raise exception when type of tag_category_uuid param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.delete_category(1) @pytest.mark.vcr() def test_tags_delete_category_uuid_unexpectedvalueerror(api): - ''' + """ test to raise exception when type of tag_category_uuid param does not match the expected type. - ''' + """ with pytest.raises(UnexpectedValueError): api.tags.delete_category('1') @pytest.mark.vcr() def test_tags_delete_category_success(api, tagcat): - ''' + """ test to delete tag category. - ''' + """ api.tags.delete_category(tagcat['uuid']) @pytest.mark.vcr() def test_tags_details_uuid_typeerror(api): - ''' + """ test to raise exception when type of tag_value_uuid param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.details(1) @pytest.mark.vcr() def test_tags_details_unexpectedvalueerror(api): - ''' + """ test to raise exception when type of tag_value_uuid param does not match the expected type. - ''' + """ with pytest.raises(UnexpectedValueError): api.tags.details('1') @pytest.mark.vcr() def test_tags_details_success(api, tagvalue): - ''' + """ test to get details for a specific tag category/value pair. - ''' + """ details = api.tags.details(tagvalue['uuid']) assert isinstance(details, dict) check(details, 'uuid', 'uuid') @@ -588,27 +646,27 @@ def test_tags_details_success(api, tagvalue): @pytest.mark.vcr() def test_tags_details_category_uuid_typeerror(api): - ''' + """ test to raise exception when type of tag_category_uuid param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.details_category(1) @pytest.mark.vcr() def test_tags_details_category_unexpectedvalueerror(api): - ''' + """ test to raise exception when type of tag_category_uuid param does not match the expected type. - ''' + """ with pytest.raises(UnexpectedValueError): api.tags.details_category('1') @pytest.mark.vcr() def test_tags_details_category_success(api, tagcat): - ''' + """ test to get details for a specific tag category. - ''' + """ details = api.tags.details_category(tagcat['uuid']) assert isinstance(details, dict) check(details, 'uuid', 'uuid') @@ -623,83 +681,83 @@ def test_tags_details_category_success(api, tagcat): @pytest.mark.vcr() def test_tags_edit_uuid_typeerror(api): - ''' + """ test to raise exception when type of tag_value_uuid param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.edit(1) @pytest.mark.vcr() def test_tags_edit_uuid_unexpectedvalueerror(api): - ''' + """ test to raise exception when type of tag_value_uuid param does not match the expected type. - ''' + """ with pytest.raises(UnexpectedValueError): api.tags.edit('1') @pytest.mark.vcr() def test_tags_edit_value_typeerror(api): - ''' + """ test to raise exception when type of value param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.edit(uuid.uuid4(), value=1) @pytest.mark.vcr() def test_tags_edit_description_typeerror(api): - ''' + """ test to raise exception when type of description param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.edit(uuid.uuid4(), description=1) @pytest.mark.vcr() def test_tags_edit_all_users_permissions_typeerror(api, tagvalue): - ''' + """ test to raise exception when type of all_users_permission param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.edit(tagvalue['uuid'], all_users_permissions=1) @pytest.mark.vcr() def test_tags_edit_all_users_permissions_unexpectedvalueerror(api, tagvalue): - ''' + """ test to raise exception when all_users_permission param value does not match the choices. - ''' + """ with pytest.raises(UnexpectedValueError): api.tags.edit(tagvalue['uuid'], all_users_permissions=['something']) @pytest.mark.vcr() def test_tags_edit_current_domain_permissions_typeerror(api, tagvalue): - ''' + """ test to raise exception when type of current_domain_permission param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.edit(tagvalue['uuid'], current_domain_permissions=1) @pytest.mark.vcr() def test_tags_edit_filters_typeerror(api, tagvalue): - ''' + """ test to raise exception when type of filters param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.edit(tagvalue['uuid'], filters=1) @pytest.mark.vcr() def test_tags_edit_success(api, tagvalue): - ''' + """ test to edit tag category/value pair information. - ''' + """ resp = api.tags.edit(tagvalue['uuid'], value='Edited') assert isinstance(resp, dict) check(resp, 'uuid', 'uuid') @@ -723,15 +781,19 @@ def test_tags_edit_success(api, tagvalue): @pytest.mark.vcr() -def test_tags_edit_filters_and_access_control_success(api, user, tagfilters, custom_tagvalue): - ''' +def test_tags_edit_filters_and_access_control_success( + api, user, tagfilters, custom_tagvalue +): + """ test to edit tag value and update all_users_permissions, current_domain_permission and filters - ''' - resp = api.tags.edit(custom_tagvalue['uuid'], - filters=[('ipv4', 'eq', ['127.0.0.1'])], - all_users_permissions=[], - current_domain_permissions=[]) + """ + resp = api.tags.edit( + custom_tagvalue['uuid'], + filters=[('ipv4', 'eq', ['127.0.0.1'])], + all_users_permissions=[], + current_domain_permissions=[], + ) assert isinstance(resp, dict) check(resp, 'uuid', 'uuid') check(resp, 'created_at', 'datetime') @@ -751,54 +813,39 @@ def test_tags_edit_filters_and_access_control_success(api, user, tagfilters, cus check(resp['access_control'], 'defined_domain_permissions', list) check(custom_tagvalue, 'filters', dict, allow_none=True) assert resp['access_control']['all_users_permissions'] == [] - assert not any(v['id'] == user['uuid'] - for v in resp['access_control']['current_domain_permissions']) + assert not any( + v['id'] == user['uuid'] + for v in resp['access_control']['current_domain_permissions'] + ) assert resp['filters'] == { - 'asset': '{"and":[{"field":"ipv4","operator":"eq","value":"127.0.0.1"}]}'} + 'asset': '{"and":[{"field":"ipv4","operator":"eq","value":"127.0.0.1"}]}' + } assert resp['access_control']['version'] == 1 -@pytest.mark.vcr() -def test_tags_edit_category_uuid_typeerror(api): - ''' - test to raise exception when type of tag_category_uuid param does not match the expected type. - ''' - with pytest.raises(TypeError): - api.tags.edit_category(1) - - -@pytest.mark.vcr() -def test_tags_edit_category_uuid_unexpectedvalueerror(api): - ''' - test to raise exception when type of tag_category_uuid param does not match the expected type. - ''' - with pytest.raises(UnexpectedValueError): - api.tags.edit_category('1') - - @pytest.mark.vcr() def test_tags_edit_category_value_typeerror(api): - ''' + """ test to raise exception when type of value param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.edit_category(uuid.uuid4(), value=1) @pytest.mark.vcr() def test_tags_edit_category_description_typeerror(api): - ''' + """ test to raise exception when type of description param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.edit_category(uuid.uuid4(), description=1) @pytest.mark.vcr() def test_tags_edit_category_success(api, tagcat): - ''' + """ test to edit tag category information. - ''' + """ resp = api.tags.edit_category(tagcat['uuid'], name='Edited') assert isinstance(resp, dict) check(resp, 'uuid', 'uuid') @@ -807,80 +854,85 @@ def test_tags_edit_category_success(api, tagcat): check(resp, 'updated_at', 'datetime') check(resp, 'updated_by', str) check(resp, 'name', str) - # check(t, 'description', str, allow_none=True) check(resp, 'reserved', bool) assert resp['name'] == 'Edited' def test_tags_list_constructor_filter_type_typeerror(api): - ''' + """ test to raise exception when type of filter_type param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - getattr(api.tags, '_tag_list_constructor')([], - getattr(api.tags, '_filterset_tags'), True, None) + getattr(api.tags, '_tag_list_constructor')( + [], getattr(api.tags, '_filterset_tags'), True, None + ) def test_tags_list_constructor_filter_type_unexpectedvalueerror(api): - ''' + """ test to raise exception when filter_type param value does not match the choices. - ''' + """ with pytest.raises(UnexpectedValueError): - getattr(api.tags, '_tag_list_constructor')([], - getattr(api.tags, '_filterset_tags'), 'nadda', None) + getattr(api.tags, '_tag_list_constructor')( + [], getattr(api.tags, '_filterset_tags'), 'nadda', None + ) def test_tags_list_constructor_filter_type_success(api): - ''' + """ test to check filter_type param in tags_list_constructor method. - ''' - resp = getattr(api.tags, '_tag_list_constructor')([], - getattr(api.tags, '_filterset_tags'), 'and', None) + """ + resp = getattr(api.tags, '_tag_list_constructor')( + [], getattr(api.tags, '_filterset_tags'), 'and', None + ) assert resp['ft'] == 'AND' def test_tags_list_constructor_sort_typeerror(api): - ''' + """ test to raise exception when type of sort param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - getattr(api.tags, '_tag_list_constructor')([], - getattr(api.tags, '_filterset_tags'), None, 1) + getattr(api.tags, '_tag_list_constructor')( + [], getattr(api.tags, '_filterset_tags'), None, 1 + ) def test_tags_list_constructor_sort_unexpectedvalueerror(api): - ''' + """ test to raise exception when sort param value does not match the choices. - ''' + """ with pytest.raises(UnexpectedValueError): - getattr(api.tags, '_tag_list_constructor')([], - getattr(api.tags, '_filterset_tags'), None, (('something_else'),)) + getattr(api.tags, '_tag_list_constructor')( + [], getattr(api.tags, '_filterset_tags'), None, (('something_else'),) + ) def test_tags_list_constructor_sort_success(api): - ''' + """ test to check sort param in tags_list_constructor method. - ''' - resp = getattr(api.tags, '_tag_list_constructor')([], - getattr(api.tags, '_filterset_tags'), None, (('value', 'asc'),)) + """ + resp = getattr(api.tags, '_tag_list_constructor')( + [], getattr(api.tags, '_filterset_tags'), None, (('value', 'asc'),) + ) assert resp['sort'] == 'value:asc' def test_tags_list_constructor_filter_success(api): - ''' + """ test to check filter param in tags_list_constructor method. - ''' - resp = getattr(api.tags, '_tag_list_constructor')([ - ('value', 'eq', 'Test') - ], getattr(api.tags, '_filterset_tags'), None, None) + """ + resp = getattr(api.tags, '_tag_list_constructor')( + [('value', 'eq', 'Test')], getattr(api.tags, '_filterset_tags'), None, None + ) assert resp['f'] == ['value:eq:Test'] @pytest.mark.vcr() def test_tags_list_success(api): - ''' + """ test to get list of tags. - ''' + """ tags = api.tags.list() assert isinstance(tags, TagsIterator) resp = tags.next() @@ -899,9 +951,9 @@ def test_tags_list_success(api): @pytest.mark.vcr() def test_tags_list_category_success(api): - ''' + """ test to list of tag categories. - ''' + """ tags = api.tags.list_categories() assert isinstance(tags, TagsIterator) resp = tags.next() @@ -917,72 +969,87 @@ def test_tags_list_category_success(api): @pytest.mark.vcr() def test_tags_list_date_failure(api): - ''' + """ test to raise exception when value of filter tuple does not match the expected. - ''' + """ with pytest.raises(UnexpectedValueError): api.tags.list(('updated_at', 'eq', 'something_else')) @pytest.mark.vcr() def test_tags_assign_assets_typeerror_list(api): - ''' + """ test to raise exception when type of asset param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.assign(1, []) @pytest.mark.vcr() def test_tags_assign_assets_typeerror_entity(api): - ''' + """ test to raise exception when type of asset param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - api.tags.assign([1, ], []) + api.tags.assign( + [ + 1, + ], + [], + ) @pytest.mark.vcr() def test_tags_assign_assets_unexpectedvalueerror_entity(api): - ''' + """ test to raise exception when asset param value does not match the expected. - ''' + """ with pytest.raises(UnexpectedValueError): api.tags.assign(['something'], []) @pytest.mark.vcr() def test_tags_assign_tags_typeerror_list(api): - ''' + """ test to raise exception when type of tags param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.assign([], 1) @pytest.mark.vcr() def test_tags_assign_tags_typeerror_entity(api): - ''' + """ test to raise exception when type of tags param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - api.tags.assign([], [1, ]) + api.tags.assign( + [], + [ + 1, + ], + ) @pytest.mark.vcr() def test_tags_assign_tags_unexpectedvalueerror_entity(api): - ''' + """ test to raise exception when tags param value does not match the expected. - ''' + """ with pytest.raises(UnexpectedValueError): - api.tags.assign([], ['something', ]) + api.tags.assign( + [], + [ + 'something', + ], + ) @pytest.mark.vcr() def test_tags_assign_success(api, tagvalue): - ''' + """ test to assign tags to assets. - ''' + """ assets = api.assets.list() resp = api.tags.assign([a['id'] for a in assets], [tagvalue['uuid']]) single(resp, str) @@ -990,63 +1057,78 @@ def test_tags_assign_success(api, tagvalue): @pytest.mark.vcr() def test_tags_unassign_assets_typeerror_list(api): - ''' + """ test to raise exception when type of asstes param does not match the expected type. - ''' + """ with pytest.raises(TypeError): api.tags.unassign(1, []) @pytest.mark.vcr() def test_tags_unassign_assets_typeerror_entity(api): - ''' + """ test to raise exception when type of assets param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - api.tags.unassign([1, ], []) + api.tags.unassign( + [ + 1, + ], + [], + ) @pytest.mark.vcr() def test_tags_unassign_assets_unexpectedvalueerror_entity(api): - ''' + """ test to raise exception when assets param value does not match the expected. - ''' + """ with pytest.raises(UnexpectedValueError): api.tags.unassign(['something'], []) @pytest.mark.vcr() def test_tags_unassign_tags_typeerror_list(api): - ''' + """ test to unassign tags from assets. - ''' + """ with pytest.raises(TypeError): api.tags.unassign([], 1) @pytest.mark.vcr() def test_tags_unassign_tags_typeerror_entity(api): - ''' + """ test to raise exception when type of tags param does not match the expected type. - ''' + """ with pytest.raises(TypeError): - api.tags.unassign([], [1, ]) + api.tags.unassign( + [], + [ + 1, + ], + ) @pytest.mark.vcr() def test_tags_unassign_tags_unexpectedvalueerror_entity(api): - ''' + """ test to raise exception when type of tags param does not match the expected type. - ''' + """ with pytest.raises(UnexpectedValueError): - api.tags.unassign([], ['something', ]) + api.tags.unassign( + [], + [ + 'something', + ], + ) @pytest.mark.vcr() def test_tags_unassign_success(api, tagvalue): - ''' + """ test to raise exception when tags param value does not match the expected. - ''' + """ assets = api.assets.list() resp = api.tags.unassign([a['id'] for a in assets], [tagvalue['uuid']]) single(resp, str) @@ -1054,9 +1136,9 @@ def test_tags_unassign_success(api, tagvalue): @pytest.mark.vcr() def test_tags_edit_without_filters(api): - ''' + """ test to apply filters that are available in current payload when filter parameter is not passed. - ''' + """ tags = api.tags.list() flag = True @@ -1074,7 +1156,7 @@ def test_tags_edit_without_filters(api): def tag_exists(api, tag_uuid): - '''function to check whether the tag value exists or not ''' + """function to check whether the tag value exists or not""" if tag_uuid in api.tags.list(): return True else: @@ -1087,4 +1169,4 @@ def test_get_tag_uuid(api): Test to fetch uuid from tag category and value """ tag_uuid = api.tags.get_tag_uuid('test tag', 'acr') - assert tag_uuid == "de2e56a2-6a0e-4757-8d00-e9ad635f6231" + assert tag_uuid == 'de2e56a2-6a0e-4757-8d00-e9ad635f6231'