def test_compile_file(self, tmpdir):
        from jac import CompressorExtension
        ext = CompressorExtension(mock.Mock(compressor_output_dir=tmpdir, compressor_static_prefix='/static',
                                            compressor_source_dirs=[str(tmpdir)]))
        static_file = os.path.join(str(tmpdir), 'test.sass')

        with open(static_file, 'w', encoding='utf-8') as f:
            f.write('''$blue: #3bbfce
$margin: 16px

.content-navigation
  border-color: $blue
  color: darken($blue, 9%)

.border
  padding: $margin / 2
  margin: $margin / 2
  border-color: $blue''')

        html = '<link type="text/sass" rel="stylesheet" src="test.sass">'
        expected_hash = hashlib.md5(utf8_encode(html))
        with open(static_file) as f:
            expected_hash.update(utf8_encode(f.read()))

        assert ext._compress_block('css', mock.Mock(return_value=html)) == \
            '<link type="text/css" rel="stylesheet" href="/static/{}.css">'.format(expected_hash.hexdigest())
    def test_compile_js(self, tmpdir, html_js):
        from jac import CompressorExtension
        ext = CompressorExtension(mock.Mock(compressor_output_dir=tmpdir, compressor_static_prefix='/static',
                                            compressor_source_dirs=[]))

        assert ext._compress_block('js', mock.Mock(return_value=html_js)) == \
            '<script type="text/javascript" src="/static/0749ffbc6e886a3a01ee6e6c15efc779.js"></script>'
    def test_compile(self, tmpdir, html_css):
        from jac import CompressorExtension
        ext = CompressorExtension(mock.Mock(compressor_output_dir=tmpdir,
                                            compressor_static_prefix='/static', compressor_source_dirs=[]))

        assert ext._compress_block('css', mock.Mock(return_value=html_css)) == \
            '<link type="text/css" rel="stylesheet" href="/static/734b0dec0b33781a9b57f86b1a5e02a3.css">'
    def test_compile_file(self, tmpdir):
        from jac import CompressorExtension
        ext = CompressorExtension(
            mock.Mock(compressor_output_dir=tmpdir,
                      compressor_static_prefix='/static',
                      compressor_source_dirs=[str(tmpdir)]))
        static_file = os.path.join(str(tmpdir), 'test.sass')

        with open(static_file, 'w', encoding='utf-8') as f:
            f.write('''$blue: #3bbfce
$margin: 16px

.content-navigation
  border-color: $blue
  color: darken($blue, 9%)

.border
  padding: $margin / 2
  margin: $margin / 2
  border-color: $blue''')

        html = '<link type="text/sass" rel="stylesheet" src="test.sass" />'
        expected_hash = hashlib.md5(utf8_encode(html))
        with open(static_file) as f:
            expected_hash.update(utf8_encode(f.read()))

        assert ext._compress_block(
            'css', mock.Mock(return_value=html)
        ) == '<link type="text/css" rel="stylesheet" href="/static/{}.css" />'.format(
            expected_hash.hexdigest())
    def test_compile_js(self, tmpdir, html_js):
        from jac import CompressorExtension
        ext = CompressorExtension(
            mock.Mock(compressor_output_dir=tmpdir,
                      compressor_static_prefix='/static',
                      compressor_source_dirs=[]))

        assert ext._compress_block('js', mock.Mock(return_value=html_js)) == \
            '<script type="text/javascript" src="/static/0749ffbc6e886a3a01ee6e6c15efc779.js"></script>'
    def test_compile(self, tmpdir, html_css):
        from jac import CompressorExtension
        ext = CompressorExtension(
            mock.Mock(compressor_output_dir=tmpdir,
                      compressor_static_prefix='/static',
                      compressor_source_dirs=[]))

        assert ext._compress_block('css', mock.Mock(return_value=html_css)) == \
            '<link type="text/css" rel="stylesheet" href="/static/734b0dec0b33781a9b57f86b1a5e02a3.css">'