From 288f4135e3e081248379d76baab1c161fef486be Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Mon, 13 Jan 2020 17:16:43 +0000 Subject: [PATCH] Added (currently inactive) code to trigger exceptions on failure to resolve template variables during tests, and added fixes for a couple of places that triggered such exceptions. - Legacy-Id: 17226 --- ietf/doc/models.py | 6 ++++++ ietf/templates/base.html | 6 ++++-- ietf/templates/doc/document_charter.html | 6 +++++- ietf/utils/test_runner.py | 20 ++++++++++++++++---- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/ietf/doc/models.py b/ietf/doc/models.py index 2dc63c319..dd7ed55fb 100644 --- a/ietf/doc/models.py +++ b/ietf/doc/models.py @@ -919,6 +919,12 @@ class DocHistory(DocumentInfo): def related_ipr(self): return self.doc.related_ipr() + def documenturl_set(self): + return self.doc.documenturl_set + + def filename_with_rev(self): + return self.doc.filename_with_rev() + class Meta: verbose_name = "document history" verbose_name_plural = "document histories" diff --git a/ietf/templates/base.html b/ietf/templates/base.html index 6b345df5a..9cbf25784 100644 --- a/ietf/templates/base.html +++ b/ietf/templates/base.html @@ -148,10 +148,12 @@ {% endif %} Report a bug: Tracker: + {% if bugreport_email %} Email: + {% endif %}
- Python {{ python_version }} | - Django {{ django_version }} + {% if python_version %}Python {{ python_version }}{% endif %} | + {% if django_version %}Django {{ django_version }}{% endif %}

diff --git a/ietf/templates/doc/document_charter.html b/ietf/templates/doc/document_charter.html index 60a4ff2df..8fa5592ed 100644 --- a/ietf/templates/doc/document_charter.html +++ b/ietf/templates/doc/document_charter.html @@ -92,7 +92,11 @@ {% endif %} - {{ doc.get_state.name }} + {% if doc.get_state %} + {{ doc.get_state.name }} + {% else %} + No document state + {% endif %} {% if chartering == "initial" %} Initial chartering diff --git a/ietf/utils/test_runner.py b/ietf/utils/test_runner.py index f17e89527..2aaa054f2 100644 --- a/ietf/utils/test_runner.py +++ b/ietf/utils/test_runner.py @@ -1,4 +1,4 @@ -# Copyright The IETF Trust 2009-2019, All Rights Reserved +# Copyright The IETF Trust 2009-2020, All Rights Reserved # -*- coding: utf-8 -*- # # Portion Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). @@ -489,6 +489,12 @@ class CoverageTest(unittest.TestCase): ' please see if they can be re-ordered with all data migrations before the schema migrations:\n' +('\n'.join([' %-6s: %-12s, %s (%s)'% (op, node.key[0], node.key[1], nm) for (node, op, nm) in unreleased ]))) +class InvalidString(str): + def __mod__(self, other): + from django.template.base import TemplateSyntaxError + raise TemplateSyntaxError( + "Undefined variable or unknown value for: \"%s\"" % other) + class IetfTestRunner(DiscoverRunner): @classmethod @@ -587,9 +593,15 @@ class IetfTestRunner(DiscoverRunner): print(" Changing SITE_ID to '1' during testing.") settings.SITE_ID = 1 - if settings.TEMPLATES[0]['OPTIONS']['string_if_invalid'] != '': - print(" Changing TEMPLATES[0]['OPTIONS']['string_if_invalid'] to '' during testing") - settings.TEMPLATES[0]['OPTIONS']['string_if_invalid'] = '' + if True: + if settings.TEMPLATES[0]['OPTIONS']['string_if_invalid'] != '': + print(" Changing TEMPLATES[0]['OPTIONS']['string_if_invalid'] to '' during testing") + settings.TEMPLATES[0]['OPTIONS']['string_if_invalid'] = '' + else: + # Alternative code to trigger test exceptions on failure to + # resolve variables in templates. + print(" Changing TEMPLATES[0]['OPTIONS']['string_if_invalid'] during testing") + settings.TEMPLATES[0]['OPTIONS']['string_if_invalid'] = InvalidString('%s') if settings.INTERNAL_IPS: print(" Changing INTERNAL_IPS to '[]' during testing.")