Ejemplo n.º 1
0
class TestAssets(unittest.TestCase):
    def setUp(self):
        self.assets = VersionedAssets()
        self.assets['jquery.js'][Version('1.7.1')] = 'jquery-1.7.1.js'
        self.assets['jquery.js'][Version('1.8.3')] = 'jquery-1.8.3.js'
        self.assets['jquery.some.js'][Version('1.8.3')] = {
            'provides': 'jquery.js',
            'requires': 'jquery.js',
            'bundle': None
            }
        self.assets['jquery.form.js'][Version('2.96.0')] = ('jquery.js', 'jquery.form-2.96.js')
        self.assets['jquery.form.1.js'][Version('2.96.0')] = {
            'requires': 'jquery.js>=1.8.3',
            'provides': 'jquery.form.js',
        }
        self.assets['old-lib.js'][Version('1.0.0')] = ('jquery.js<1.8.0', 'old-lib-1.0.0.js')

    def test_asset_unversioned(self):
        bundle = self.assets.require('jquery.js')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js',))

    def test_asset_versioned(self):
        bundle = self.assets.require('jquery.js==1.7.1')
        self.assertEqual(bundle.contents, ('jquery-1.7.1.js',))
        bundle = self.assets.require('jquery.js<1.8.0')
        self.assertEqual(bundle.contents, ('jquery-1.7.1.js',))
        bundle = self.assets.require('jquery.js>=1.8.0')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js',))

    def test_missing_asset(self):
        self.assertRaises(AssetNotFound, self.assets.require, 'missing.js')

    def test_single_requires(self):
        bundle = self.assets.require('jquery.form.js')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js', 'jquery.form-2.96.js'))

    def test_single_requires_which_is_dict(self):
        bundle = self.assets.require('jquery.form.1.js')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js',))

    def test_provides_requires(self):
        bundle = self.assets.require('jquery.some.js', 'jquery.form.js')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js', 'jquery.form-2.96.js'))

    def test_version_copies(self):
        # First asset will load highest available version of the requirement, which conflicts
        # with the second requested version. The same asset can't be requested twice
        self.assertRaises(ValueError, self.assets.require, 'jquery.form.js', 'jquery.js==1.7.1')

    def test_version_conflict(self):
        # First asset will load highest available version of the requirement, which conflicts
        # with the second requested version. The same asset can't be requested twice
        self.assertRaises(ValueError, self.assets.require, 'jquery.form.js', 'old-lib.js')

    def test_blacklist(self):
        bundle = self.assets.require('!jquery.js', 'jquery.form.js')
        self.assertEqual(bundle.contents, ('jquery.form-2.96.js',))
        bundle = self.assets.require('jquery.form.js', '!jquery.js')
        self.assertEqual(bundle.contents, ('jquery.form-2.96.js',))
Ejemplo n.º 2
0
 def setUp(self):
     self.assets = VersionedAssets()
     self.assets['jquery.js'][Version('1.7.1')] = 'jquery-1.7.1.js'
     self.assets['jquery.js'][Version('1.8.3')] = 'jquery-1.8.3.js'
     self.assets['jquery.some.js'][Version('1.8.3')] = {
         'provides': 'jquery.js',
         'requires': 'jquery.js',
         'bundle': None
         }
     self.assets['jquery.form.js'][Version('2.96.0')] = ('jquery.js', 'jquery.form-2.96.js')
     self.assets['jquery.form.1.js'][Version('2.96.0')] = {
         'requires': 'jquery.js>=1.8.3',
         'provides': 'jquery.form.js',
     }
     self.assets['old-lib.js'][Version('1.0.0')] = ('jquery.js<1.8.0', 'old-lib-1.0.0.js')
