コード例 #1
0
ファイル: __init__.py プロジェクト: necoma/n6-matatabi
def main(global_config, **settings):
    helper = ConfigHelper(
        # a dict of settings from the *.ini file
        settings=settings,

        # a data backend API *class*
        data_backend_api_class=MatatabiDataBackendApi,

        # an *instance* of an authentication policy class
        authentication_policy=AnonymousAuthenticationPolicy(),

        # the list of HTTP resources defined above
        resources=RESOURCES,
    )
    return helper.make_wsgi_app()
コード例 #2
0
 def test__exc_to_http_exc__HTTPException_no_server_error(self, LOGGER):
     exc = HTTPNotFound()
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIs(http_exc, exc)
     self.assertEqual(http_exc.code, 404)
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY, 404),
     ])
コード例 #3
0
 def test__exc_to_http_exc__HTTPException_no_server_error(self, LOGGER):
     exc = HTTPNotFound()
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIs(http_exc, exc)
     self.assertEqual(http_exc.code, 404)
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY, 404),
     ])
コード例 #4
0
 def test__exc_to_http_exc__HTTPException_server_error(self, LOGGER):
     exc = HTTPServerError()
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIs(http_exc, exc)
     self.assertEqual(http_exc.code, 500)
     self.assertEqual(LOGGER.mock_calls, [
         call.error(ANY, exc, ANY, 500, exc_info=True),
     ])
コード例 #5
0
 def test__exc_to_http_exc__HTTPException_server_error(self, LOGGER):
     exc = HTTPServerError()
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIs(http_exc, exc)
     self.assertEqual(http_exc.code, 500)
     self.assertEqual(LOGGER.mock_calls, [
         call.error(ANY, exc, ANY, 500, exc_info=True),
     ])
コード例 #6
0
 def test__exc_to_http_exc__other_DataAPIError_2(self, LOGGER):
     exc = DataAPIError()  # no specific public message
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPServerError)
     self.assertEqual(http_exc.code, 500)
     self.assertIs(http_exc.detail, None)  # *no* detail
     self.assertEqual(LOGGER.mock_calls, [
         call.error(ANY, exc, ANY, exc_info=True),
     ])
コード例 #7
0
 def test__exc_to_http_exc__other_DataAPIError(self, LOGGER):
     exc = DataAPIError(public_message='FOO')  # custom public message
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPServerError)
     self.assertEqual(http_exc.code, 500)
     self.assertEqual(http_exc.detail, 'FOO')  # detail == custom public message
     self.assertEqual(LOGGER.mock_calls, [
         call.error(ANY, exc, ANY, exc_info=True),
     ])
コード例 #8
0
 def test__exc_to_http_exc__ParamCleaningError(self, LOGGER):
     exc = ParamCleaningError(public_message='FOO')  # custom public message
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPBadRequest)
     self.assertEqual(http_exc.code, 400)
     self.assertEqual(http_exc.detail, 'FOO')  # detail == custom public message
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY),
     ])
コード例 #9
0
 def test__exc_to_http_exc__other_exception(self, LOGGER):
     exc = ZeroDivisionError
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPServerError)
     self.assertEqual(http_exc.code, 500)
     self.assertIs(http_exc.detail, None)  # no detail
     self.assertEqual(LOGGER.mock_calls, [
         call.error(ANY, exc, exc_info=True),
     ])
コード例 #10
0
 def test__exc_to_http_exc__other_DataAPIError_2(self, LOGGER):
     exc = DataAPIError()  # no specific public message
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPServerError)
     self.assertEqual(http_exc.code, 500)
     self.assertIs(http_exc.detail, None)  # *no* detail
     self.assertEqual(LOGGER.mock_calls, [
         call.error(ANY, exc, ANY, exc_info=True),
     ])
コード例 #11
0
 def test__exc_to_http_exc__other_exception(self, LOGGER):
     exc = ZeroDivisionError
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPServerError)
     self.assertEqual(http_exc.code, 500)
     self.assertIs(http_exc.detail, None)  # no detail
     self.assertEqual(LOGGER.mock_calls, [
         call.error(ANY, exc, exc_info=True),
     ])
コード例 #12
0
 def test__exc_to_http_exc__TooMuchDataError(self, LOGGER):
     exc = TooMuchDataError(public_message='FOO')  # custom public message
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPForbidden)
     self.assertEqual(http_exc.code, 403)
     self.assertEqual(http_exc.detail, 'FOO')  # detail == custom public message
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY),
     ])
