From f68c7e87f7d6d188140ffc727bdd8795ae4b92bd Mon Sep 17 00:00:00 2001 From: Jeremy Bowman Date: Wed, 18 Sep 2019 12:59:32 -0400 Subject: [PATCH] Fix student.helpers logging tests --- common/djangoapps/student/helpers.py | 12 ++++++------ common/djangoapps/student/tests/test_helpers.py | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/common/djangoapps/student/helpers.py b/common/djangoapps/student/helpers.py index fe82520fdb..366d6d33d5 100644 --- a/common/djangoapps/student/helpers.py +++ b/common/djangoapps/student/helpers.py @@ -327,14 +327,14 @@ def _get_redirect_to(request): mime_type, _ = mimetypes.guess_type(redirect_to, strict=False) if not is_safe_login_or_logout_redirect(request, redirect_to): log.warning( - u'Unsafe redirect parameter detected after login page: %(redirect_to)r', + u"Unsafe redirect parameter detected after login page: '%(redirect_to)s'", {"redirect_to": redirect_to} ) redirect_to = None elif 'text/html' not in header_accept: log.info( - u'Redirect to non html content %(content_type)r detected from %(user_agent)r' - u' after login page: %(redirect_to)r', + u"Redirect to non html content '%(content_type)s' detected from '%(user_agent)s'" + u" after login page: '%(redirect_to)s'", { "redirect_to": redirect_to, "content_type": header_accept, "user_agent": request.META.get('HTTP_USER_AGENT', '') @@ -343,13 +343,13 @@ def _get_redirect_to(request): redirect_to = None elif mime_type: log.warning( - u'Redirect to url path with specified filed type %(mime_type)r not allowed: %(redirect_to)r', + u"Redirect to url path with specified filed type '%(mime_type)s' not allowed: '%(redirect_to)s'", {"redirect_to": redirect_to, "mime_type": mime_type} ) redirect_to = None elif settings.STATIC_URL in redirect_to: log.warning( - u'Redirect to static content detected after login page: %(redirect_to)r', + u"Redirect to static content detected after login page: '%(redirect_to)s'", {"redirect_to": redirect_to} ) redirect_to = None @@ -359,7 +359,7 @@ def _get_redirect_to(request): for theme in themes: if theme.theme_dir_name in next_path: log.warning( - u'Redirect to theme content detected after login page: %(redirect_to)r', + u"Redirect to theme content detected after login page: '%(redirect_to)s'", {"redirect_to": redirect_to} ) redirect_to = None diff --git a/common/djangoapps/student/tests/test_helpers.py b/common/djangoapps/student/tests/test_helpers.py index 5a7f195960..07ca1d319b 100644 --- a/common/djangoapps/student/tests/test_helpers.py +++ b/common/djangoapps/student/tests/test_helpers.py @@ -38,20 +38,20 @@ class TestLoginHelper(TestCase): @ddt.data( (logging.WARNING, "WARNING", "https://www.amazon.com", "text/html", None, - "Unsafe redirect parameter detected after login page: u'https://www.amazon.com'"), + "Unsafe redirect parameter detected after login page: 'https://www.amazon.com'"), (logging.WARNING, "WARNING", "testserver/edx.org/images/logo", "text/html", None, - "Redirect to theme content detected after login page: u'testserver/edx.org/images/logo'"), + "Redirect to theme content detected after login page: 'testserver/edx.org/images/logo'"), (logging.INFO, "INFO", "favicon.ico", "image/*", "test/agent", - "Redirect to non html content 'image/*' detected from 'test/agent' after login page: u'favicon.ico'"), + "Redirect to non html content 'image/*' detected from 'test/agent' after login page: 'favicon.ico'"), (logging.WARNING, "WARNING", "https://www.test.com/test.jpg", "image/*", None, - "Unsafe redirect parameter detected after login page: u'https://www.test.com/test.jpg'"), + "Unsafe redirect parameter detected after login page: 'https://www.test.com/test.jpg'"), (logging.INFO, "INFO", static_url + "dummy.png", "image/*", "test/agent", - "Redirect to non html content 'image/*' detected from 'test/agent' after login page: u'" + static_url + + "Redirect to non html content 'image/*' detected from 'test/agent' after login page: '" + static_url + "dummy.png" + "'"), (logging.WARNING, "WARNING", "test.png", "text/html", None, - "Redirect to url path with specified filed type 'image/png' not allowed: u'test.png'"), + "Redirect to url path with specified filed type 'image/png' not allowed: 'test.png'"), (logging.WARNING, "WARNING", static_url + "dummy.png", "text/html", None, - "Redirect to url path with specified filed type 'image/png' not allowed: u'" + static_url + "dummy.png" + "'"), + "Redirect to url path with specified filed type 'image/png' not allowed: '" + static_url + "dummy.png" + "'"), ) @ddt.unpack def test_next_failures(self, log_level, log_name, unsafe_url, http_accept, user_agent, expected_log):