Example #1
0
    def test_scripts_file_compiled(self):
        with contextlib.nested(*make_named_files(2)) as (js_file, temp_file):
            js_file.write('file')
            js_file.flush()
            js_read_handle = open(js_file.name, 'r')
            temp_read_handle = open(temp_file.name, 'r')

            def temp_opener(filename):
                if 'media/comp/js' in filename:
                    return temp_file
                if 'media/test.js' in filename:
                    return js_read_handle
                return None

            with contextlib.nested(
                    django_exceptions(),
                    django_settings({
                        'COMPILER_ROOT': 'comp',
                        'MEDIA_ROOT': 'media',
                        'MEDIA_URL': '/media/'
                    }), open_redirector(temp_opener), modified_time(),
                    paths_exist('media/comp', 'media/comp/css',
                                'media/comp/js')):
                from compilation.templatetags.compiler import CompilerNode
                html = "<link type=\"text/javascript\" href=\"/media/test.js\" />"
                nodelist = MockNodelist(html)
                compiler_node = CompilerNode(nodelist)
                compiler_node.render(None)
                self.assertEqual(temp_read_handle.read(), 'file\n')
Example #2
0
    def test_styles_compiled(self):
        with contextlib.nested(*make_named_files(2)) as (css_file, temp_file):
            css_file.write('file')
            css_file.flush()
            css_read_handle = open(css_file.name, 'r')
            temp_read_handle = open(temp_file.name, 'r')

            def temp_opener(filename):
                if 'media/comp/css' in filename:
                    return temp_file
                if 'media/test.css' in filename:
                    return css_read_handle
                return None

            with contextlib.nested(
                    django_exceptions(),
                    django_settings({
                        'COMPILER_ROOT': 'comp',
                        'MEDIA_ROOT': 'media',
                        'MEDIA_URL': '/media/'
                    }), open_redirector(temp_opener), modified_time(),
                    paths_exist('media/comp', 'media/comp/css',
                                'media/comp/js')):
                from compilation.templatetags.compiler import CompilerNode
                html = """
                    <link type="text/css" href="/media/test.css" />
                    <style type="text/css">inline</style>
                """
                nodelist = MockNodelist(html)
                compiler_node = CompilerNode(nodelist)
                compiler_node.render(None)
                self.assertSortedEqual(
                    temp_read_handle.read().strip().split('\n'),
                    ['file', 'inline'])
Example #3
0
    def test_scripts_inline_compiled(self):
        with tempfile.NamedTemporaryFile(mode='w') as temp_file:
            read_handle = open(temp_file.name, 'r')

            def temp_opener(filename):
                if 'media/comp/js' in filename:
                    return temp_file
                return None

            with contextlib.nested(
                    django_exceptions(),
                    django_settings({
                        'COMPILER_ROOT': 'comp',
                        'MEDIA_ROOT': 'media',
                        'MEDIA_URL': '/media/'
                    }), open_redirector(temp_opener),
                    paths_exist('media/comp', 'media/comp/css',
                                'media/comp/js')):
                from compilation.templatetags.compiler import CompilerNode
                html = "<script type=\"text/javascript\">inline</script>"
                nodelist = MockNodelist(html)
                compiler_node = CompilerNode(nodelist)
                compiler_node.render(None)
                self.assertEqual(read_handle.read(), 'inline\n')
 def test_scripts_compiled(self):
     with contextlib.nested(*make_named_files(2)) as (js_file, temp_file):
         js_file.write('file')
         js_file.flush()
         js_read_handle = open(js_file.name, 'r')
         temp_read_handle = open(temp_file.name, 'r')
         def temp_opener(filename):
             if 'media/comp/js' in filename:
                 return temp_file
             if 'media/test.js' in filename:
                 return js_read_handle
             return None
         
         with contextlib.nested(django_exceptions(), django_settings({'COMPILER_ROOT':'comp', 'MEDIA_ROOT':'media', 'MEDIA_URL':'/media/'}), open_redirector(temp_opener), modified_time(), paths_exist('media/comp', 'media/comp/css', 'media/comp/js')):
             from compilation.templatetags.compiler import CompilerNode
             html = """
                 <link type="text/javascript" href="/media/test.js" />
                 <script type="text/javascript">inline</script>
             """
             nodelist = MockNodelist(html)
             compiler_node = CompilerNode(nodelist)
             compiler_node.render(None)
             self.assertSortedEqual(temp_read_handle.read().strip().split('\n'), ['file', 'inline'])
 def test_scripts_inline_compiled(self):
     with tempfile.NamedTemporaryFile(mode='w') as temp_file:
         read_handle = open(temp_file.name, 'r')
         def temp_opener(filename):
             if 'media/comp/js' in filename:
                 return temp_file
             return None
         
         with contextlib.nested(django_exceptions(), django_settings({'COMPILER_ROOT':'comp', 'MEDIA_ROOT':'media', 'MEDIA_URL':'/media/'}), open_redirector(temp_opener), paths_exist('media/comp', 'media/comp/css', 'media/comp/js')):
             from compilation.templatetags.compiler import CompilerNode
             html = "<script type=\"text/javascript\">inline</script>"
             nodelist = MockNodelist(html)
             compiler_node = CompilerNode(nodelist)
             compiler_node.render(None)
             self.assertEqual(read_handle.read(), 'inline\n')
 def test_styles_file_compiled(self):
     with contextlib.nested(*make_named_files(2)) as (css_file, temp_file):
         css_file.write('file')
         css_file.flush()
         css_read_handle = open(css_file.name, 'r')
         temp_read_handle = open(temp_file.name, 'r')
         def temp_opener(filename):
             if 'media/comp/css' in filename:
                 return temp_file
             if 'media/test.css' in filename:
                 return css_read_handle
             return None
         
         with contextlib.nested(django_exceptions(), django_settings({'COMPILER_ROOT':'comp', 'MEDIA_ROOT':'media', 'MEDIA_URL':'/media/'}), open_redirector(temp_opener), modified_time(), paths_exist('media/comp', 'media/comp/css', 'media/comp/js')):
             from compilation.templatetags.compiler import CompilerNode
             html = "<link type=\"text/css\" href=\"/media/test.css\" />"
             nodelist = MockNodelist(html)
             compiler_node = CompilerNode(nodelist)
             compiler_node.render(None)
             self.assertEqual(temp_read_handle.read(), 'file\n')