Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let ZipkinResourceDecorator proxy callables #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions swagger_zipkin/zipkin_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def __init__(self, resource):
def __getattr__(self, name):
return decorate_client(self.resource, self.with_headers, name)

def __call__(self, *args, **kwargs):
return self.resource(*args, **kwargs)

def with_headers(self, call_name, *args, **kwargs):
kwargs.setdefault('_request_options', {})
headers = kwargs['_request_options'].setdefault('headers', {})
Expand Down
32 changes: 23 additions & 9 deletions tests/zipkin_decorator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ def create_request_options(trace_id, span_id, parent_span_id):
}


def create_client():
class V1Operation():
def foo():
return 'foo'

class Client(object):
def __init__(self):
self.v1 = V1Operation()

def func(self):
return 'some func'

client = Client()
return client


def test_client_request_option_decorator():
trace_id = 'trace_id'
span_id = 'span_id'
Expand Down Expand Up @@ -60,15 +76,13 @@ def test_client_request_option_decorator():


def test_client_dir():
class V1Operation():
def foo():
return 'foo'

class Client(object):
def __init__(self):
self.v1 = V1Operation()

client = Client()
client = create_client()
wrapped_client = ZipkinClientDecorator(client)

assert 'foo' in dir(wrapped_client.v1)


def test_callable():
client = create_client()
wrapped_client = ZipkinClientDecorator(client)
assert 'some func' == wrapped_client.func()