async def test_set_owner( self, sequoia_client, response_registry_list_services, response_registry_get_description, response_identity_get_description, response_metadata_get_description, ): responses = [ # Get services and description of them after setting owner response_registry_list_services, response_identity_get_description, response_metadata_get_description, response_registry_get_description, ] with patch.object(httpx.AsyncClient, "request", new_callable=AsyncMock, side_effect=responses): assert sequoia_client._token is None assert sequoia_client._owner is None assert sequoia_client._services == ServicesRegistry() await sequoia_client.set_owner("root") assert sequoia_client._token is None assert sequoia_client._owner == "root" assert sequoia_client._services == ServicesRegistry({ "identity": Service( name="identity", url="https://identity.sequoia.piksel.com", title="Identity and Access Service", description= "Responsible for identity and access management", ), "metadata": Service( name="metadata", url="https://metadata.sequoia.piksel.com", title="Metadata Service", description="Stores content metadata resources", ), "registry": Service( name="registry", url="https://registry.sequoia.piksel.com", title="Registry Service", description="Responsible for managing the service registry", ), })
async def test_aenter(self, sequoia_client, response_registry_list_services, response_identity_get_oauth_token): responses = [ # Services discovery response_registry_list_services, # Auth token response_identity_get_oauth_token, ] with patch.object(httpx.AsyncClient, "request", new_callable=AsyncMock, side_effect=responses): async with sequoia_client as client: assert client._token == "74b685d3ba5943662884cf786e4ca8d6ff71cc09" assert client._owner is None assert client._services == ServicesRegistry( { "identity": Service( name="identity", url="https://identity.sequoia.piksel.com", title="Identity and Access Service", description="Responsible for identity and access management", ), "metadata": Service( name="metadata", url="https://metadata.sequoia.piksel.com", title="Metadata Service", description="Stores content metadata resources", ), "registry": Service( name="registry", url="https://registry.sequoia.piksel.com", title="Registry Service", description="Responsible for managing the service registry", ), } )
def __init__( self, client_id: str, client_secret: str, registry_url: str, owner: typing.Optional[str] = None, httpx_client: typing.Optional[httpx.AsyncClient] = None, ) -> None: """ Client to interact with Sequoia services. :param client_id: Sequoia client ID. :param client_secret: Sequoia client secret. :param registry_url: URL for Registry service. :param owner: Owner. :param httpx_client: Httpx client, a mechanism to reuse an already created client. """ self._registry_url = registry_url self._client_id = client_id self._client_secret = client_secret self._httpx_client = httpx_client if httpx_client is not None else httpx.AsyncClient( verify=False) self._token: typing.Optional[str] = None self._owner = owner self._services: ServicesRegistry = ServicesRegistry()
def __init__( self, client_id: str, client_secret: str, registry_url: str, owner: typing.Optional[str] = None, httpx_client: typing.Optional[httpx.AsyncClient] = None, max_retries: int = DEFAULT_MAX_RETRIES, ) -> None: """ Client to interact with Sequoia services. :param client_id: Sequoia client ID. :param client_secret: Sequoia client secret. :param registry_url: URL for Registry service. :param owner: Owner. :param httpx_client: Httpx client, a mechanism to reuse an already created client. :param max_retries: Max num of attempts to connect to a sequoia service after receiving an error """ self._registry_url = registry_url self._client_id = client_id self._client_secret = client_secret self._httpx_client = httpx_client if httpx_client is not None else httpx.AsyncClient(verify=False) self._owner = owner self._token: typing.Optional[str] = None self._services: ServicesRegistry = ServicesRegistry() self._max_retries = max_retries
async def test_aexit(self, sequoia_client, response_registry_list_services, response_identity_get_oauth_token): responses = [ # Services discovery response_registry_list_services, # Auth token response_identity_get_oauth_token, ] with patch.object(httpx.AsyncClient, "request", new_callable=AsyncMock, side_effect=responses): async with sequoia_client as client: pass assert client._token is None assert client._owner is None assert client._services == ServicesRegistry()
def services_registry(service): return ServicesRegistry({"foo": service})