"""Test AccountByUuidResourceGetter.""" from unittest.mock import MagicMock, patch import pytest from owsresponse import response from account.constants import constants from account.logic.resource_getters.account import AccountDistributorByUuidResourceGetter @pytest.fixture() def some_uuid() -> str: return '6c965e79-a0a1-4d8f-a2db-21f19c4191d9' @pytest.fixture() def resource_getter(some_uuid: str) -> AccountDistributorByUuidResourceGetter: return AccountDistributorByUuidResourceGetter(some_uuid) @pytest.mark.parametrize( 'is_distributor', [True, False], ) @patch('account.logic.resource_getters.account.lookup_vendors_by_uuids') def test_happy_path( mock_lookup: MagicMock, some_uuid: str, resource_getter: AccountDistributorByUuidResourceGetter, is_distributor: bool, ) -> None: """Test get_attributes happy path for different is_distributor values.""" mock_lookup.return_value = response.Response( { 'vendors': [ { 'id': 123, 'company_brand_uuid': '955a1bbd-b623-4ea1-ab5f-8d6620c442fb', 'parent_company_uuid': 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'uuid': some_uuid, 'is_distributor': is_distributor, }, ] } ) actual = resource_getter.get_attributes() mock_lookup.assert_called_once_with( [some_uuid], fetch_flags=[constants.FETCH_TENANT_HIERARCHY, constants.FETCH_IS_DISTRIBUTOR] ) assert actual == { 'tenant': { 'tenant_uuid': some_uuid, 'tenant_type': 'account', 'tenant_hierarchy': [ '955a1bbd-b623-4ea1-ab5f-8d6620c442fb', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', ], }, 'name': some_uuid, 'is_distributor': is_distributor, } @pytest.mark.parametrize( 'mock_empty_response', [ pytest.param(None, id='None means there is no vendor data.'), pytest.param( response.create_not_found_response(), id='empty message means there is no vendor data', ), pytest.param( response.Response([]), id='empty list message means there is no vendor data', ), pytest.param( response.Response({'vendors': []}), id='empty list message in vendor object means there is no vendor data.', ), ], ) @patch('account.logic.resource_getters.account.lookup_vendors_by_uuids') def test_empty_attributes_returned( mock_lookup: MagicMock, mock_empty_response: response.Response | None, some_uuid: str, resource_getter: AccountDistributorByUuidResourceGetter, ) -> None: """Test get_attributes returns empty for bad lookups.""" mock_lookup.return_value = mock_empty_response actual = resource_getter.get_attributes() mock_lookup.assert_called_once_with( [some_uuid], fetch_flags=[constants.FETCH_TENANT_HIERARCHY, constants.FETCH_IS_DISTRIBUTOR] ) assert actual == {}