Ejemplo n.º 3
0
 def setUp(self):
     self.assets = VersionedAssets()
     self.assets['jquery.js'][Version('1.7.1')] = 'jquery-1.7.1.js'
     self.assets['jquery.js'][Version('1.8.3')] = 'jquery-1.8.3.js'
     self.assets['jquery.some.js'][Version('1.8.3')] = {
         'provides': 'jquery.js',
         'requires': 'jquery.js',
         'bundle': None
         }
     self.assets['jquery.form.js'][Version('2.96.0')] = ('jquery.js', 'jquery.form-2.96.js')
     self.assets['jquery.form.1.js'][Version('2.96.0')] = {
         'requires': 'jquery.js>=1.8.3',
         'provides': 'jquery.form.js',
         }
     self.assets['old-lib.js'][Version('1.0.0')] = ('jquery.js<1.8.0', 'old-lib-1.0.0.js')
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-

from __future__ import absolute_import

from coaster.assets import Version, VersionedAssets

from . import __version__

#: Semantic-versioned assets
assets = VersionedAssets()

assets['jquery.js'][Version('1.7.1')] = 'baseframe/js/jquery-1.7.1.js'
assets['jquery.js'][Version('1.8.3')] = 'baseframe/js/jquery-1.8.3.js'
assets['jquery.js'][Version('1.9.1')] = 'baseframe/js/jquery-1.9.1.js'

assets['baseframe-networkbar.js'][Version(
    __version__)] = 'baseframe/js/networkbar.js'
assets['baseframe-networkbar.css'][Version(__version__)] = (
    'baseframe/css/networkbar.css')
assets['baseframe-base.js'][Version(__version__)] = (
    'baseframe/js/baseframe-bootstrap.js')
assets['baseframe-base.css'][Version(
    __version__)] = 'baseframe/css/baseframe.css'
assets['baseframe-base-bs3.css'][Version(__version__)] = (
    'baseframe/css/baseframe-bs3.css')

# Bootstrap 2.0.1
assets['bootstrap.css'][Version('2.0.1')] = 'baseframe/css/bootstrap.css'
assets['bootstrap-responsive.css'][Version(
    '2.0.1')] = 'baseframe/css/responsive.css'
