Remove 204-NoContent, Flask, and Werkzeug no longer provide
public apis to add additional error code exception handling.
This commit is contained in:
@@ -17,7 +17,6 @@ from flask import (
|
||||
)
|
||||
|
||||
from pypuppetdb import connect
|
||||
from pypuppetdb.errors import EmptyResponseError
|
||||
from pypuppetdb.QueryBuilder import *
|
||||
|
||||
from puppetboard.forms import (CatalogForm, QueryForm)
|
||||
@@ -119,26 +118,6 @@ def utility_processor():
|
||||
return dict(now=now)
|
||||
|
||||
|
||||
#
|
||||
# 204 doesn't have a mapping in werkzeug, we need to define a custom
|
||||
# class and then set it to the mappings.
|
||||
#
|
||||
class NoContent(ex.HTTPException):
|
||||
code = 204
|
||||
description = '<p>No content</p'
|
||||
|
||||
abort.mapping[204] = NoContent
|
||||
|
||||
try:
|
||||
@app.errorhandler(204)
|
||||
def no_content(e):
|
||||
return '', 204
|
||||
except KeyError:
|
||||
@app.errorhandler(EmptyResponseError)
|
||||
def no_content(e):
|
||||
return '', 204
|
||||
|
||||
|
||||
@app.errorhandler(400)
|
||||
def bad_request(e):
|
||||
envs = environments()
|
||||
|
||||
@@ -16,12 +16,6 @@ def mock_puppetdb_environments(mocker):
|
||||
return_value=environemnts)
|
||||
|
||||
|
||||
def test_error_no_content():
|
||||
result = app.no_content(None)
|
||||
assert result[0] == ''
|
||||
assert result[1] == 204
|
||||
|
||||
|
||||
def test_error_bad_request(mock_puppetdb_environments):
|
||||
with app.app.test_request_context():
|
||||
(output, error_code) = app.bad_request(None)
|
||||
|
||||
@@ -12,7 +12,6 @@ from werkzeug.exceptions import NotFound, InternalServerError
|
||||
|
||||
from puppetboard import utils
|
||||
from puppetboard import app
|
||||
from puppetboard.app import NoContent
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
import logging
|
||||
@@ -108,19 +107,6 @@ def test_http_connection_error(mock_log):
|
||||
mock_log.error.assert_called_with(err)
|
||||
|
||||
|
||||
def test_http_empty(mock_log, mocker):
|
||||
err = "Empty Response"
|
||||
|
||||
def connection_error():
|
||||
raise EmptyResponseError(err)
|
||||
|
||||
flask_abort = mocker.patch('flask.abort')
|
||||
with pytest.raises(NoContent):
|
||||
utils.get_or_abort(connection_error)
|
||||
mock_log.error.assert_called_with(err)
|
||||
flask_abort.assert_called_with('204')
|
||||
|
||||
|
||||
def test_db_version_good(mocker, mock_info_log):
|
||||
mocker.patch.object(app.puppetdb, 'current_version', return_value='4.2.0')
|
||||
err = 'PuppetDB Version %d.%d.%d' % (4, 2, 0)
|
||||
|
||||
Reference in New Issue
Block a user