Skip to content

Commit 42fcb18

Browse files
Updated tests
1 parent 4cd1a22 commit 42fcb18

File tree

11 files changed

+111
-2
lines changed

11 files changed

+111
-2
lines changed

end_to_end_tests/golden-record/my_test_api_client/client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import httpx
55
from attrs import define, evolve, field
6+
import urllib.parse
67

78

89
@define
@@ -266,3 +267,25 @@ async def __aenter__(self) -> "AuthenticatedClient":
266267
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
267268
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
268269
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
270+
271+
def replace_client_path(client: Client, base_path: str) -> Client:
272+
"""Override a client's base URL with a new path. Does not update scheme, host, or other URL parts."""
273+
parsed = urllib.parse.urlparse(client.base_url)
274+
# _replace is not private, it's part of the NamedTuple API but prefixed _ to avoid conflicts
275+
updated_url = parsed._replace(path=base_path)
276+
return client.with_base_url(updated_url.geturl())
277+
278+
279+
def v3_stable_client(client: Client) -> Client:
280+
"""Override a client's base URL with a v2 stable path."""
281+
return replace_client_path(client, "api/v3-draft")
282+
283+
284+
def v3_alpha_client(client: Client) -> Client:
285+
"""Override a client's base URL with a v2-alpha path."""
286+
return replace_client_path(client, "api/v3-alpha")
287+
288+
289+
def v3_beta_client(client: Client) -> Client:
290+
"""Override a client's base URL with a v2-beta path."""
291+
return replace_client_path(client, "api/v3-beta")

end_to_end_tests/literal-enums-golden-record/my_enum_api_client/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import httpx
55
from attrs import define, evolve, field
6+
import urllib.parse
67

78

89
@define
@@ -266,3 +267,10 @@ async def __aenter__(self) -> "AuthenticatedClient":
266267
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
267268
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
268269
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
270+
271+
272+
def replace_client_path(client: Client, base_path: str) -> Client:
273+
"""Override a client's base URL with a new path. Does not update scheme, host, or other URL parts."""
274+
parsed = urllib.parse.urlparse(client.base_url)
275+
# _replace is not private, it's part of the NamedTuple API but prefixed _ to avoid conflicts
276+
updated_url = parsed._replace(path=base_path)

end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/client.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import httpx
55
from attrs import define, evolve, field
6-
6+
import urllib.parse
77

88
@define
99
class Client:
@@ -266,3 +266,25 @@ async def __aenter__(self) -> "AuthenticatedClient":
266266
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
267267
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
268268
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
269+
270+
def replace_client_path(client: Client, base_path: str) -> Client:
271+
"""Override a client's base URL with a new path. Does not update scheme, host, or other URL parts."""
272+
parsed = urllib.parse.urlparse(client.base_url)
273+
# _replace is not private, it's part of the NamedTuple API but prefixed _ to avoid conflicts
274+
updated_url = parsed._replace(path=base_path)
275+
return client.with_base_url(updated_url.geturl())
276+
277+
278+
def v3_stable_client(client: Client) -> Client:
279+
"""Override a client's base URL with a v2 stable path."""
280+
return replace_client_path(client, "api/v3-draft")
281+
282+
283+
def v3_alpha_client(client: Client) -> Client:
284+
"""Override a client's base URL with a v2-alpha path."""
285+
return replace_client_path(client, "api/v3-alpha")
286+
287+
288+
def v3_beta_client(client: Client) -> Client:
289+
"""Override a client's base URL with a v2-beta path."""
290+
return replace_client_path(client, "api/v3-beta")

integration-tests/integration_tests/client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ssl
2+
import urllib.parse
23
from typing import Any, Optional, Union
34

45
import httpx
@@ -266,3 +267,26 @@ async def __aenter__(self) -> "AuthenticatedClient":
266267
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
267268
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
268269
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
270+
271+
272+
def replace_client_path(client: Client, base_path: str) -> Client:
273+
"""Override a client's base URL with a new path. Does not update scheme, host, or other URL parts."""
274+
parsed = urllib.parse.urlparse(client.base_url)
275+
# _replace is not private, it's part of the NamedTuple API but prefixed _ to avoid conflicts
276+
updated_url = parsed._replace(path=base_path)
277+
return client.with_base_url(updated_url.geturl())
278+
279+
280+
def v3_stable_client(client: Client) -> Client:
281+
"""Override a client's base URL with a v2 stable path."""
282+
return replace_client_path(client, "api/v3-draft")
283+
284+
285+
def v3_alpha_client(client: Client) -> Client:
286+
"""Override a client's base URL with a v2-alpha path."""
287+
return replace_client_path(client, "api/v3-alpha")
288+
289+
290+
def v3_beta_client(client: Client) -> Client:
291+
"""Override a client's base URL with a v2-beta path."""
292+
return replace_client_path(client, "api/v3-beta")

openapi_python_client/templates/client.py.jinja

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,3 @@ def v3_alpha_client(client: Client) -> Client:
212212
def v3_beta_client(client: Client) -> Client:
213213
"""Override a client's base URL with a v2-beta path."""
214214
return replace_client_path(client, "api/v3-beta")
215-
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class_overrides:
2+
Class1: {class_name: ExampleClass, module_name: example_module}
3+
Class2: {class_name: DifferentClass, module_name: different_module}
4+
field_prefix: blah
5+
package_name_override: package_name
6+
package_version_override: package_version
7+
project_name_override: project-name
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"field_prefix": "blah", "class_overrides": {"Class1": {"class_name": "ExampleClass", "module_name": "example_module"}, "Class2": {"class_name": "DifferentClass", "module_name": "different_module"}}, "project_name_override": "project-name", "package_name_override": "package_name", "package_version_override": "package_version"}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class_overrides:
2+
Class1: {class_name: ExampleClass, module_name: example_module}
3+
Class2: {class_name: DifferentClass, module_name: different_module}
4+
field_prefix: blah
5+
package_name_override: package_name
6+
package_version_override: package_version
7+
project_name_override: project-name
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"field_prefix": "blah",
3+
"class_overrides": {
4+
"Class1": {
5+
"class_name": "ExampleClass",
6+
"module_name": "example_module"
7+
},
8+
"Class2": {
9+
"class_name": "DifferentClass",
10+
"module_name": "different_module"
11+
}
12+
},
13+
"project_name_override": "project-name",
14+
"package_name_override": "package_name",
15+
"package_version_override": "package_version"
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Users/tara.natarajan/openapi-python-client/tests/tmp/test_load_from_path_absolute_e3

0 commit comments

Comments
 (0)