def test_lets_exception_raised_by_callback_pass_through(self):
     exception_class = Spam
     raised = exception_class()
     callback = func_that_raises(raised)
     client = HttpClient()
     client.set_exceptional_response_callback(exception_class=HttpNotFound,
                                              callback=callback)
     self.context.inject(inspect_response, func_that_raises(HttpNotFound))
     expect(partial(client.put, "https://up.with.it")).to(raise_ex(raised))
 def test_re_raises_unspecified_response_exception(self):
     client = HttpClient()
     client.set_exceptional_response_callback(exception_class=HttpNotFound,
                                              callback=lambda *a, **k: None)
     raised = HttpUnauthorized()
     self.context.inject(inspect_response, func_that_raises(raised))
     expect(partial(client.post, "http://mail.net")).to(raise_ex(raised))
Ejemplo n.º 3
0
 def test_returned_func_accepts_arbitrary_kwargs(self):
     func = func_that_raises(FakeException())
     try:
         func(a=1, b=2, c="the spinach inquisition")
         assert False, "No exception was raised"
     except FakeException:
         pass
Ejemplo n.º 4
0
 def test_returned_func_accepts_arbitrary_args(self):
     func = func_that_raises(FakeException())
     try:
         func(1, 2, 3, 4, 5)
         assert False, "No exception was raised"
     except FakeException:
         pass
 def test_returns_response_returned_by_callback(self):
     callback_response = EndlessFake()
     self.context.inject(inspect_response, func_that_raises(HttpNotFound()))
     client = HttpClient()
     client.set_exceptional_response_callback(
         exception_class=HttpNotFound,
         callback=lambda *a, **k: callback_response)
     expect(client.get("http://stuffed")).to(be(callback_response))
 def test_re_raises_exception_if_callback_returns_none(self):
     original = HttpImATeapot()
     self.context.inject(inspect_response, func_that_raises(original))
     client = HttpClient()
     client.set_exceptional_response_callback(exception_class=HttpImATeapot,
                                              callback=lambda *a, **k: None)
     expect(partial(client.delete,
                    "http://nothing.new")).to(raise_ex(original))
 def test_passes_exception_as_kwarg(self):
     exception_class = HttpImATeapot
     spy = FunctionSpy(return_value=EndlessFake())
     client = HttpClient()
     client.set_exceptional_response_callback(
         exception_class=exception_class, callback=spy)
     self.context.inject(inspect_response,
                         func_that_raises(exception_class()))
     client.get("http://foo.bar")
     expect(spy["exception"]).to(be_a(exception_class))
 def test_calls_callback_for_child_class(self):
     specified_class = Spam
     raised_class = SonOfSpam
     spy = FunctionSpy()
     client = HttpClient()
     client.set_exceptional_response_callback(
         exception_class=specified_class, callback=spy)
     self.context.inject(inspect_response, func_that_raises(raised_class()))
     try:
         client.get("http://stuffed.com.au")
     except raised_class:
         # Exception should not be raised, but this test does not care
         pass
     spy.assert_was_called()
 def test_calls_callback_for_exception(self):
     exception_class = HttpUnauthorized
     spy = FunctionSpy()
     client = HttpClient()
     client.set_exceptional_response_callback(
         exception_class=HttpUnauthorized, callback=spy)
     self.context.inject(inspect_response,
                         func_that_raises(exception_class()))
     try:
         client.get("http://spam")
     except exception_class:
         # This shouldn't be raised but this test doesn't care
         pass
     spy.assert_was_called()
Ejemplo n.º 10
0
    def test_returned_func_raises_expected_exception(self):

        expected = RuntimeError("Shuzbut")
        expect(func_that_raises(expected)).to(raise_ex(expected))