import httpx import pytest from owsclient import OwsClient from owsclient.test import OwsClientMock from fansifter_common.adapters.ows_account import ( Feature, OwsAccountClient, Subaccount, Vendor, VendorLookup, ) class TestOwsAccountClient: @pytest.fixture def ows_account_client(self, ows_client: OwsClient) -> OwsAccountClient: return OwsAccountClient(ows_client=ows_client) def test_lookup_vendors_by_uuids( self, ows_account_client: OwsAccountClient, ows_client_mock: OwsClientMock ) -> None: vendor_id_1 = 1 vendor_id_2 = 2 vendor_uuid_1 = "uuid1" vendor_uuid_2 = "uuid2" missing_vendor_uuid = "missing_vendor_uuid" ows_client_mock.post( service_name="ows-account", path="/lookup/vendors/uuids/", json={ "uuids": [vendor_uuid_1, missing_vendor_uuid, vendor_uuid_2], }, ).mock( httpx.Response( status_code=200, json={ "vendors": [ {"vendor_id": vendor_id_1, "uuid": vendor_uuid_1}, None, {"vendor_id": vendor_id_2, "uuid": vendor_uuid_2}, ] }, ) ) vendors = ows_account_client.lookup_vendors_by_uuids( [ vendor_uuid_1, missing_vendor_uuid, vendor_uuid_2, ], ) assert vendors == [ VendorLookup(vendor_id=vendor_id_1, uuid=vendor_uuid_1), VendorLookup(vendor_id=vendor_id_2, uuid=vendor_uuid_2), ] def test_get_vendor( self, ows_account_client: OwsAccountClient, ows_client_mock: OwsClientMock ) -> None: vendor_id = 1 name = "vendor_name" brand = "vendor_brand" ows_client_mock.get( service_name="ows-account", path=f"/vendor/{vendor_id}", ).mock( httpx.Response( status_code=200, json={ "vendor_id": vendor_id, "account_name": name, "company_brand": brand, }, ) ) vendor = ows_account_client.get_vendor(vendor_id) assert vendor == Vendor( vendor_id=vendor_id, account_name=name, company_brand=brand ) def test_get_subaccount( self, ows_account_client: OwsAccountClient, ows_client_mock: OwsClientMock ) -> None: vendor_id = 1 subaccount_id = 2 name = "subaccount_name" ows_client_mock.get( service_name="ows-account", path=f"/subaccount/{subaccount_id}", ).mock( httpx.Response( status_code=200, json={ "vendor_id": vendor_id, "subaccount_id": subaccount_id, "subaccount_name": name, }, ) ) subaccount = ows_account_client.get_subaccount(subaccount_id) assert subaccount == Subaccount( vendor_id=vendor_id, subaccount_id=subaccount_id, subaccount_name=name ) def test_get_vendor_features( self, ows_account_client: OwsAccountClient, ows_client_mock: OwsClientMock ) -> None: vendor_id = 1 ows_client_mock.get( service_name="ows-account", path=f"/vendor/{vendor_id}/features", ).mock( httpx.Response( status_code=200, json={ "items": [ { "feature_id": 1, "feature_name": "feature_name_1", }, { "feature_id": 2, "feature_name": "feature_name_2", }, ] }, ) ) features = ows_account_client.get_vendor_features(vendor_id) assert features == [ Feature(feature_id=1, feature_name="feature_name_1"), Feature(feature_id=2, feature_name="feature_name_2"), ]