diff --git a/tests/__init__.py b/tests/__init__.py index 6988853..e69de29 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,13 +0,0 @@ -import sys, os - -# In order to test the Flask-Script command, Flask-Script needs to be -# installed. If this is the case, we won't be able to import from our -# local src/flaskext directory that nose puts on sys.path, due to the -# way Flask extensions employ pkg_resources to have multiple directories -# contribute to the same module. We fix it by manually adding the -# directory to an already existing virtual flaskext module. -try: - sys.modules['flaskext'].__path__.append( - os.path.join(os.path.dirname(__file__), '../src/flaskext')) -except KeyError: - pass \ No newline at end of file diff --git a/tests/test_module/__init__.py b/tests/bp_for_test/__init__.py similarity index 50% rename from tests/test_module/__init__.py rename to tests/bp_for_test/__init__.py index 96d0422..d585732 100644 --- a/tests/test_module/__init__.py +++ b/tests/bp_for_test/__init__.py @@ -1,3 +1,3 @@ """This is here so that the tests have a Python package available -that can serve as the base for Flask modules used during testing. +that can serve as the base for Flask blueprints used during testing. """ \ No newline at end of file diff --git a/tests/test_module/static/README b/tests/bp_for_test/static/README similarity index 100% rename from tests/test_module/static/README rename to tests/bp_for_test/static/README diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..1207ee4 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,34 @@ +import shutil +import tempfile + +import pytest +from flask import Flask + +from flask_assets import Environment +from tests.helpers import new_blueprint + + +@pytest.fixture +def app(): + app = Flask(__name__, static_url_path="/app_static") + bp = new_blueprint("bp", static_url_path="/bp_static", static_folder="static") + app.register_blueprint(bp) + return app + + +@pytest.fixture +def env(app): + env = Environment(app) + return env + + +@pytest.fixture +def no_app_env(): + return Environment() + + +@pytest.fixture +def temp_dir(): + temp = tempfile.mkdtemp() + yield temp + shutil.rmtree(temp, ignore_errors=True) diff --git a/tests/helpers.py b/tests/helpers.py index 8c78e10..4c932f3 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -1,38 +1,27 @@ -from flask.app import Flask -from webassets.test import TempEnvironmentHelper as BaseTempEnvironmentHelper -from flask_assets import Environment +import os -try: - from flask import Blueprint - Module = None -except ImportError: - # Blueprints only available starting with 0.7, - # fall back to old Modules otherwise. - Blueprint = None - from flask import Module +from flask import Blueprint +__all__ = ("create_files", "new_blueprint") -__all__ = ('TempEnvironmentHelper', 'Module', 'Blueprint') +def create_files(parent, *files): + result = [] + for file in files: + path = os.path.join(parent, file) + dir_path = os.path.dirname(path) + if not os.path.exists(dir_path): + os.mkdir(dir_path) + f = open(path, "w", encoding="utf-8") + f.close() + result.append(path) -class TempEnvironmentHelper(BaseTempEnvironmentHelper): + return result - def _create_environment(self, **kwargs): - if not hasattr(self, 'app'): - self.app = Flask(__name__, static_folder=self.tempdir, **kwargs) - self.env = Environment(self.app) - return self.env - -try: - from test.test_support import check_warnings -except ImportError: - # Python < 2.6 - import contextlib - - @contextlib.contextmanager - def check_warnings(*filters, **kwargs): - # We cannot reasonably support this, we'd have to copy to much code. - # (or write our own). Since this is only testing warnings output, - # we might slide by ignoring it. - yield +def new_blueprint(name, import_name=None, **kwargs): + if import_name is None: + from tests import bp_for_test + import_name = bp_for_test.__name__ + bp = Blueprint(name, import_name, **kwargs) + return bp diff --git a/tests/test_config.py b/tests/test_config.py index ad39faa..c886423 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,116 +1,53 @@ -"""The Environment configuration is hooked up to the Flask config dict. -""" - -from __future__ import absolute_import - import pytest from flask import Flask -from flask_assets import Environment - -try: - from webassets.updater import BaseUpdater -except ImportError: - BaseUpdater = None # older webassets versions (<=0.5) - - -if BaseUpdater: - class MooUpdater(BaseUpdater): - id = 'MOO' - - -class TestConfigAppBound: - """The extension is bound to a specific app. - """ - - def setup(self): - self.app = Flask(__name__) - self.env = Environment(self.app) - - def test_set_environment(self): - """Setting a config value on the environment works. - """ - self.env.updater = 'foo' - assert self.app.config['ASSETS_UPDATER'] == 'foo' - - def test_set_config(self): - """Setting a value in the Flask config works. - """ - self.app.config['ASSETS_UPDATER'] = 'MOO' - assert self.env.updater == 'MOO' - - def test_custom_values(self): - """Custom config values are relayed to the Flask config as.is. - """ - self.app.config['LESS_PATH'] = '/usr/bin/less' - assert self.env.config['LESS_PATH'] == '/usr/bin/less' - - def test_no_override(self): - """Ensure that the webassets defaults do not override existing - Flask config values. - """ - app = Flask(__name__) - app.config['ASSETS_UPDATER'] = 'MOO' - env = Environment(app) - assert env.updater == 'MOO' - assert app.config['ASSETS_UPDATER'] == 'MOO' - - # Neither do the defaults that flask-assets set. - app = Flask(__name__) - app.config['ASSETS_URL'] = 'MOO' - env = Environment(app) - assert env.url == 'MOO' - assert app.config['ASSETS_URL'] == 'MOO' - - -class TestConfigNoAppBound: - """The application is not bound to a specific app. - """ - - def setup(self): - self.env = Environment() - - def test_no_app_available(self): - """Without an application bound, we can't do much.""" - with pytest.raises(RuntimeError): - setattr(self.env, 'debug', True) - with pytest.raises(RuntimeError): - self.env.config.get('debug') - - def test_global_defaults(self): - """We may set defaults even without an application, however.""" - self.env.config.setdefault('FOO', 'BAR') - with Flask(__name__).test_request_context(): - assert self.env.config['FOO'] == 'BAR' - - def test_multiple_separate_apps(self): - """Each app has it's own separate configuration. - """ - app1 = Flask(__name__) - self.env.init_app(app1) - - # With no app yet available... - with pytest.raises(RuntimeError): - getattr(self.env, 'url') - # ...set a default - self.env.config.setdefault('FOO', 'BAR') - - # When an app is available, the default is used - with app1.test_request_context(): - assert self.env.config['FOO'] == 'BAR' - - # If the default is overridden for this application, it - # is still valid for other apps. - self.env.config['FOO'] = '42' - assert self.env.config['FOO'] == '42' - app2 = Flask(__name__) - with app2.test_request_context(): - assert self.env.config['FOO'] == 'BAR' - - def test_key_error(self): - """KeyError is raised if a config value doesn't exist. - """ - with Flask(__name__).test_request_context(): - with pytest.raises(KeyError): - self.env.config['YADDAYADDA'] - # The get() helper, on the other hand, simply returns None - assert self.env.config.get('YADDAYADDA') == None + + +def test_env_set(app, env): + env.url = "https://github.com/miracle2k/flask-assets" + assert app.config["ASSETS_URL"] == "https://github.com/miracle2k/flask-assets" + + +def test_env_get(app, env): + app.config["ASSETS_URL"] = "https://github.com/miracle2k/flask-assets" + assert env.url == "https://github.com/miracle2k/flask-assets" + + +def test_env_config(app, env): + app.config["LESS_PATH"] = "/usr/bin/less" + assert env.config["LESS_PATH"] == "/usr/bin/less" + + with pytest.raises(KeyError): + _ = env.config["do_not_exist"] + + assert env.config.get("do_not_exist") is None + + +def test_no_app_env_set(no_app_env): + with pytest.raises(RuntimeError): + no_app_env.debug = True + + +def test_no_app_env_get(no_app_env): + with pytest.raises(RuntimeError): + no_app_env.config.get("debug") + + +def test_no_app_env_config(app, no_app_env): + no_app_env.config.setdefault("foo", "bar") + with app.test_request_context(): + assert no_app_env.config["foo"] == "bar" + + +def test_config_isolation_within_apps(no_app_env): + no_app_env.config.setdefault("foo", "bar") + + app1 = Flask(__name__) + with app1.test_request_context(): + assert no_app_env.config["foo"] == "bar" + + no_app_env.config["foo"] = "qux" + assert no_app_env.config["foo"] == "qux" + + app2 = Flask(__name__) + with app2.test_request_context(): + assert no_app_env.config["foo"] == "bar" diff --git a/tests/test_env.py b/tests/test_env.py index c519f49..5a579e1 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -1,50 +1,34 @@ import os +import types -from flask import Flask -from flask_assets import Environment, Bundle +from flask_assets import Bundle -class TestEnv: +def test_assets_tag(app, env): + env.register("test", "file1", "file2") + template = app.jinja_env.from_string("{% assets 'test' %}{{ASSET_URL}};{% endassets %}") + assert template.render() == "/app_static/file1;/app_static/file2;" - def setup(self): - self.app = Flask(__name__) - self.env = Environment(self.app) - self.env.debug = True - self.env.register('test', 'file1', 'file2') - def test_tag_available(self): - """Jinja tag has been made available. - """ - t = self.app.jinja_env.from_string('{% assets "test" %}{{ASSET_URL}};{% endassets %}') - assert t.render() == '/static/file1;/static/file2;' +def test_from_module(app, env): + module = types.ModuleType("test") + module.pytest = Bundle("py_file1", "py_file2") + env.from_module(module) + template = app.jinja_env.from_string('{% assets "pytest" %}{{ASSET_URL}};{% endassets %}') + assert template.render() == '/app_static/py_file1;/app_static/py_file2;' - def test_from_yaml(self): - """YAML configuration gets loaded - """ - f = open('test.yaml', 'w') + +def test_from_yaml(app, env): + with open("test.yaml", "w", encoding="utf-8") as f: f.write(""" - yamltest: + yaml_test: contents: - - yamlfile1 - - yamlfile2 + - yaml_file1 + - yaml_file2 """) - f.close() - - self.env.from_yaml('test.yaml') - - t = self.app.jinja_env.from_string('{% assets "yamltest" %}{{ASSET_URL}};{% endassets %}') - assert t.render() == '/static/yamlfile1;/static/yamlfile2;' - - os.remove('test.yaml') - - def test_from_python_module(self): - """Python configuration module gets loaded - """ - import types - module = types.ModuleType('test') - module.pytest = Bundle('pyfile1', 'pyfile2') - - self.env.from_module(module) - - t = self.app.jinja_env.from_string('{% assets "pytest" %}{{ASSET_URL}};{% endassets %}') - assert t.render() == '/static/pyfile1;/static/pyfile2;' + try: + env.from_yaml("test.yaml") + template = app.jinja_env.from_string('{% assets "yaml_test" %}{{ASSET_URL}};{% endassets %}') + assert template.render() == "/app_static/yaml_file1;/app_static/yaml_file2;" + finally: + os.remove("test.yaml") diff --git a/tests/test_integration.py b/tests/test_integration.py index 79842d8..aece12e 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1,257 +1,166 @@ -from __future__ import absolute_import +import os import pytest -from flask import Flask -from flask_assets import Environment, Bundle from webassets.bundle import get_all_bundle_files -from tests.helpers import TempEnvironmentHelper, Module, Blueprint +from flask_assets import Bundle +from tests.helpers import create_files, new_blueprint -def test_import(): - # We want to expose these via the assets extension module. - from flask_assets import Bundle - from flask_assets import Environment - +def test_directory_auto(app, env): + """Test how we resolve file references through the Flask static + system by default (if no custom 'env.directory' etc. values + have been configured manually). + """ + assert "directory" not in env.config + + assert get_all_bundle_files(Bundle("foo"), env) == [ + app.root_path + os.path.normpath("/static/foo") + ] + + # Blueprints prefixes in paths are handled specifically. + assert get_all_bundle_files(Bundle("bp/bar"), env) == [ + app.root_path + os.path.normpath("/bp_for_test/static/bar") + ] + + # Prefixes that aren't valid blueprint names are just considered + # sub-folders of the main app. + assert get_all_bundle_files(Bundle("app/bar"), env) == [ + app.root_path + os.path.normpath("/static/app/bar") + ] + + # In case the name of a app-level sub-folder conflicts with a + # module name, you can always use this hack: + assert get_all_bundle_files(Bundle("./bp_for_test/bar"), env) == [ + app.root_path + os.path.normpath("/static/bp_for_test/bar") + ] + + +def test_url_auto(app, env): + """Test how urls are generated via the Flask static system + by default (if no custom 'env.url' etc. values have been + configured manually). + """ + assert "url" not in env.config -class TestUrlAndDirectory(TempEnvironmentHelper): - """By default, the 'url' and 'directory' settings of webassets are - not used in Flask-Assets; that is, the values are automatically - handled based on the configuration of the Flask app and the modules - used. + assert Bundle("foo", env=env).urls() == ["/app_static/foo"] + # Urls for files that point to a blueprint use that blueprint"s url prefix. + assert Bundle("bp/bar", env=env).urls() == ["/bp_static/bar"] + # Try with a prefix which is not a blueprint. + assert Bundle("non-bp/bar", env=env).urls() == ["/app_static/non-bp/bar"] - The user can disable the automatic handling by setting these values - if he needs to for some reason. - Let's test the different scenarios to ensure everything works. +def test_custom_load_path(app, env, temp_dir): + """A custom load_path is configured - this will affect how + we deal with source files. """ - - def setup(self): - TempEnvironmentHelper.setup(self) - - self.app = Flask(__name__, static_url_path='/app_static') - from tests import test_module - if not Blueprint: - self.module = Module(test_module.__name__, name='module', - static_url_path='/mod_static') - self.app.register_module(self.module) - else: - self.blueprint = Blueprint('module', test_module.__name__, - static_url_path='/mod_static', - static_folder='static') - self.app.register_blueprint(self.blueprint) - self.env = Environment(self.app) - - def test_config_values_not_set_by_default(self): - assert not 'directory' in self.env.config - assert not 'url' in self.env.config - with pytest.raises(KeyError): - self.env.config['directory'] - with pytest.raises(KeyError): - self.env.config['url'] - - def test_directory_auto(self): - """Test how we resolve file references through the Flask static - system by default (if no custom 'env.directory' etc. values - have been configured manually). - """ - assert not 'directory' in self.env.config - root = self.app.root_path - assert get_all_bundle_files(Bundle('foo'), self.env) == [root + '/static/foo'] - # Modules prefixes in paths are handled specifically. - assert get_all_bundle_files(Bundle('module/bar'), self.env) == [root + '/test_module/static/bar'] - # Prefixes that aren't valid module names are just considered - # subfolders of the main app. - assert get_all_bundle_files(Bundle('nomodule/bar'), self.env) == [root + '/static/nomodule/bar'] - # In case the name of a app-level subfolder conflicts with a - # module name, you can always use this hack: - assert get_all_bundle_files(Bundle('./module/bar'), self.env) == [root + '/static/module/bar'] - - # Custom static folder - self.app.static_folder = '/test' - assert get_all_bundle_files(Bundle('foo'), self.env) == ['/test/foo'] - - def test_url_auto(self): - """Test how urls are generated via the Flask static system - by default (if no custom 'env.url' etc. values have been - configured manually). - """ - assert not 'url' in self.env.config - - assert Bundle('foo', env=self.env).urls() == ['/app_static/foo'] - # Urls for files that point to a module use that module's url prefix. - assert Bundle('module/bar', env=self.env).urls() == ['/mod_static/bar'] - # Try with a prefix that's not actually a valid module - assert Bundle('nomodule/bar', env=self.env).urls() == ['/app_static/nomodule/bar'] - - # [Regression] Ensure that any request context we may have added - # to the stack has been removed. - from flask import has_request_context - assert not has_request_context() - - def test_custom_load_path(self): - """A custom load_path is configured - this will affect how - we deal with source files. - """ - self.env.append_path(self.tempdir, '/custom/') - self.create_files(['foo', 'module/bar']) - assert get_all_bundle_files(Bundle('foo'), self.env) == [self.path('foo')] - # We do not recognize references to modules. - assert get_all_bundle_files(Bundle('module/bar'), self.env) == [self.path('module/bar')] - - - assert Bundle('foo', env=self.env).urls() == ['/custom/foo'] - assert Bundle('module/bar', env=self.env).urls() == ['/custom/module/bar'] - - # [Regression] With a load path configured, generating output - # urls still works, and it still uses the flask system. - self.env.debug = False - self.env.url_expire = False - assert Bundle('foo', output='out', env=self.env).urls() == ['/app_static/out'] - - def test_custom_directory_and_url(self): - """Custom directory/url are configured - this will affect how - we deal with output files.""" - # Create source source file, make it findable (by default, - # static_folder) is set to a fixed subfolder of the test dir (why?) - self.create_files({'a': ''}) - self.app.static_folder = self.tempdir - # Setup custom directory/url pair for output - self.env.directory = self.tempdir - self.env.url = '/custom' - self.env.debug = False # Return build urls - self.env.url_expire = False # No query strings - - assert Bundle('a', output='foo', env=self.env).urls() == ['/custom/foo'] - # We do not recognize references to modules. - assert Bundle('a', output='module/bar', env=self.env).urls() == ['/custom/module/bar'] - - def test_existing_request_object_used(self): - """[Regression] Check for a bug where the url generation code of - Flask-Assets always added a dummy test request to the context stack, - instead of using the existing one if there is one. - - We test this by making the context define a custom SCRIPT_NAME - prefix, and then we check if it affects the generated urls, as - it should. - """ - with self.app.test_request_context( - '/', environ_overrides={'SCRIPT_NAME': '/yourapp'}): - assert Bundle('foo', env=self.env).urls() == ['/yourapp/app_static/foo'] - - def test_glob(self): - """Make sure url generation works with globs.""" - self.app.static_folder = self.tempdir - self.create_files({'a.js': 'foo', 'b.js': 'bar'}) - assert list(sorted(self.mkbundle('*.js', env=self.env).urls())) == [ - '/app_static/a.js', '/app_static/b.js'] - - -class TestUrlAndDirectoryWithInitApp(object): - """[Regression] Make sure the automatic "directory" and "url" - values also work if the application is initialized via "init_app()". + env.append_path(temp_dir, "/custom/") + create_files(temp_dir, "foo", os.path.normpath("module/bar")) + assert get_all_bundle_files(Bundle("foo"), env) == [os.path.join(temp_dir, "foo")] + # We do not recognize references to modules. + assert get_all_bundle_files(Bundle("module/bar"), env) == [os.path.join(temp_dir, os.path.normpath("module/bar"))] + + assert Bundle("foo", env=env).urls() == ["/custom/foo"] + assert Bundle("module/bar", env=env).urls() == ["/custom/module/bar"] + + # [Regression] With a load path configured, generating output + # urls still works, and it still uses the flask system. + env.debug = False + env.url_expire = False + assert Bundle("foo", output="out", env=env).urls() == ["/app_static/out"] + + +def test_custom_directory_and_url(app, env, temp_dir): + """Custom directory/url are configured - this will affect how + we deal with output files.""" + # Create source source file, make it findable (by default, + # static_folder) is set to a fixed sub-folder of the test dir (why?) + create_files(temp_dir, "a") + app.static_folder = temp_dir + # Setup custom directory/url pair for output + env.directory = temp_dir + env.url = "/custom" + env.debug = False # Return build urls + env.url_expire = False # No query strings + + assert Bundle("a", output="foo", env=env).urls() == ["/custom/foo"] + # We do not recognize references to modules. + assert Bundle("a", output="module/bar", env=env).urls() == ["/custom/module/bar"] + + +def test_existing_request_object_used(app, env): + """Check for a bug where the url generation code of + Flask-Assets always added a dummy test request to the context stack, + instead of using the existing one if there is one. + + We test this by making the context define a custom SCRIPT_NAME + prefix, and then we check if it affects the generated urls, as + it should. """ + with app.test_request_context("/", environ_overrides={"SCRIPT_NAME": "/your_app"}): + assert Bundle("foo", env=env).urls() == ["/your_app/app_static/foo"] - def setup(self): - self.app = Flask(__name__, static_url_path='/initapp_static') - self.env = Environment() - self.env.init_app(self.app) - def test(self): - """Make sure the "url" and "directory" config values are - read from the Flask app. - """ - with self.app.test_request_context(): - assert not 'url' in self.env.config - assert Bundle('foo', env=self.env).urls() == ['/initapp_static/foo'] +def test_globals(app, env, temp_dir): + """Make sure url generation works with globals.""" + app.static_folder = temp_dir + create_files(temp_dir, "a.js", "b.js") + b = Bundle("*.js", env=env) + assert b.urls() == ["/app_static/a.js", "/app_static/b.js"] - assert not 'directory' in self.env.config - root = self.app.root_path - assert get_all_bundle_files(Bundle('foo'), self.env) == [root + '/static/foo'] +def test_blueprint_output(app, env, temp_dir): + """[Regression] Output can point to a blueprint's static directory.""" + bp1_static_folder = (temp_dir + os.path.sep + "bp1_static") + os.mkdir(bp1_static_folder) -class TestBuild(TempEnvironmentHelper): - """[Regression] + bp1 = new_blueprint("bp1", static_folder=bp1_static_folder) + app.register_blueprint(bp1) - Make sure actually building a bundle works also. - """ + app.static_folder = temp_dir + + with open(os.path.join(temp_dir, "foo"), "w", encoding="utf-8") as f: + f.write("function bla () { /* comment */ var a; } ") + + Bundle("foo", filters="rjsmin", output="bp1/out", env=env).build() + with open(os.path.join(bp1_static_folder, "out")) as f: + assert f.read() == "function bla(){var a;}" + + +def test_blueprint_urls(app, env): + """Urls to blueprint files are generated correctly.""" + # source urls + assert Bundle("bp/foo", env=env).urls() == ["/bp_static/foo"] + + # output urls - env settings are to not touch filesystem + env.auto_build = False + env.url_expire = False + assert Bundle(output="bp/out", debug=False, env=env).urls() == ["/bp_static/out"] + + +def test_blueprint_no_static_folder(app, env, temp_dir): + """Test dealing with a blueprint without a static folder.""" + bp2 = new_blueprint("bp2") + app.register_blueprint(bp2) + with pytest.raises(TypeError): + Bundle("bp2/foo", env=env).urls() + + +def test_cssrewrite(app, env, temp_dir): + """Make sure cssrewrite works with Blueprints.""" + bp3_static_folder = temp_dir + os.path.sep + "bp3_static" + os.mkdir(bp3_static_folder) + bp3 = new_blueprint("bp3", static_folder=bp3_static_folder, static_url_path="/w/u/f/f") + app.register_blueprint(bp3) + + path = create_files(temp_dir, os.path.normpath("bp3_static/css"))[0] + with open(path, "w", encoding="utf-8") as f: + f.write('h1{background: url("local")}') + + # Source file is in a blueprint, output file is app-level. + Bundle("bp3/css", filters="cssrewrite", output="out", env=env).build() - default_files = { - 'foo': 'function bla () { /* comment */ var a; } ', - } - - def test_build(self): - self.mkbundle('foo', filters='rjsmin', output='out').build() - assert self.get('out') == 'function bla(){var a;}' - - def test_with_cache_default_directory(self): - """[Regression] The cache directory is created in the Flask - main static folder. - """ - self.env.cache = True - self.mkbundle('foo', filters='rjsmin', output='out').build() - assert self.get('out') == 'function bla(){var a;}' - - -class TestBlueprints(TempEnvironmentHelper): - - default_files = { - 'foo': 'function bla () { /* comment */ var a; } ', - } - - def make_blueprint(self, name='module', import_name=None, **kw): - if not import_name: - from tests import test_module - import_name = test_module.__name__ - - if not Blueprint: - self.module = Module(import_name, name=name) - self.app.register_module(self.module) - else: - self.blueprint = Blueprint(name, import_name, **kw) - self.app.register_blueprint(self.blueprint) - - def test_blueprint_output(self): - """[Regression] Output can point to a blueprint's static - directory. - """ - module_static_dir = self.create_directories('module-static')[0] - self.make_blueprint('module', static_folder=module_static_dir) - self.mkbundle('foo', filters='rjsmin', output='module/out').build() - assert self.get('module-static/out') == 'function bla(){var a;}' - - def test_blueprint_urls(self): - """Urls to blueprint files are generated correctly.""" - self.make_blueprint('module', static_folder='static', - static_url_path='/rasputin') - - # source urls - assert self.mkbundle('module/foo').urls() == ['/rasputin/foo'] - - # output urls - env settings are to not touch filesystem - self.env.auto_build = False - self.env.url_expire = False - assert self.mkbundle(output='module/out', debug=False).urls() == ['/rasputin/out'] - - def test_blueprint_no_static_folder(self): - """Test dealing with a blueprint without a static folder.""" - self.make_blueprint('module') - with pytest.raises(TypeError): - self.mkbundle('module/foo').urls() - - def test_cssrewrite(self): - """Make sure cssrewrite works with Blueprints. - """ - - module_static_dir = self.create_directories('modfolder')[0] - self.make_blueprint('modname', static_folder=module_static_dir, - static_url_path='/w/u/f/f') - self.create_files( - {'modfolder/css': 'h1{background: url("local")}'}) - - # Source file is in a Blueprint, output file is app-level. - self.mkbundle('modname/css', filters='cssrewrite', output='out').build() - - # The urls are NOT rewritten using the filesystem (/modfolder), but - # within the url space. - assert self.get('out') == 'h1{background: url("../w/u/f/f/local")}' + # The urls are NOT rewritten using the filesystem, but + # within the url space. + with open(os.path.join(app.static_folder, "out"), "r") as f: + assert f.read() == 'h1{background: url("../w/u/f/f/local")}'