コード例 #13
0
 def test__exc_to_http_exc__ParamCleaningError_2(self, LOGGER):
     exc = ParamCleaningError()  # no specific public message
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPBadRequest)
     self.assertEqual(http_exc.code, 400)
     self.assertEqual(http_exc.detail,  # detail == default public message
                      ParamCleaningError.default_public_message)
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY),
     ])
コード例 #14
0
 def test__exc_to_http_exc__TooMuchDataError_2(self, LOGGER):
     exc = TooMuchDataError()  # no specific public message
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPForbidden)
     self.assertEqual(http_exc.code, 403)
     self.assertEqual(http_exc.detail,  # detail == default public message
                      TooMuchDataError.default_public_message)
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY),
     ])
コード例 #15
0
 def test__exc_to_http_exc__ParamCleaningError(self, LOGGER):
     exc = ParamCleaningError(public_message='FOO')  # custom public message
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPBadRequest)
     self.assertEqual(http_exc.code, 400)
     self.assertEqual(http_exc.detail,
                      'FOO')  # detail == custom public message
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY),
     ])
コード例 #16
0
 def test__exc_to_http_exc__TooMuchDataError(self, LOGGER):
     exc = TooMuchDataError(public_message='FOO')  # custom public message
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPForbidden)
     self.assertEqual(http_exc.code, 403)
     self.assertEqual(http_exc.detail,
                      'FOO')  # detail == custom public message
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY),
     ])
コード例 #17
0
 def test__exc_to_http_exc__other_DataAPIError(self, LOGGER):
     exc = DataAPIError(public_message='FOO')  # custom public message
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPServerError)
     self.assertEqual(http_exc.code, 500)
     self.assertEqual(http_exc.detail,
                      'FOO')  # detail == custom public message
     self.assertEqual(LOGGER.mock_calls, [
         call.error(ANY, exc, ANY, exc_info=True),
     ])
コード例 #18
0
 def test__exc_to_http_exc__ParamCleaningError_2(self, LOGGER):
     exc = ParamCleaningError()  # no specific public message
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPBadRequest)
     self.assertEqual(http_exc.code, 400)
     self.assertEqual(
         http_exc.detail,  # detail == default public message
         ParamCleaningError.default_public_message)
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY),
     ])
コード例 #19
0
 def test__exc_to_http_exc__TooMuchDataError_2(self, LOGGER):
     exc = TooMuchDataError()  # no specific public message
     http_exc = ConfigHelper.exc_to_http_exc(exc)
     self.assertIsInstance(http_exc, HTTPForbidden)
     self.assertEqual(http_exc.code, 403)
     self.assertEqual(
         http_exc.detail,  # detail == default public message
         TooMuchDataError.default_public_message)
     self.assertEqual(LOGGER.mock_calls, [
         call.debug(ANY, exc, ANY),
     ])
コード例 #20
0
ファイル: test_pyramid_commons.py プロジェクト: scottwedge/n6
 def test__exception_view__http_exc_body_already_set(
         self, exc_to_http_exc_mock):
     http_exc = HTTPNotFound('FOO', body='SPAM', content_type='text/spam')
     exc_to_http_exc_mock.return_value = http_exc
     assert http_exc.code == 404
     assert http_exc.content_type == 'text/spam'
     assert http_exc.body == 'SPAM'
     request = MagicMock()
     request.environ = {'HTTP_ACCEPT': 'text/html'}
     result = ConfigHelper.exception_view(sen.exc, request)
     self.assertIs(result, http_exc)
     self.assertEqual(http_exc.content_type, 'text/spam')
     self.assertEqual(http_exc.body, 'SPAM')
     self.assertEqual(exc_to_http_exc_mock.mock_calls, [
         call(sen.exc),
     ])
コード例 #21
0
ファイル: test_pyramid_commons.py プロジェクト: scottwedge/n6
 def test__exception_view(self, exc_to_http_exc_mock):
     http_exc = HTTPNotFound('FOO')
     exc_to_http_exc_mock.return_value = http_exc
     assert http_exc.code == 404
     assert http_exc.content_type == 'text/html'
     assert http_exc.body == ''
     request = MagicMock()
     request.environ = {'HTTP_ACCEPT': 'text/html'}
     result = ConfigHelper.exception_view(sen.exc, request)
     self.assertIs(result, http_exc)
     self.assertEqual(http_exc.content_type, 'text/plain')  # no HTML
     self.assertNotIn('<', http_exc.body)  # no HTML
     self.assertIn('404', http_exc.body)
     self.assertIn('FOO', http_exc.body)
     self.assertEqual(exc_to_http_exc_mock.mock_calls, [
         call(sen.exc),
     ])