"""Test for handler util.""" from unittest.mock import MagicMock from owsresponse import response from account.constants import error from account.models import subaccount as subaccount_model from account.utils import handler_util def test_check_subaccount_ownership( monkeypatch, fixture_subaccount, fixture_subaccount_id, fixture_account_id, fixture_account_type, ): """Test subaccount is owned by given vendor.""" monkeypatch.setattr( subaccount_model, 'get_subaccount_by_vendor_id', MagicMock(return_value=fixture_subaccount), ) result = handler_util.check_subaccount_ownership( fixture_subaccount_id, fixture_account_type, fixture_account_id ) assert result.status == 200 def test_check_subaccount_ownership_failure( monkeypatch, fixture_subaccount_id, fixture_account_type ): """Test subaccount is owned by given vendor.""" account_id = 123 monkeypatch.setattr( subaccount_model, 'get_subaccount_by_vendor_id', MagicMock(return_value=response.create_not_found_response()), ) result = handler_util.check_subaccount_ownership( fixture_subaccount_id, fixture_account_type, account_id ) assert result.status == 403 assert result.errors['code'] == error.ERROR_CODE_AUTHORIZATION