From c5d49be2c1baa38c175cd71827ab4cee89b53ac9 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Fri, 4 May 2018 08:39:09 -0400 Subject: [PATCH] avoid error in templating error --- awx/main/tests/unit/api/test_views.py | 9 +++++++++ awx/templates/rest_framework/base.html | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/awx/main/tests/unit/api/test_views.py b/awx/main/tests/unit/api/test_views.py index 4c767043bb..fe1c4974dc 100644 --- a/awx/main/tests/unit/api/test_views.py +++ b/awx/main/tests/unit/api/test_views.py @@ -16,6 +16,9 @@ from awx.api.views import ( from awx.main.models import ( Host, ) +from awx.main.views import handle_error + +from rest_framework.test import APIRequestFactory @pytest.fixture @@ -25,6 +28,12 @@ def mock_response_new(mocker): return m +def test_handle_error(): + # Assure that templating of error does not raise errors + request = APIRequestFactory().get('/fooooo/') + handle_error(request) + + class TestApiRootView: def test_get_endpoints(self, mocker, mock_response_new): endpoints = [ diff --git a/awx/templates/rest_framework/base.html b/awx/templates/rest_framework/base.html index cbd761cf33..313bbec9a3 100644 --- a/awx/templates/rest_framework/base.html +++ b/awx/templates/rest_framework/base.html @@ -157,8 +157,8 @@
-
HTTP {{ response.status_code }} {{ response.status_text }}{% autoescape off %}{% for key, val in response_headers|items %}
-{{ key }}: {{ val|break_long_headers|urlize_quoted_links }}{% endfor %}
+                
HTTP {{ response.status_code }} {{ response.status_text }}{% autoescape off %}{% if response_headers %}{% for key, val in response_headers|items %}
+{{ key }}: {{ val|break_long_headers|urlize_quoted_links }}{% endfor %}{% endif %}
 {# Original line below had the side effect of also escaping content: #}
 {#   {{ content|urlize_quoted_links }}
{% endautoescape %} #} {# For AWX, disable automatic URL creation and move content outside of autoescape off block. #}