Exemplo n.º 1
0
    def test_error_base(self):
        err = errors.U1DBError()
        self.assertEqual("error", err.wire_description)
        self.assertIs(None, err.message)

        err = errors.U1DBError("Message.")
        self.assertEqual("error", err.wire_description)
        self.assertEqual("Message.", err.message)
Exemplo n.º 2
0
 def test_generic_u1db_errors(self):
     self.exc = errors.U1DBError()
     resp = self.app.post('/req',
                          params='{}',
                          headers={'content-type': 'application/json'},
                          expect_errors=True)
     self.assertEqual(500, resp.status)
     self.assertEqual('application/json', resp.header('content-type'))
     self.assertEqual({"error": "error"}, json.loads(resp.body))
Exemplo n.º 3
0
    def test_generic_u1db_errors_hooks(self):
        calls = []

        def begin(environ):
            self.assertTrue('PATH_INFO' in environ)
            calls.append('begin')

        def u1db_error(environ, exc):
            self.assertTrue('PATH_INFO' in environ)
            calls.append(('error', exc))

        self.http_app.request_begin = begin
        self.http_app.request_u1db_error = u1db_error
        # shouldn't be called
        self.http_app.request_done = lambda env: 1 / 0

        self.exc = errors.U1DBError()
        resp = self.app.post('/req', params='{}',
                             headers={'content-type': 'application/json'},
                             expect_errors=True)
        self.assertEqual(500, resp.status)
        self.assertEqual(['begin', ('error', self.exc)], calls)
Exemplo n.º 4
0
 def before_get_docs_explode(state):
     if state != 'before get_docs':
         return
     raise errors.U1DBError("fail")