Permalink
Browse files

Unit tests added for default js compressor

  • Loading branch information...
1 parent 522b51f commit 78b3e80707e700cc91254aba549bfc736e1fe7e5 @reyiyo reyiyo committed Feb 9, 2014
@@ -2,6 +2,9 @@
#
# This file is part of couchapp released under the Apache 2 license.
# See the NOTICE for more information.
+from __future__ import absolute_import
+
+__about__ = 'jsmin'
def compress(js):
try:
No changes.
No changes.
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# This software is licensed as described in the file LICENSE, which
+# you should have received as part of this distribution.
+
+import unittest
+import mock
+import os
+
+class CompressTest(unittest.TestCase):
+
+ def test_compress_js(self):
+ from couchapp.config import Config
+ config = Config()
+ config.conf['compress'] = {'js': {'foo':['shows/example-show.js']}}
+ with mock.patch('couchapp.hooks.compress.default.compress', return_value='foo') as mock_compress:
+ from couchapp.hooks.compress import Compress
+ compress = Compress(os.path.join(os.path.dirname(__file__), '../../../testapp'))
+ compress.conf = config
+ with mock.patch('couchapp.util.write'):
+ compress.run()
+ self.assertTrue(mock_compress.called, 'Default compressor has been called')
+
+ def test_our_jsmin_loading(self):
+ orig_import = __import__
+
+ def import_mock(name, *args):
+ if name == 'jsmin':
+ raise ImportError()
+ return orig_import(name, *args)
+
+ with mock.patch('__builtin__.__import__', side_effect=import_mock):
+ with mock.patch('couchapp.hooks.compress.jsmin.jsmin', return_value='foo'):
+ from couchapp.hooks.compress import default
+ result = default.compress('bar')
+ self.assertEqual(result, 'foo', 'Our module is called when it is not installed in the system')
+
+ def test_system_jsmin_loading(self):
+ orig_import = __import__
+
+ def import_mock(name, *args):
+ if name == 'couchapp.hooks.compress.jsmin':
+ raise ImportError()
+ return orig_import(name, *args)
+
+ with mock.patch('__builtin__.__import__', side_effect=import_mock):
+ with mock.patch('jsmin.jsmin', return_value='foo'):
+ from couchapp.hooks.compress import default
+ result = default.compress('bar')
+ self.assertEqual(result, 'foo', 'The system module is called when it is installed')
+
+
+if __name__ == "__main__":
+ # import sys;sys.argv = ['', 'Test.testName']
+ unittest.main()

0 comments on commit 78b3e80

Please sign in to comment.