Skip to content

Commit d27667b

Browse files
Merge pull request #537 from timhoffm/master
Support completion of operation names for ServiceProxy
2 parents 7f2ed90 + 08898b3 commit d27667b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/zeep/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class OperationProxy(object):
1313
def __init__(self, service_proxy, operation_name):
1414
self._proxy = service_proxy
1515
self._op_name = operation_name
16+
try:
17+
signature = str(self._proxy._binding._operations[operation_name])
18+
self.__doc__ = signature
19+
except:
20+
self.__doc__ = 'OperationProxy for %s' % operation_name
1621

1722
def __call__(self, *args, **kwargs):
1823
"""Call the operation with the given args and kwargs.
@@ -66,6 +71,13 @@ def __getitem__(self, key):
6671
except ValueError:
6772
raise AttributeError('Service has no operation %r' % key)
6873
return OperationProxy(self, key)
74+
75+
def __dir__(self):
76+
""" Return the names of the operations. """
77+
return list(dir(super(ServiceProxy, self))
78+
+ list(self.__dict__)
79+
+ list(self._binding.port_type.operations))
80+
# using list() on the dicts for Python 3 compatibility
6981

7082

7183
class Factory(object):

tests/test_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ def test_service_proxy_non_existing():
4343
assert client_obj.service.NonExisting
4444

4545

46+
def test_service_proxy_dir_operations():
47+
client_obj = client.Client('tests/wsdl_files/soap.wsdl')
48+
operations = [op for op in dir(client_obj.service) if not op.startswith('_')]
49+
assert set(operations) == set(['GetLastTradePrice', 'GetLastTradePriceNoOutput'])
50+
51+
52+
def test_operation_proxy_doc():
53+
client_obj = client.Client('tests/wsdl_files/soap.wsdl')
54+
assert (client_obj.service.GetLastTradePrice.__doc__
55+
== 'GetLastTradePrice(tickerSymbol: xsd:string, '
56+
'account: ns0:account, '
57+
'country: ns0:country) -> price: xsd:float')
58+
59+
4660
def test_open_from_file_object():
4761
with open('tests/wsdl_files/soap_transport_err.wsdl', 'rb') as fh:
4862
client_obj = client.Client(fh)

0 commit comments

Comments
 (0)