Skip to content

Commit

Permalink
Merge pull request #452 from nameko/set-attr_name-on-unbound-dependen…
Browse files Browse the repository at this point in the history
…cy-provider

Set attr_name on unbound DependencyProvider
  • Loading branch information
mattbennett committed Jul 20, 2017
2 parents a6d2f84 + e9cb7ce commit c9ef868
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions nameko/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def bind(self, container, attr_name):
"""
instance = super(DependencyProvider, self).bind(container)
instance.attr_name = attr_name
self.attr_name = attr_name
return instance

def get_dependency(self, worker_ctx):
Expand Down
12 changes: 12 additions & 0 deletions test/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ def test_extension_uniqueness(container_factory):
assert dep1.ext != dep2.ext


def test_dependency_attr_name(container_factory):
c1 = container_factory(Service, config={})

bound_dep_provider = get_extension(c1, SimpleDependencyProvider)
assert bound_dep_provider.attr_name == 'dep'

dep_provider_declaration = c1.service_cls.dep
assert dep_provider_declaration.attr_name == 'dep'

assert bound_dep_provider != dep_provider_declaration


def test_is_bound():
container = Mock()

Expand Down

0 comments on commit c9ef868

Please sign in to comment.