"""Test resource utils file.""" from unittest.mock import patch import pytest from permissions.utils.resource_utils import transform_resource_entity @pytest.mark.parametrize( ('resource', 'expected'), [ ( {'some_attribute': 'some_value', 'type': 'Subaccount', 'id': 100, 'uuid': 'uuid'}, {'type': 'Subaccount', 'id': 100, 'uuid': 'uuid'}, ), ( {'some_attribute': 'some_value', 'type': 'SubAccount', 'id': 100, 'uuid': 'uuid'}, {'type': 'Subaccount', 'id': 100, 'uuid': 'uuid'}, ), ( { 'some_attribute': 'some_value', 'type': 'Vendor', 'vendorId': 100, 'id': 200, 'uuid': 'uuid', }, {'type': 'Vendor', 'id': 100, 'uuid': 'uuid'}, ), ( {'some_attribute': 'some_value', 'type': 'CompanyBrand', 'id': 100, 'uuid': 'uuid'}, {'type': 'CompanyBrand', 'id': 'uuid', 'uuid': 'uuid'}, ), ], ) def test_transform_resource_entity(resource, expected): """Test transform_resource_entity with valid resource.""" actual = transform_resource_entity(resource) assert actual == expected @pytest.mark.parametrize( ('resource', 'expected'), [ ({'type': 'ArtistInfo', 'id': 100, 'uuid': 'uuid'}, None), ({'type': 'NotValidResourceType', 'id': 100, 'uuid': 'uuid'}, None), ], ) @patch('permissions.utils.resource_utils.g') def test_transform_resource_entity_bad_input(mock_g, app_context, resource, expected): """Test transform_resource_entity with invalid resource.""" actual = transform_resource_entity(resource) mock_g.log.debug.assert_called_with('Resource type not supported: {}'.format(resource['type'])) assert actual == expected