Esempio n. 1
0
def test_run_command(app, mocker):
    b = Bundle('p1', 'some/where', ['some/input/file.js'])
    rollup = Rollup(app)
    rollup.register(b)
    fake_run = mocker.Mock()
    mocker.patch.object(rollup, 'run_rollup', fake_run)
    runner = app.test_cli_runner()
    rv = runner.invoke(rollup_run_cmd)
    assert rv.exit_code == 0
    assert 'All done' in rv.output
    fake_run.assert_called_once()
Esempio n. 2
0
def test_template_global_fail_on_prod(app, mocker):
    def handler():
        return render_template_string('{{ jsbundle(request.endpoint) }}')

    mocker.patch.dict('os.environ', {'FLASK_ENV': 'production'})
    app.config['SERVER_NAME'] = '127.0.0.1'
    name = 'p1'
    b = Bundle(name, 'some/where', ['some/input/file.js'])
    rollup = Rollup(app)
    mocker.patch('flask_rollup.glob.glob', mocker.Mock(return_value=[]))
    rollup.register(b)
    app.add_url_rule('/something', endpoint=name, view_func=handler)
    with app.test_client() as client:
        with app.app_context():
            url = url_for(name)
        rv = client.get(url)
        assert rv.status_code == 500
Esempio n. 3
0
def test_autobuild_not_running_in_production(app, mocker):
    def handler():
        return 'something'

    app.config['SERVER_NAME'] = '127.0.0.1'
    name = 'p1'
    mocker.patch.dict('os.environ', {'FLASK_ENV': 'production'})
    rollup = Rollup(app)
    b = Bundle(name, 'some/where', ['some/input/file.js'])
    rollup.register(b)
    app.add_url_rule('/something', endpoint=name, view_func=handler)
    fake_run = mocker.Mock()
    mocker.patch.object(rollup, 'run_rollup', fake_run)
    with app.test_client() as client:
        with app.app_context():
            url = url_for(name)
        client.get(url)
    fake_run.assert_not_called()
Esempio n. 4
0
def test_init_command(app, tmp_path, mocker):
    Rollup(app)
    pwd = tmp_path / 'flaskrolluptest'
    os.makedirs(pwd, exist_ok=True)
    os.chdir(pwd)
    fake_run = mocker.Mock()
    mocker.patch('flask_rollup.cli.subprocess.run', fake_run)
    runner = app.test_cli_runner()
    rv = runner.invoke(rollup_init_cmd)
    assert rv.exit_code == 0
    assert 'Rollup installation is ready' in rv.output
    assert fake_run.call_count == 2
Esempio n. 5
0
def test_autobuild_running_in_development(app, mocker):
    def handler():
        return 'something'

    app.config['SERVER_NAME'] = '127.0.0.1'
    name = 'p1'
    mocker.patch.dict('os.environ', {'FLASK_ENV': 'development'})
    rollup = Rollup(app)
    b = Bundle(name, 'some/where', ['some/input/file.js'])
    mocker.patch('flask_rollup.os.stat',
                 mocker.Mock(return_value=mocker.Mock(st_mtime_ns=200)))
    mocker.patch('flask_rollup.subprocess.run')
    rollup.register(b)
    app.add_url_rule('/something', endpoint=name, view_func=handler)
    fake_run = mocker.Mock()
    mocker.patch.object(rollup, 'run_rollup', fake_run)
    with app.test_client() as client:
        with app.app_context():
            url = url_for(name)
        client.get(url)
    fake_run.assert_called_once_with(name)
Esempio n. 6
0
def test_init_with_babel(app, tmp_path, mocker):
    Rollup(app)
    pwd = tmp_path / 'flaskrolluptest'
    os.makedirs(pwd, exist_ok=True)
    os.chdir(pwd)
    fake_run = mocker.Mock()
    mocker.patch('flask_rollup.cli.subprocess.run', fake_run)
    runner = app.test_cli_runner()
    rv = runner.invoke(rollup_init_cmd, ['--babel'])
    assert rv.exit_code == 0
    assert 'Rollup installation is ready' in rv.output
    assert fake_run.call_count == 2
    install_cmd = fake_run.call_args_list[-1][0][0]
    assert '@babel/core' in install_cmd
Esempio n. 7
0
def test_run(environment, app, mocker):
    name = 'p1'
    mocker.patch.dict('os.environ', {'FLASK_ENV': environment})
    b = Bundle(name, 'some/where', ['some/input/file.js'])
    rollup = Rollup(app)
    fake_run = mocker.Mock()
    mocker.patch('flask_rollup.subprocess.run', fake_run)
    mocker.patch('flask_rollup.os.stat',
                 mocker.Mock(return_value=mocker.Mock(st_mtime_ns=100)))
    rollup.register(b)
    rollup.run_rollup(name)
    rollup.run_rollup(name)
    fake_run.assert_called_once()
Esempio n. 8
0
def test_template_global(app, mocker):
    def handler():
        return render_template_string('{{ jsbundle(request.endpoint) }}')

    app.config['SERVER_NAME'] = '127.0.0.1'
    name = 'p1'
    b = Bundle(name, 'some/where', ['some/input/file.js'])
    mocker.patch.object(b, 'calc_state', mocker.Mock(return_value='state'))
    rollup = Rollup(app)
    mocker.patch('flask_rollup.subprocess.run')
    tgt_path = '/static/directory/some/where/file1.js'
    mocker.patch('flask_rollup.glob.glob',
                 mocker.Mock(return_value=[tgt_path]))
    rollup.register(b)
    app.add_url_rule('/something', endpoint=name, view_func=handler)
    mocker.patch('flask_rollup.os.remove')
    rollup.run_rollup(name)
    with app.test_client() as client:
        with app.app_context():
            url = url_for(name)
        rv = client.get(url)
        assert b.output.url.encode('utf-8') in rv.data
Esempio n. 9
0
def test_autobuild_disabled_in_production(app, mocker):
    mocker.patch.dict('os.environ', {'FLASK_ENV': 'production'})
    Rollup(app)
    assert len(app.before_request_funcs) == 0
Esempio n. 10
0
def test_create_simple(app):
    rv = Rollup(app)
    assert rv.app == app
    assert app.extensions['rollup'] == rv
Esempio n. 11
0
def test_autobuild_enabled_in_development(app, mocker):
    mocker.patch.dict('os.environ', {'FLASK_ENV': 'development'})
    Rollup(app)
    assert len(app.before_request_funcs) == 1
Esempio n. 12
0
def test_config_path_provided(app):
    config_file_path = '/some/where/rollup.config.js'
    app.config['ROLLUP_CONFIG_JS'] = config_file_path
    rv = Rollup(app)
    assert len(rv.argv) == 3
    assert rv.argv[-1] == config_file_path
Esempio n. 13
0
def test_init_app(app):
    r = Rollup()
    r.init_app(app)
    assert r.app is None
    assert app.extensions['rollup'] == r
Esempio n. 14
0
def test_register(app):
    b = Bundle('p1', 'some/where', ['some/input/file.js'])
    rollup = Rollup(app)
    rollup.register(b)
    assert len(rollup.bundles) == 1
    assert os.path.isabs(b.target_dir)