Skip to content
Snippets Groups Projects
Unverified Commit b1e31a70 authored by Michael Youngstrom's avatar Michael Youngstrom Committed by GitHub
Browse files

Merge pull request #18957 from edx/youngstrom/refactor-unittests

Refactor PipelineRenderTest to avoid npm install
parents 3deb7f28 e614b960
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ import os ...@@ -7,6 +7,7 @@ import os
from django.conf import settings from django.conf import settings
from django.test import TestCase from django.test import TestCase
from paver.easy import call_task from paver.easy import call_task
from mock import patch
from pipeline_mako import compressed_css, compressed_js, render_require_js_path_overrides from pipeline_mako import compressed_css, compressed_js, render_require_js_path_overrides
...@@ -41,38 +42,22 @@ class RequireJSPathOverridesTest(TestCase): ...@@ -41,38 +42,22 @@ class RequireJSPathOverridesTest(TestCase):
self.assertEqual(map(str.strip, result.splitlines()), self.OVERRIDES_JS) self.assertEqual(map(str.strip, result.splitlines()), self.OVERRIDES_JS)
@skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in LMS')
@ddt.ddt @ddt.ddt
class PipelineRenderTest(TestCase): class PipelineRenderTest(TestCase):
"""Test individual pipeline rendering functions. """ """Test individual pipeline rendering functions. """
shard = 7 shard = 7
@classmethod @staticmethod
def setUpClass(cls): def mock_staticfiles_lookup(path):
""" return '/static/' + path
Create static assets once for all pipeline render tests.
"""
super(PipelineRenderTest, cls).setUpClass()
# Ensure that the npm requirements are always installed before updating static assets.
prereq_install_value_orig = os.environ.get('NO_PREREQ_INSTALL')
os.environ['NO_PREREQ_INSTALL'] = 'False'
try:
call_task('pavelib.prereqs.install_node_prereqs')
except:
raise
finally:
if prereq_install_value_orig is None:
del os.environ['NO_PREREQ_INSTALL']
else:
os.environ['NO_PREREQ_INSTALL'] = prereq_install_value_orig
# Update all static assets.
call_task('pavelib.assets.update_assets', args=('lms', '--settings=test', '--themes=no'))
@skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in LMS') @patch('static_replace.try_staticfiles_lookup', side_effect=mock_staticfiles_lookup)
@ddt.data( @ddt.data(
(True,), (True,),
(False,), (False,),
) )
def test_compressed_css(self, pipeline_enabled): def test_compressed_css(self, pipeline_enabled, mock_staticfiles_lookup):
""" """
Verify the behavior of compressed_css, with the pipeline Verify the behavior of compressed_css, with the pipeline
both enabled and disabled. both enabled and disabled.
...@@ -86,8 +71,9 @@ class PipelineRenderTest(TestCase): ...@@ -86,8 +71,9 @@ class PipelineRenderTest(TestCase):
css_include = compressed_css('style-main-v1', raw=True) css_include = compressed_css('style-main-v1', raw=True)
self.assertIn(u'lms-main-v1.css?raw', css_include) self.assertIn(u'lms-main-v1.css?raw', css_include)
@skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in LMS') @patch('django.contrib.staticfiles.storage.staticfiles_storage.exists', return_value=True)
def test_compressed_js(self): @patch('static_replace.try_staticfiles_lookup', side_effect=mock_staticfiles_lookup)
def test_compressed_js(self, mock_staticfiles_lookup, mock_staticfiles_exists):
""" """
Verify the behavior of compressed_css, with the pipeline Verify the behavior of compressed_css, with the pipeline
both enabled and disabled. both enabled and disabled.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment