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_file_inside_media_url(self):
     with django_settings({
             'MEDIA_URL': '/test/',
             'MEDIA_ROOT': '/testroot/'
     }):
         self.assertEqual(DjangoMediaLocator.locate('/test/file'),
                          ['/testroot/file'])
Example #3
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'])
 def test_read_django_url(self):
     with django_settings():
         with make_named_files() as temp_file:
             temp_file.write('test')
             temp_file.flush()
             handler = self.handler('/test%s' % temp_file.name, 'url')
             self.assertEqual(handler.content, 'test')
Example #5
0
 def test_read_django_url(self):
     with django_settings():
         with make_named_files() as temp_file:
             temp_file.write('test')
             temp_file.flush()
             handler = self.handler('/test%s' % temp_file.name, 'url')
             self.assertEqual(handler.content, 'test')
Example #6
0
 def test_bad_settings_no_compiler_root(self):
     with contextlib.nested(django_exceptions(), django_settings()):
         from django.core.exceptions import ImproperlyConfigured
         from compilation.templatetags.compiler import CompilerNode
         html = "<script type=\"text/javascript\">testing</script>"
         nodelist = MockNodelist(html)
         compiler_node = CompilerNode(nodelist)
         self.assertRaises(ImproperlyConfigured, compiler_node.render, None)
 def test_bad_settings_compiler_root_dne(self):
     with contextlib.nested(django_exceptions(), django_template(), django_settings({'COMPILER_ROOT':'directory/doesnt/exist'})):
         from django.core.exceptions import ImproperlyConfigured
         from compilation.templatetags.compiler import CompilerNode
         html = "<script type=\"text/javascript\">testing</script>"
         nodelist = MockNodelist(html)
         compiler_node = CompilerNode(nodelist)
         self.assertRaises(ImproperlyConfigured, compiler_node.render, None)
 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_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 #10
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 #11
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')
Example #12
0
 def basic_context(self):
     return contextlib.nested(django_template(),
                              django_settings({'COMPILER_ROOT': '/'}),
                              django_exceptions(),
                              paths_exist('/css', '/js'))
Example #13
0
 def test_file_outside_media_url(self):
     with django_settings({'MEDIA_URL': '/nope'}):
         self.assertEqual(DjangoMediaLocator.locate('/test/file'), [])
Example #14
0
 def test_file_outside_media_url(self):
     with django_settings({'MEDIA_URL': '/nope'}):
         self.assertRaises(ValueError, self.handler, '/test/file', 'url')
Example #15
0
 def basic_context(self):
     return contextlib.nested(django_template(), django_settings({'COMPILER_ROOT':'/'}), django_exceptions(), paths_exist('/css', '/js'))
Example #16
0
 def test_file_inside_media_url(self):
     with django_settings({'MEDIA_URL': '/test/', 'MEDIA_ROOT': '/testroot/'}):
         self.assertEqual(DjangoMediaLocator.locate('/test/file'), ['/testroot/file'])
Example #17
0
 def test_file_outside_media_url(self):
     with django_settings({'MEDIA_URL': '/nope'}):
         self.assertEqual(DjangoMediaLocator.locate('/test/file'), [])
Example #18
0
 def test_file_outside_media_url(self):
     with django_settings({'MEDIA_URL': '/nope'}):
         self.assertRaises(ValueError, self.handler, '/test/file', 'url')