Skip to content

Commit

Permalink
NEW: support Url in ByBindingName.address
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed Nov 14, 2024
1 parent 011d44c commit 73b95d8
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 121 deletions.
2 changes: 1 addition & 1 deletion combadge/support/zeep/backends/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def with_params(
service_proxy = AsyncServiceProxy(
client,
client.wsdl.bindings[service.binding_name],
address=service.address,
address=service.address_string,
)
else:
raise TypeError(type(service))
Expand Down
29 changes: 22 additions & 7 deletions combadge/support/zeep/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from dataclasses import dataclass
from typing import Any, Generic, TypeVar, Union

from pydantic_core import Url

from combadge._helpers.dataclasses import SLOTS
from combadge.core.errors import BackendError

Expand All @@ -13,7 +15,7 @@
# Before Python 3.10:
UnionType = type(Union[int, str]) # type: ignore[assignment, misc]

from pydantic import TypeAdapter
from pydantic import HttpUrl, TypeAdapter
from typing_extensions import get_args as get_type_args
from typing_extensions import get_origin as get_type_origin
from zeep.exceptions import Fault
Expand Down Expand Up @@ -104,10 +106,26 @@ def _parse_soap_fault(exception: Fault, fault_type: TypeAdapter[_SoapFaultT]) ->

@dataclass(**SLOTS)
class ByBindingName:
"""Create service by binding name and address."""
"""
Create service by binding name and address.
Examples:
>>> ByBindingName(
>>> binding_name="{http://www.dataaccess.com/webservicesserver/}NumberConversionSoapBinding",
>>> address=Url("https://www.dataaccess.com/webservicesserver/NumberConversion.wso",
>>> )
)
"""

binding_name: str
address: str
address: HttpUrl | str

@property
def address_string(self) -> str:
"""Return the service address as a plain `#!python str`."""
if isinstance(self.address, Url):
return str(self.address)
return self.address

Check warning on line 128 in combadge/support/zeep/backends/base.py

View check run for this annotation

Codecov / codecov/patch

combadge/support/zeep/backends/base.py#L128

Added line #L128 was not covered by tests


@dataclass(**SLOTS)
Expand All @@ -116,10 +134,7 @@ class ByServiceName:
Create service by service and port names.
Examples:
>>> backend = SyncZeepBackend.with_params(
>>> "NumberConversion.wsdl",
>>> service=ByServiceName(port_name="NumberConversionSoap"),
>>> )
>>> ByServiceName(port_name="NumberConversionSoap")
"""

service_name: str | None = None
Expand Down
2 changes: 1 addition & 1 deletion combadge/support/zeep/backends/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def with_params(
elif isinstance(service, ByServiceName):
service_proxy = client.bind(service.service_name, service.port_name)
elif isinstance(service, ByBindingName):
service_proxy = client.create_service(service.binding_name, service.address)
service_proxy = client.create_service(service.binding_name, service.address_string)
else:
raise TypeError(type(service))
return cls(service_proxy)
Expand Down

This file was deleted.

This file was deleted.

35 changes: 30 additions & 5 deletions tests/integration/test_number_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest
from pydantic import BaseModel, Field, RootModel
from pydantic_core import Url
from typing_extensions import assert_type
from zeep import AsyncClient, Client

Expand All @@ -14,7 +15,7 @@
from combadge.support.soap.markers import operation_name
from combadge.support.soap.response import BaseSoapFault
from combadge.support.zeep.backends.async_ import ZeepBackend as AsyncZeepBackend
from combadge.support.zeep.backends.base import ByServiceName
from combadge.support.zeep.backends.base import ByBindingName, ByServiceName
from combadge.support.zeep.backends.sync import ZeepBackend as SyncZeepBackend


Expand Down Expand Up @@ -108,10 +109,22 @@ async def test_happy_path_scalar_response_async(number_conversion_service_async:


@pytest.mark.vcr
def test_happy_path_with_params() -> None:
@pytest.mark.parametrize(
"service",
[
ByServiceName(port_name="NumberConversionSoap"),
ByBindingName(
binding_name="{http://www.dataaccess.com/webservicesserver/}NumberConversionSoapBinding",
address=Url(
"https://www.dataaccess.com/webservicesserver/NumberConversion.wso",
),
),
],
)
def test_happy_path_with_params_sync(service: ByServiceName | ByBindingName) -> None:
backend = SyncZeepBackend.with_params(
Path(__file__).parent / "wsdl" / "NumberConversion.wsdl",
service=ByServiceName(port_name="NumberConversionSoap"),
service=service,
operation_timeout=1,
)
service = SupportsNumberConversion.bind(backend)
Expand All @@ -120,10 +133,22 @@ def test_happy_path_with_params() -> None:


@pytest.mark.vcr
async def test_happy_path_with_params_async() -> None:
@pytest.mark.parametrize(
"service",
[
ByServiceName(port_name="NumberConversionSoap"),
ByBindingName(
binding_name="{http://www.dataaccess.com/webservicesserver/}NumberConversionSoapBinding",
address=Url(
"https://www.dataaccess.com/webservicesserver/NumberConversion.wso",
),
),
],
)
async def test_happy_path_with_params_async(service: ByServiceName | ByBindingName) -> None:
backend = AsyncZeepBackend.with_params(
Path(__file__).parent / "wsdl" / "NumberConversion.wsdl",
service=ByServiceName(port_name="NumberConversionSoap"),
service=service,
operation_timeout=1,
)
service = SupportsNumberConversionAsync.bind(backend)
Expand Down

0 comments on commit 73b95d8

Please sign in to comment.