From 3d4b2a7382f0a0e568e2745e4501f33e7d7a6275 Mon Sep 17 00:00:00 2001 From: Ari Rizzitano Date: Wed, 19 Jul 2017 11:38:01 -0400 Subject: [PATCH] include webpack commons bundle on all pages; stub webpack_loader in python unittests include webpack commons bundle on all pages quotes homegrown webpack_loader mock toggle installed webpack_loader in test env file instead fix test checking context --- .../views/tests/test_textbooks.py | 2 +- cms/envs/test.py | 2 ++ cms/templates/base.html | 2 ++ .../templates/static_content.html | 27 +++++++++---------- lms/envs/common.py | 1 + lms/envs/test.py | 2 ++ lms/templates/main.html | 2 ++ lms/templates/main_django.html | 2 ++ openedx/tests/util/__init__.py | 0 openedx/tests/util/webpack_loader/__init__.py | 0 .../webpack_loader/templatetags/__init__.py | 0 .../templatetags/webpack_loader.py | 16 +++++++++++ 12 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 openedx/tests/util/__init__.py create mode 100644 openedx/tests/util/webpack_loader/__init__.py create mode 100644 openedx/tests/util/webpack_loader/templatetags/__init__.py create mode 100644 openedx/tests/util/webpack_loader/templatetags/webpack_loader.py diff --git a/cms/djangoapps/contentstore/views/tests/test_textbooks.py b/cms/djangoapps/contentstore/views/tests/test_textbooks.py index cfbef2491a..5b6076f49d 100644 --- a/cms/djangoapps/contentstore/views/tests/test_textbooks.py +++ b/cms/djangoapps/contentstore/views/tests/test_textbooks.py @@ -19,7 +19,7 @@ class TextbookIndexTestCase(CourseTestCase): self.assertEqual(resp.status_code, 200) # we don't have resp.context right now, # due to bugs in our testing harness :( - if resp.context: + if resp.context and resp.context.get('course'): self.assertEqual(resp.context['course'], self.course) def test_view_index_xhr(self): diff --git a/cms/envs/test.py b/cms/envs/test.py index 62d0eefea4..f33f0f3e76 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -66,6 +66,8 @@ TEST_ROOT = path('test_root') # Want static files in the same dir for running on jenkins. STATIC_ROOT = TEST_ROOT / "staticfiles" +INSTALLED_APPS = tuple(app for app in INSTALLED_APPS if app != 'webpack_loader') +INSTALLED_APPS += ('openedx.tests.util.webpack_loader',) WEBPACK_LOADER['DEFAULT']['STATS_FILE'] = STATIC_ROOT / "webpack-stats.json" GITHUB_REPO_ROOT = TEST_ROOT / "data" diff --git a/cms/templates/base.html b/cms/templates/base.html index 8e24b21021..9cc015c745 100644 --- a/cms/templates/base.html +++ b/cms/templates/base.html @@ -62,6 +62,8 @@ from openedx.core.djangolib.js_utils import ( <%static:js group='base_vendor'/> + <%static:webpack entry="commons"/> + - """).render(Context({ - 'entry': entry, - 'body': capture(caller.body) - })) - except (IOError, WebpackLoaderBadStatsError) as e: - # Don't break Mako template rendering if the bundle or webpack-stats can't be found, but log it - logger.error('[LEARNER-1938] {error}'.format(error=e)) + return Template(""" + {% load render_bundle from webpack_loader %} + {% render_bundle entry %} + {% if body %} + + {% endif %} + """).render(Context({ + 'entry': entry, + 'body': capture(caller.body) + })) %> diff --git a/lms/envs/common.py b/lms/envs/common.py index 52a991bab3..5d5ef06219 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1967,6 +1967,7 @@ YOUTUBE = { YOUTUBE_API_KEY = None ################################### APPS ###################################### + INSTALLED_APPS = ( # Standard ones that are always installed... 'django.contrib.auth', diff --git a/lms/envs/test.py b/lms/envs/test.py index f980451e99..a1264048df 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -113,6 +113,8 @@ NOSE_PLUGINS = [ TEST_ROOT = path("test_root") # Want static files in the same dir for running on jenkins. STATIC_ROOT = TEST_ROOT / "staticfiles" +INSTALLED_APPS = tuple(app for app in INSTALLED_APPS if app != 'webpack_loader') +INSTALLED_APPS += ('openedx.tests.util.webpack_loader',) WEBPACK_LOADER['DEFAULT']['STATS_FILE'] = STATIC_ROOT / "webpack-stats.json" STATUS_MESSAGE_PATH = TEST_ROOT / "status_message.json" diff --git a/lms/templates/main.html b/lms/templates/main.html index dad1767c40..e25c17cc8c 100644 --- a/lms/templates/main.html +++ b/lms/templates/main.html @@ -81,6 +81,8 @@ from pipeline_mako import render_require_js_path_overrides <%static:js group='lms_bootstrap'/> % endif + <%static:webpack entry="commons"/> +