File: test_compress.py

package info (click to toggle)
couchapp 1.0.1%2Bgit20140213%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 968 kB
  • ctags: 405
  • sloc: python: 3,278; sh: 53; makefile: 22
file content (56 lines) | stat: -rw-r--r-- 2,183 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 unittest2 as 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()