Skip to content
Myr

Merge pull request #863 from sigmavirus24/fix_hooks

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #785 & add regression test.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents c91f83f, 4dd3d1a · Browse files · 2 files+38 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+38 added−2 removed

  • tests:+34 added−0 removed
  • other:+4 added−2 removed

2 files+38 added−2 removed

modified:requests/models.py+4 added-2 removed
460 unmodified lines
461 return ''.join(url)462463 def register_hook(self, event, hook):464 """Properly register a hook."""465 if isinstance(hook, (list, tuple, set)):466 self.hooks[event].extend(hook)467 else:468 self.hooks[event].append(hook)469466 self.hooks[event].append(hook)467470 def deregister_hook(self, event, hook):471 """Deregister a previously registered hook.472 Returns True if the hook existed, False if not.473 """
417 unmodified lines
modified:tests/test_requests.py+34 added
742 unmodified lines
743744 assert 'foo' in response.text745 assert 'bar' in response.text746747 def test_allow_list_of_hooks_to_register_hook(self):748 """Issue 785: https://github.com/kennethreitz/requests/issues/785"""749 def add_foo_header(args):750 if not args.get('headers'):751 args['headers'] = {}752753 args['headers'].update({754 'X-Foo': 'foo'755 })756757 return args758759 def add_bar_header(args):760 if not args.get('headers'):761 args['headers'] = {}762763 args['headers'].update({764 'X-Bar': 'bar'765 })766767 return args768769 def assert_hooks_are_callable(hooks):770 for h in hooks['args']:771 assert callable(h) is True772773 hooks = [add_foo_header, add_bar_header]774 r = requests.models.Request()775 r.register_hook('args', hooks)776 assert_hooks_are_callable(r.hooks)777778 r = requests.models.Request(hooks={'args': hooks})779 assert_hooks_are_callable(r.hooks)780781 def test_session_persistent_cookies(self):782783 s = requests.session()784
395 unmodified lines