(self)
| 679 | self.assertEqual(args, got[2]) |
| 680 | |
| 681 | def test_processors(self): |
| 682 | # *_request / *_response methods get called appropriately |
| 683 | o = OpenerDirector() |
| 684 | meth_spec = [ |
| 685 | [("http_request", "return request"), |
| 686 | ("http_response", "return response")], |
| 687 | [("http_request", "return request"), |
| 688 | ("http_response", "return response")], |
| 689 | ] |
| 690 | handlers = add_ordered_mock_handlers(o, meth_spec) |
| 691 | |
| 692 | req = Request("http://example.com/") |
| 693 | o.open(req) |
| 694 | # processor methods are called on *all* handlers that define them, |
| 695 | # not just the first handler that handles the request |
| 696 | calls = [ |
| 697 | (handlers[0], "http_request"), (handlers[1], "http_request"), |
| 698 | (handlers[0], "http_response"), (handlers[1], "http_response")] |
| 699 | |
| 700 | for i, (handler, name, args, kwds) in enumerate(o.calls): |
| 701 | if i < 2: |
| 702 | # *_request |
| 703 | self.assertEqual((handler, name), calls[i]) |
| 704 | self.assertEqual(len(args), 1) |
| 705 | self.assertIsInstance(args[0], Request) |
| 706 | else: |
| 707 | # *_response |
| 708 | self.assertEqual((handler, name), calls[i]) |
| 709 | self.assertEqual(len(args), 2) |
| 710 | self.assertIsInstance(args[0], Request) |
| 711 | # response from opener.open is None, because there's no |
| 712 | # handler that defines http_open to handle it |
| 713 | if args[1] is not None: |
| 714 | self.assertIsInstance(args[1], MockResponse) |
| 715 | |
| 716 | |
| 717 | class HandlerTests(unittest.TestCase): |
nothing calls this directly
no test coverage detected