From e22b66c9aa8cefb98ad451c1948eb22f53881754 Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Fri, 5 Apr 2019 10:48:13 +0300 Subject: [PATCH 1/7] Fix issue #762 HTTP errors now don't crash when formatting the output, even if a `hug.output_format.accept()` formatter is used. --- hug/api.py | 3 ++- tests/test_output_format.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/hug/api.py b/hug/api.py index 90f90321..22367954 100644 --- a/hug/api.py +++ b/hug/api.py @@ -369,7 +369,8 @@ def server(self, default_not_found=True, base_url=None): def error_serializer(request, response, error): response.content_type = self.output_format.content_type - response.body = self.output_format({"errors": {error.title: error.description}}) + response.body = self.output_format({"errors": {error.title: error.description}}, + request, response) falcon_api.set_error_serializer(error_serializer) return falcon_api diff --git a/tests/test_output_format.py b/tests/test_output_format.py index 870e8384..d9fe3455 100644 --- a/tests/test_output_format.py +++ b/tests/test_output_format.py @@ -268,6 +268,26 @@ class FakeRequest(object): assert formatter('hi', request, response) == b'"hi"' +def test_accept_with_http_errors(): + """Ensure that content type based output formats work for HTTP error responses""" + formatter = hug.output_format.accept({'application/json': hug.output_format.json, + 'text/plain': hug.output_format.text}, + default=hug.output_format.json) + + api = hug.API('test_accept_with_http_errors') + hug.default_output_format(api=api)(formatter) + + @hug.get('/500', api=api) + def error_500(): + raise hug.HTTPInternalServerError('500 Internal Server Error', + 'This is an example') + + response = hug.test.get(api, '/500') + assert response.status == '500 Internal Server Error' + assert response.data == { + 'errors': {'500 Internal Server Error': 'This is an example'}} + + def test_suffix(): """Ensure that it's possible to route the output type format by the suffix of the requested URL""" formatter = hug.output_format.suffix({'.js': hug.output_format.json, '.html': hug.output_format.text}) From 462d9520e83367cdd5f6006dd4712cbd8b222951 Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Fri, 5 Apr 2019 10:54:21 +0300 Subject: [PATCH 2/7] Change log for the fix to #762 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8715080a..5a9ed598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ Ideally, within a virtual environment. Changelog ========= +### 2.4.8 - TBD +- Fixed issue #762 - HTTP errors crash with selectable output types + ### 2.4.7 - March 28, 2019 - Fixed API documentation with selectable output types From 471e4db9822c6475c4085f8a907a55b273285047 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sat, 6 Apr 2019 22:01:09 -0700 Subject: [PATCH 3/7] Attempt to fix brew install --- scripts/before_install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/before_install.sh b/scripts/before_install.sh index 85c818dd..b7d8d6ea 100755 --- a/scripts/before_install.sh +++ b/scripts/before_install.sh @@ -6,6 +6,7 @@ echo $TRAVIS_OS_NAME # Travis has an old version of pyenv by default, upgrade it brew update > /dev/null 2>&1 + brew install readline xz brew outdated pyenv || brew upgrade pyenv pyenv --version From 9ef194df5b4360041f6edaf7d116587f5d71becc Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sat, 6 Apr 2019 22:35:45 -0700 Subject: [PATCH 4/7] Try isort version of script --- scripts/before_install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/before_install.sh b/scripts/before_install.sh index b7d8d6ea..51d88bb3 100755 --- a/scripts/before_install.sh +++ b/scripts/before_install.sh @@ -1,4 +1,4 @@ -#! /bin/bash + #! /bin/bash echo $TRAVIS_OS_NAME @@ -6,7 +6,6 @@ echo $TRAVIS_OS_NAME # Travis has an old version of pyenv by default, upgrade it brew update > /dev/null 2>&1 - brew install readline xz brew outdated pyenv || brew upgrade pyenv pyenv --version @@ -17,6 +16,10 @@ echo $TRAVIS_OS_NAME python_minor=4;; py35) python_minor=5;; + py36) + python_minor=6;; + py37) + python_minor=7;; esac latest_version=`pyenv install --list | grep -e "^[ ]*3\.$python_minor" | tail -1` From 5600d0784ed3e46563f0a92428958661ccbb9448 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sat, 6 Apr 2019 22:47:02 -0700 Subject: [PATCH 5/7] Fix max -> python testing --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index adb5efdf..3650107d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,10 +19,13 @@ matrix: env: TOXENV=pypy3 - os: osx language: generic - env: TOXENV=py34 + env: TOXENV=py35 - os: osx language: generic - env: TOXENV=py35 + env: TOXENV=py36 + - os: osx + language: generic + env: TOXENV=py37 before_install: - "./scripts/before_install.sh" install: From 41f004c6d5422512c5e47f85eeea262970e70e1d Mon Sep 17 00:00:00 2001 From: Timothy Edmund Crosley Date: Sat, 6 Apr 2019 23:09:35 -0700 Subject: [PATCH 6/7] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a9ed598..8dec927a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Changelog ### 2.4.8 - TBD - Fixed issue #762 - HTTP errors crash with selectable output types +- Fixed MacOS testing via travis - added testing accross all the same Python versions tested on Linux ### 2.4.7 - March 28, 2019 - Fixed API documentation with selectable output types From 9d7884c4f6691f98b6d200edd2c6608738909d3f Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sun, 7 Apr 2019 10:00:20 -0700 Subject: [PATCH 7/7] Bump version --- .bumpversion.cfg | 2 +- .env | 2 +- CHANGELOG.md | 2 +- hug/_version.py | 2 +- setup.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index e0782c10..0c098fb6 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.4.7 +current_version = 2.4.8 [bumpversion:file:.env] diff --git a/.env b/.env index 11308709..ecc7e458 100644 --- a/.env +++ b/.env @@ -11,7 +11,7 @@ fi export PROJECT_NAME=$OPEN_PROJECT_NAME export PROJECT_DIR="$PWD" -export PROJECT_VERSION="2.4.7" +export PROJECT_VERSION="2.4.8" if [ ! -d "venv" ]; then if ! hash pyvenv 2>/dev/null; then diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dec927a..f0b60300 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ Ideally, within a virtual environment. Changelog ========= -### 2.4.8 - TBD +### 2.4.8 - April 7, 2019 - Fixed issue #762 - HTTP errors crash with selectable output types - Fixed MacOS testing via travis - added testing accross all the same Python versions tested on Linux diff --git a/hug/_version.py b/hug/_version.py index ffba2818..922de651 100644 --- a/hug/_version.py +++ b/hug/_version.py @@ -21,4 +21,4 @@ """ from __future__ import absolute_import -current = "2.4.7" +current = "2.4.8" diff --git a/setup.py b/setup.py index 48dc9cb2..59cd55c0 100755 --- a/setup.py +++ b/setup.py @@ -75,7 +75,7 @@ def list_modules(dirname): setup( name='hug', - version='2.4.7', + version='2.4.8', description='A Python framework that makes developing APIs ' 'as simple as possible, but no simpler.', long_description=long_description,