diff --git a/keystone_client/client.py b/keystone_client/client.py index 6cbdf66..84802e3 100644 --- a/keystone_client/client.py +++ b/keystone_client/client.py @@ -9,18 +9,16 @@ import httpx from httpx import HTTPStatusError + from keystone_client.http import AsyncHTTPClient, HTTPClient -from keystone_client.schema import Endpoint, Schema class ClientBase(abc.ABC): """Base client class with shared application constants and helpers.""" - schema = Schema() - - LOGIN_ENDPOINT = Endpoint('authentication/login') - LOGOUT_ENDPOINT = Endpoint('authentication/logout') - IDENTITY_ENDPOINT = Endpoint('authentication/whoami') + LOGIN_ENDPOINT = 'authentication/login' + LOGOUT_ENDPOINT = 'authentication/logout' + IDENTITY_ENDPOINT = 'authentication/whoami' @abc.abstractmethod def login(self, username: str, password: str, timeout: int) -> None: diff --git a/keystone_client/schema.py b/keystone_client/schema.py deleted file mode 100644 index 6c7f0bc..0000000 --- a/keystone_client/schema.py +++ /dev/null @@ -1,40 +0,0 @@ -"""Schema objects used to define available API endpoints.""" - -from dataclasses import dataclass -from os import path - - -class Endpoint(str): - """API endpoint agnostic to the baseAPI URL.""" - - def join_url(self, base: str, *append) -> str: - """Join the endpoint with a base URL. - - This method returns URLs in a format that avoids trailing slash - redirects from the Keystone API. - - Args: - base: The base URL. - *append: Partial paths to append onto the url. - - Returns: - The base URL join with the endpoint. - """ - - url = path.join(base, self) - for partial_path in filter(lambda x: x is not None, append): - url = path.join(url, str(partial_path)) - - return url.rstrip('/') + '/' - - -@dataclass -class Schema: - """Schema defining the complete set of API endpoints.""" - - allocations: Endpoint = Endpoint("allocations/allocations") - clusters: Endpoint = Endpoint("allocations/clusters") - requests: Endpoint = Endpoint("allocations/requests") - teams: Endpoint = Endpoint("users/teams") - memberships: Endpoint = Endpoint("users/memberships") - users: Endpoint = Endpoint("users/users") diff --git a/tests/unit_tests/test_schema/__init__.py b/tests/unit_tests/test_schema/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/unit_tests/test_schema/test_Endpoint.py b/tests/unit_tests/test_schema/test_Endpoint.py deleted file mode 100644 index 62c4290..0000000 --- a/tests/unit_tests/test_schema/test_Endpoint.py +++ /dev/null @@ -1,87 +0,0 @@ -"""Test the formatting of API endpoints and URLs.""" - -from unittest import TestCase - -from keystone_client.schema import Endpoint - - -class JoinUrlMethod(TestCase): - """Test the joining of URL parts via the `join_url` method.""" - - def test_with_trailing_slash(self) -> None: - """Verify a base URL with a trailing slash is joined correctly.""" - - endpoint = Endpoint("authentication/new") - base_url = "https://api.example.com/" - expected_result = "https://api.example.com/authentication/new/" - self.assertEqual(expected_result, endpoint.join_url(base_url)) - - def test_without_trailing_slash(self) -> None: - """Verify a base URL with a trailing slash is joined correctly.""" - - endpoint = Endpoint("authentication/new") - base_url = "https://api.example.com" - expected_result = "https://api.example.com/authentication/new/" - self.assertEqual(expected_result, endpoint.join_url(base_url)) - - def test_with_endpoint_trailing_slash(self) -> None: - """Verify an endpoint with a trailing slash is joined correctly.""" - - endpoint = Endpoint("authentication/new/") - base_url = "https://api.example.com" - expected_result = "https://api.example.com/authentication/new/" - self.assertEqual(expected_result, endpoint.join_url(base_url)) - - def test_without_endpoint_trailing_slash(self) -> None: - """Verify an endpoint without a trailing slash is joined correctly.""" - - endpoint = Endpoint("authentication/new") - base_url = "https://api.example.com" - expected_result = "https://api.example.com/authentication/new/" - self.assertEqual(expected_result, endpoint.join_url(base_url)) - - def test_with_append_trailing_slash(self) -> None: - """Verify an append path with a trailing slash is joined correctly.""" - - endpoint = Endpoint("authentication") - base_url = "https://api.example.com" - append_path = "new/" - expected_result = "https://api.example.com/authentication/new/" - self.assertEqual(expected_result, endpoint.join_url(base_url, append_path)) - - def test_without_append_trailing_slash(self) -> None: - """Verify an append path without a trailing slash is joined correctly.""" - - endpoint = Endpoint("authentication") - base_url = "https://api.example.com" - append_path = "new" - expected_result = "https://api.example.com/authentication/new/" - self.assertEqual(expected_result, endpoint.join_url(base_url, append_path)) - - def test_with_mixed_trailing_slash_in_append(self) -> None: - """Verify mixed trailing slashes in append paths are handled correctly.""" - - endpoint = Endpoint("authentication") - base_url = "https://api.example.com" - append_path1 = "new/" - append_path2 = "extra" - expected_result = "https://api.example.com/authentication/new/extra/" - self.assertEqual(expected_result, endpoint.join_url(base_url, append_path1, append_path2)) - - def test_int_append_argument(self) -> None: - """Verify an integer append argument is joined correctly.""" - - endpoint = Endpoint("authentication") - base_url = "https://api.example.com" - append_path = 123 - expected_result = "https://api.example.com/authentication/123/" - self.assertEqual(expected_result, endpoint.join_url(base_url, str(append_path))) - - def test_none_append_argument(self) -> None: - """Verify a `None` append argument is ignored in joining.""" - - endpoint = Endpoint("authentication") - base_url = "https://api.example.com" - append_path = None - expected_result = "https://api.example.com/authentication/" - self.assertEqual(expected_result, endpoint.join_url(base_url, append_path))