Exemplo n.º 1
0
def test_environment_generates_bundle_urls(mtime):
    env = Environment('/assets', 'bundles.ini', 'manifest.json')

    assert env.urls('app_js') == [
        '/assets/app.bundle.js?abcdef',
        '/assets/vendor.bundle.js?1234',
    ]
Exemplo n.º 2
0
def test_environment_generates_bundle_urls(mtime):
    env = Environment("/assets", "bundles.ini", "manifest.json")

    assert env.urls("app_js") == [
        "/assets/app.bundle.js?abcdef",
        "/assets/vendor.bundle.js?1234",
    ]
Exemplo n.º 3
0
def test_environment_lists_bundle_files(mtime):
    env = Environment('/assets', 'bundles.ini', 'manifest.json')

    assert env.files('app_js') == [
        'app.bundle.js',
        'vendor.bundle.js',
    ]
Exemplo n.º 4
0
def test_environment_lists_bundle_files(mtime):
    env = Environment('/assets', 'bundles.ini', 'manifest.json')

    assert env.files('app_js') == [
        'app.bundle.js',
        'vendor.bundle.js',
    ]
Exemplo n.º 5
0
def test_environment_generates_bundle_urls(mtime):
    env = Environment('/assets', 'bundles.ini', 'manifest.json')

    assert env.urls('app_js') == [
        '/assets/app.bundle.js?abcdef',
        '/assets/vendor.bundle.js?1234',
    ]
Exemplo n.º 6
0
def test_environment_generates_bundle_urls(mtime):
    env = Environment("/assets", "bundles.ini", "manifest.json")

    assert env.urls("app_js") == [
        "/assets/app.bundle.js?abcdef",
        "/assets/vendor.bundle.js?1234",
    ]
Exemplo n.º 7
0
def test_environment_reloads_manifest_on_change(mtime, open, auto_reload):
    manifest_content = '{"app.bundle.js":"app.bundle.js?oldhash"}'
    bundle_content = "[bundles]\napp_js = \n  app.bundle.js"

    def _fake_open(path):
        if path == "bundles.ini":
            return StringIO(bundle_content)
        elif path == "manifest.json":
            return StringIO(manifest_content)

    open.side_effect = _fake_open
    mtime.return_value = 100
    env = Environment("/assets",
                      "bundles.ini",
                      "manifest.json",
                      auto_reload=auto_reload)

    # An initial call to urls() should read and cache the manifest
    env.urls("app_js")

    manifest_content = '{"app.bundle.js":"app.bundle.js?newhash"}'
    assert env.urls("app_js") == ["/assets/app.bundle.js?oldhash"]

    # Once the manifest's mtime changes, the Environment should re-read
    # the manifest
    mtime.return_value = 101

    if auto_reload:
        assert env.urls("app_js") == ["/assets/app.bundle.js?newhash"]
    else:
        assert env.urls("app_js") == ["/assets/app.bundle.js?oldhash"]
Exemplo n.º 8
0
def test_environment_reloads_manifest_on_change(mtime, open, auto_reload):
    manifest_content = '{"app.bundle.js":"app.bundle.js?oldhash"}'
    bundle_content = "[bundles]\napp_js = \n  app.bundle.js"

    def _fake_open(path):
        if path == "bundles.ini":
            return StringIO(bundle_content)
        elif path == "manifest.json":
            return StringIO(manifest_content)

    open.side_effect = _fake_open
    mtime.return_value = 100
    env = Environment(
        "/assets", "bundles.ini", "manifest.json", auto_reload=auto_reload
    )

    # An initial call to urls() should read and cache the manifest
    env.urls("app_js")

    manifest_content = '{"app.bundle.js":"app.bundle.js?newhash"}'
    assert env.urls("app_js") == ["/assets/app.bundle.js?oldhash"]

    # Once the manifest's mtime changes, the Environment should re-read
    # the manifest
    mtime.return_value = 101

    if auto_reload:
        assert env.urls("app_js") == ["/assets/app.bundle.js?newhash"]
    else:
        assert env.urls("app_js") == ["/assets/app.bundle.js?oldhash"]
Exemplo n.º 9
0
    def pyramid_config(self, pyramid_config):
        # Mock out jinja2 related stuff
        pyramid_config.get_jinja2_environment = mock.create_autospec(
            spec=lambda: JinjaEnvironment())

        pyramid_config.registry["assets_env"] = Environment(
            assets_base_url=mock.sentinel.assets_base_url,
            bundle_config_path=mock.sentinel.bundle_config_path,
            manifest_path=mock.sentinel.manifest_path,
            auto_reload=True,
        )

        pyramid_config.add_jinja2_extension = mock.create_autospec(
            lambda name: True)

        # Prevent us from really loading the includes
        pyramid_config.include = mock.create_autospec(lambda name: True)

        return pyramid_config
Exemplo n.º 10
0
def test_environment_reloads_manifest_on_change(mtime, open):
    manifest_content = '{"app.bundle.js":"app.bundle.js?oldhash"}'
    bundle_content = '[bundles]\napp_js = \n  app.bundle.js'

    def _fake_open(path):
        if path == 'bundles.ini':
            return StringIO(bundle_content)
        elif path == 'manifest.json':
            return StringIO(manifest_content)

    open.side_effect = _fake_open
    mtime.return_value = 100
    env = Environment('/assets', 'bundles.ini', 'manifest.json')

    # An initial call to urls() should read and cache the manifest
    env.urls('app_js')

    manifest_content = '{"app.bundle.js":"app.bundle.js?newhash"}'
    assert env.urls('app_js') == ['/assets/app.bundle.js?oldhash']

    # Once the manifest's mtime changes, the Environment should re-read
    # the manifest
    mtime.return_value = 101
    assert env.urls('app_js') == ['/assets/app.bundle.js?newhash']
Exemplo n.º 11
0
def test_environment_url_returns_cache_busted_url(mtime):
    env = Environment("/assets", "bundles.ini", "manifest.json")

    assert env.url("app.bundle.js") == "/assets/app.bundle.js?abcdef"
Exemplo n.º 12
0
def test_environment_lists_bundle_files(mtime):
    env = Environment("/assets", "bundles.ini", "manifest.json")

    assert env.files("app_js") == ["app.bundle.js", "vendor.bundle.js"]
Exemplo n.º 13
0
def test_environment_url_returns_cache_busted_url(mtime):
    env = Environment('/assets', 'bundles.ini', 'manifest.json')

    assert env.url('app.bundle.js') == '/assets/app.bundle.js?abcdef'
Exemplo n.º 14
0
def test_environment_url_returns_cache_busted_url(mtime):
    env = Environment("/assets", "bundles.ini", "manifest.json")

    assert env.url("app.bundle.js") == "/assets/app.bundle.js?abcdef"
Exemplo n.º 15
0
def test_environment_lists_bundle_files(mtime):
    env = Environment("/assets", "bundles.ini", "manifest.json")

    assert env.files("app_js") == ["app.bundle.js", "vendor.bundle.js"]
Exemplo n.º 16
0
def test_environment_url_returns_cache_busted_url(mtime):
    env = Environment('/assets', 'bundles.ini', 'manifest.json')

    assert env.url('app.bundle.js') == '/assets/app.bundle.js?abcdef'