assets['bootstrap-alert.js'][Version('2.0.1')] = (
Ejemplo n.º 5
0
class TestAssets(unittest.TestCase):
    def setUp(self):
        self.assets = VersionedAssets()
        self.assets['jquery.js'][Version('1.7.1')] = 'jquery-1.7.1.js'
        self.assets['jquery.js'][Version('1.8.3')] = 'jquery-1.8.3.js'
        self.assets['jquery.some.js'][Version('1.8.3')] = {
            'provides': 'jquery.js',
            'requires': 'jquery.js',
            'bundle': None
        }
        self.assets['jquery.form.js'][Version('2.96.0')] = (
            'jquery.js', 'jquery.form-2.96.js')
        self.assets['jquery.form.1.js'][Version('2.96.0')] = {
            'requires': 'jquery.js>=1.8.3',
            'provides': 'jquery.form.js',
        }
        self.assets['old-lib.js'][Version('1.0.0')] = ('jquery.js<1.8.0',
                                                       'old-lib-1.0.0.js')

    def test_asset_unversioned(self):
        bundle = self.assets.require('jquery.js')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js', ))

    def test_asset_versioned(self):
        bundle = self.assets.require('jquery.js==1.7.1')
        self.assertEqual(bundle.contents, ('jquery-1.7.1.js', ))
        bundle = self.assets.require('jquery.js<1.8.0')
        self.assertEqual(bundle.contents, ('jquery-1.7.1.js', ))
        bundle = self.assets.require('jquery.js>=1.8.0')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js', ))

    def test_missing_asset(self):
        self.assertRaises(AssetNotFound, self.assets.require, 'missing.js')

    def test_single_requires(self):
        bundle = self.assets.require('jquery.form.js')
        self.assertEqual(bundle.contents,
                         ('jquery-1.8.3.js', 'jquery.form-2.96.js'))

    def test_single_requires_which_is_dict(self):
        bundle = self.assets.require('jquery.form.1.js')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js', ))

    def test_provides_requires(self):
        bundle = self.assets.require('jquery.some.js', 'jquery.form.js')
        self.assertEqual(bundle.contents,
                         ('jquery-1.8.3.js', 'jquery.form-2.96.js'))

    def test_version_copies(self):
        # First asset will load highest available version of the requirement, which conflicts
        # with the second requested version. The same asset can't be requested twice
        self.assertRaises(ValueError, self.assets.require, 'jquery.form.js',
                          'jquery.js==1.7.1')

    def test_version_conflict(self):
        # First asset will load highest available version of the requirement, which conflicts
        # with the second requested version. The same asset can't be requested twice
        self.assertRaises(ValueError, self.assets.require, 'jquery.form.js',
                          'old-lib.js')

    def test_blacklist(self):
        bundle = self.assets.require('!jquery.js', 'jquery.form.js')
        self.assertEqual(bundle.contents, ('jquery.form-2.96.js', ))
        bundle = self.assets.require('jquery.form.js', '!jquery.js')
        self.assertEqual(bundle.contents, ('jquery.form-2.96.js', ))
Ejemplo n.º 6
0
class TestAssets(unittest.TestCase):
    def setUp(self):
        self.assets = VersionedAssets()
        self.assets['jquery.js'][Version('1.7.1')] = 'jquery-1.7.1.js'
        self.assets['jquery.js'][Version('1.8.3')] = 'jquery-1.8.3.js'
        self.assets['jquery.some.js'][Version('1.8.3')] = {
            'provides': 'jquery.js',
            'requires': 'jquery.js',
            'bundle': None
            }
        self.assets['jquery.form.js'][Version('2.96.0')] = ('jquery.js', 'jquery.form-2.96.js')
        self.assets['jquery.form.1.js'][Version('2.96.0')] = {
            'requires': 'jquery.js>=1.8.3',
            'provides': 'jquery.form.js',
            }
        self.assets['old-lib.js'][Version('1.0.0')] = ('jquery.js<1.8.0', 'old-lib-1.0.0.js')

    def test_asset_unversioned(self):
        bundle = self.assets.require('jquery.js')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js',))

    def test_asset_versioned(self):
        bundle = self.assets.require('jquery.js==1.7.1')
        self.assertEqual(bundle.contents, ('jquery-1.7.1.js',))
        bundle = self.assets.require('jquery.js<1.8.0')
        self.assertEqual(bundle.contents, ('jquery-1.7.1.js',))
        bundle = self.assets.require('jquery.js>=1.8.0')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js',))

    def test_missing_asset(self):
        self.assertRaises(AssetNotFound, self.assets.require, 'missing.js')

    def test_single_requires(self):
        bundle = self.assets.require('jquery.form.js')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js', 'jquery.form-2.96.js'))

    def test_single_requires_which_is_dict(self):
        bundle = self.assets.require('jquery.form.1.js')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js',))

    def test_provides_requires(self):
        bundle = self.assets.require('jquery.some.js', 'jquery.form.js')
        self.assertEqual(bundle.contents, ('jquery-1.8.3.js', 'jquery.form-2.96.js'))

    def test_version_copies(self):
        # First asset will load highest available version of the requirement, which conflicts
        # with the second requested version. The same asset can't be requested twice
        self.assertRaises(ValueError, self.assets.require, 'jquery.form.js', 'jquery.js==1.7.1')

    def test_version_conflict(self):
        # First asset will load highest available version of the requirement, which conflicts
        # with the second requested version. The same asset can't be requested twice
        self.assertRaises(ValueError, self.assets.require, 'jquery.form.js', 'old-lib.js')

    def test_blacklist(self):
        bundle = self.assets.require('!jquery.js', 'jquery.form.js')
        self.assertEqual(bundle.contents, ('jquery.form-2.96.js',))
        bundle = self.assets.require('jquery.form.js', '!jquery.js')
        self.assertEqual(bundle.contents, ('jquery.form-2.96.js',))

    def test_uglipyjs(self):
        """Test the UglipyJS filter"""
        infile = six.StringIO("""
            function test() {
              alert("Hello, world!");
            };
            """)
        outfile = six.StringIO()
        filter = UglipyJS()
        filter.setup()
        filter.output(infile, outfile)
        self.assertEqual(outfile.getvalue(), 'function test(){alert("Hello, world!")};')
Ejemplo n.º 7
0
class TestAssets(unittest.TestCase):
    def setUp(self):
        self.assets = VersionedAssets()
        self.assets['jquery.js'][Version('1.7.1')] = 'jquery-1.7.1.js'
        self.assets['jquery.js'][Version('1.8.3')] = 'jquery-1.8.3.js'
        self.assets['jquery.some.js'][Version('1.8.3')] = {
            'provides': 'jquery.js',
            'requires': 'jquery.js',
            'bundle': None,
        }
        self.assets['jquery.form.js'][Version('2.96.0')] = (
            'jquery.js',
            'jquery.form-2.96.js',
        )
        self.assets['jquery.form.1.js'][Version('2.96.0')] = {
            'requires': 'jquery.js>=1.8.3',
            'provides': 'jquery.form.js',
        }
        self.assets['old-lib.js'][Version('1.0.0')] = (
            'jquery.js<1.8.0',
            'old-lib-1.0.0.js',
        )

    def test_asset_unversioned(self):
        bundle = self.assets.require('jquery.js')
        assert bundle.contents == ('jquery-1.8.3.js', )

    def test_asset_versioned(self):
        bundle = self.assets.require('jquery.js==1.7.1')
        assert bundle.contents == ('jquery-1.7.1.js', )
        bundle = self.assets.require('jquery.js<1.8.0')
        assert bundle.contents == ('jquery-1.7.1.js', )
        bundle = self.assets.require('jquery.js>=1.8.0')
        assert bundle.contents == ('jquery-1.8.3.js', )

    def test_missing_asset(self):
        with pytest.raises(AssetNotFound):
            self.assets.require('missing.js')

    def test_single_requires(self):
        bundle = self.assets.require('jquery.form.js')
        assert bundle.contents == ('jquery-1.8.3.js', 'jquery.form-2.96.js')

    def test_single_requires_which_is_dict(self):
        bundle = self.assets.require('jquery.form.1.js')
        assert bundle.contents == ('jquery-1.8.3.js', )

    def test_provides_requires(self):
        bundle = self.assets.require('jquery.some.js', 'jquery.form.js')
        assert bundle.contents == ('jquery-1.8.3.js', 'jquery.form-2.96.js')

    def test_version_copies(self):
        # First asset will load highest available version of the requirement, which conflicts
        # with the second requested version. The same asset can't be requested twice
        with pytest.raises(ValueError):
            self.assets.require('jquery.form.js', 'jquery.js==1.7.1')

    def test_version_conflict(self):
        # First asset will load highest available version of the requirement, which conflicts
        # with the second requested version. The same asset can't be requested twice
        with pytest.raises(ValueError):
            self.assets.require('jquery.form.js', 'old-lib.js')

    def test_blacklist(self):
        bundle = self.assets.require('!jquery.js', 'jquery.form.js')
        assert bundle.contents == ('jquery.form-2.96.js', )
        bundle = self.assets.require('jquery.form.js', '!jquery.js')
        assert bundle.contents == ('jquery.form-2.96.js', )

    def test_uglipyjs(self):
        """Test the UglipyJS filter"""
        infile = six.StringIO("""
            function test() {
              alert("Hello, world!");
            };
            """)
        outfile = six.StringIO()
        afilter = UglipyJS()
        afilter.setup()
        afilter.output(infile, outfile)
        assert outfile.getvalue() == 'function test(){alert("Hello, world!")};'