Skip to content

Commit

Permalink
Fix call id properties (#507)
Browse files Browse the repository at this point in the history
* fix_call_id_properties - Fix the tests of immediate_parent_call_id

* fix_call_id_properties - fix immediate_parent_call_id to get the correct element from the stack

* fix_call_id_properties - Added tests for a new method to fetch the origin call_id from the stack

* fix_call_id_properties - Implemented property origin_call_id

* fix_call_id_properties - Added newline to test/test_call_id_stack.py
  • Loading branch information
fobiols authored and mattbennett committed Feb 17, 2018
1 parent ccade35 commit ee009fa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
7 changes: 6 additions & 1 deletion nameko/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,15 @@ def context_data(self):
return data

@property
def immediate_parent_call_id(self):
def origin_call_id(self):
if self._parent_call_id_stack:
return self._parent_call_id_stack[0]

@property
def immediate_parent_call_id(self):
if self._parent_call_id_stack:
return self._parent_call_id_stack[-1]

def __repr__(self):
cls_name = type(self).__name__
service_name = self.service_name
Expand Down
45 changes: 43 additions & 2 deletions test/test_call_id_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,18 @@ def test_with_parent(self, mock_container):
service = Mock()
entrypoint = DummyProvider("bar")
context_data = {
'call_id_stack': ['parent.method.1']
'call_id_stack': [
'parent.method.1',
'parent.method.2',
'parent.method.3'
]
}

worker_ctx = WorkerContext(
mock_container, service, entrypoint, data=context_data
)

assert worker_ctx.immediate_parent_call_id == "parent.method.1"
assert worker_ctx.immediate_parent_call_id == "parent.method.3"

def test_without_parent(self, mock_container):

Expand All @@ -241,3 +245,40 @@ def test_without_parent(self, mock_container):
)

assert worker_ctx.immediate_parent_call_id is None


class TestOriginCallId(object):

def test_with_origin(self, mock_container):

mock_container.service_name = "foo"

service = Mock()
entrypoint = DummyProvider("bar")
context_data = {
'call_id_stack': [
'parent.method.1',
'parent.method.2',
'parent.method.3'
]
}

worker_ctx = WorkerContext(
mock_container, service, entrypoint, data=context_data
)

assert worker_ctx.origin_call_id == "parent.method.1"

def test_without_origin(self, mock_container):

mock_container.service_name = "foo"

service = Mock()
entrypoint = DummyProvider("bar")
context_data = {}

worker_ctx = WorkerContext(
mock_container, service, entrypoint, data=context_data
)

assert worker_ctx.origin_call_id is None

0 comments on commit ee009fa

Please sign in to comment.