"""Tests for OWSAccount.""" from unittest.mock import MagicMock from owsrequest import request from contracts.models import ows_account def test_get_vendor_by_subaccount_success(monkeypatch): """Test get vendor id by subaccount id successful.""" mock_response = MagicMock() subaccount_id = 2 mock_response.json.return_value = {'vendor_id': 1} mock_response.status_code = 200 monkeypatch.setattr(request, 'get', MagicMock(return_value=mock_response)) response = ows_account.get_vendor_id_by_subaccount_id(subaccount_id) request.get.assert_called_with( ows_account.ACCOUNT_SERVICE, ows_account.ACCOUNT_OWNERSHIP_RESOURCE.format(subaccount_id=subaccount_id), ) assert response.message == 1 def test_get_vendor_by_subaccount_fail(monkeypatch): """Test get vendor id by subaccount id fail.""" mock_response = MagicMock() subaccount_id = 2 mock_response.status_code = 404 monkeypatch.setattr(request, 'get', MagicMock(return_value=mock_response)) response = ows_account.get_vendor_id_by_subaccount_id(subaccount_id) request.get.assert_called_with( ows_account.ACCOUNT_SERVICE, ows_account.ACCOUNT_OWNERSHIP_RESOURCE.format(subaccount_id=subaccount_id), ) assert response.status == 404 def test_get_vendor_uuid_by_vendor_id(monkeypatch): """Test get vendor uuid by vendor id successful.""" vendor_id = 1234 mock_response = MagicMock() mock_response.status_code = 200 mock_response.json.return_value = { 'vendors': [{'vendor_id': vendor_id, 'uuid': 'abc-123-uuid'}] } monkeypatch.setattr(request, 'post', MagicMock(return_value=mock_response)) response_obj = ows_account.get_vendor_uuid_by_vendor_id(vendor_id) request.post.assert_called_with( ows_account.ACCOUNT_SERVICE, ows_account.ACCOUNT_VENDOR_UUID_RESOURCE, json={'vendor_ids': [vendor_id]}, ) assert response_obj == {'vendor_id': vendor_id, 'vendor_uuid': 'abc-123-uuid'} def test_get_vendor_uuid_by_vendor_id_not_found(monkeypatch): """Test vendor not found case in get_vendor_uuid_by_vendor_id.""" vendor_id = 9999 mock_post_response = MagicMock() mock_post_response.status_code = 200 mock_post_response.json.return_value = {'vendors': [{}]} monkeypatch.setattr(request, 'post', MagicMock(return_value=mock_post_response)) result = ows_account.get_vendor_uuid_by_vendor_id(vendor_id) assert result is None