def test_app_config_is_overridden_by_local_conf_with_multiple_paths(self): self.app.config['SCSS_LOAD_PATHS'].append('foo') scss = flask_scss.Scss(self.app, load_paths=['bar', 'baz']) self.assertIn(pathlib.Path(os.getcwd(), 'bar'), scss.compiler.search_path) self.assertIn(pathlib.Path(os.getcwd(), 'baz'), scss.compiler.search_path)
def test_discover_scss(self): self.set_layout() self.create_asset_file('foo.scss') self.create_asset_file('foo.txt') scss_inst = flask_scss.Scss(self.app) scss_inst.discover_scss() self.assertIn(op.join(self.asset_dir, 'foo.scss'), scss_inst.assets) self.assertNotIn(op.join(self.asset_dir, 'foo.txt'), scss_inst.assets)
def test_local_static_dir_must_override_app_conf(self): static_scss_dir = op.join(self.test_data, 'static', 'bar') static_scss_dir2 = op.join(self.test_data, 'static2', 'bar') self.app.config['SCSS_STATIC_DIR'] = static_scss_dir os.makedirs(static_scss_dir) os.makedirs(static_scss_dir2) scss_inst = flask_scss.Scss(self.app, static_dir=static_scss_dir2) self.assertEqual(scss_inst.static_dir, static_scss_dir2)
def test_local_asset_dir_must_override_app_conf(self): asset_scss_dir = op.join(self.test_data, 'assets', 'bar') asset_scss_dir2 = op.join(self.test_data, 'assets2', 'bar') self.app.config['SCSS_ASSET_DIR'] = asset_scss_dir os.makedirs(asset_scss_dir) os.makedirs(asset_scss_dir2) scss_inst = flask_scss.Scss(self.app, asset_dir=asset_scss_dir2) self.assertEqual(scss_inst.asset_dir, asset_scss_dir2)
def test_it_looks_for_an_app_load_path_settings_with_multiple_paths(self): paths = ['foo', 'bar'] for path in paths: self.app.config['SCSS_LOAD_PATHS'].append(path) scss = flask_scss.Scss(self.app) for path in paths: self.assertIn(pathlib.Path(os.getcwd(), path), scss.compiler.search_path)
def test_scss_discovery_is_recursive(self): self.set_layout() self.create_asset_file('foo.scss') asset_scss_dir = op.join(self.test_data, 'assets', 'bar') self.create_asset_file('bar/baz.scss') scss_inst = flask_scss.Scss(self.app) scss_inst.discover_scss() self.assertIn(op.join(self.test_data, 'assets', 'bar', 'baz.scss'), scss_inst.assets)
def test_asset_tree_is_kept_in_static_dir(self): self.set_layout() asset_scss_dir = op.join(self.test_data, 'assets', 'bar') os.makedirs(asset_scss_dir) self.create_asset_file('bar/baz.scss') scss_inst = flask_scss.Scss(self.app) scss_inst.discover_scss() asset = op.join(self.test_data, 'assets', 'bar', 'baz.scss') expected_dest = op.join(self.test_data, 'static', 'bar', 'baz.css') self.assertEqual(expected_dest, scss_inst.assets[asset], "css folder not kept")
def setup(app): # public configs, from config.yaml with open('config.yaml', 'r') as config_file: app.config.update(yaml.load(config_file)) app.config['DEBUG'] = distutils.util.strtobool(ENV.get('DEBUG', False)) # extensions flask_misaka.Misaka(app) flask_scss.Scss(app, static_dir='static', asset_dir='static') cache = Cache(app, config={'CACHE_TYPE': 'simple'}) return cache
def test_compile_scss_creates_subfolders_if_necessary(self): self.set_layout() asset_scss_dir = op.join(self.test_data, 'assets', 'bar') os.makedirs(asset_scss_dir) self.create_asset_file('bar/baz.scss') self.create_asset_file('foo.scss') op.join(self.test_data, 'assets', 'bar', 'baz.scss') expected_dest = op.join(self.test_data, 'static', 'bar', 'baz.css') scss_inst = flask_scss.Scss(self.app) scss_inst.update_scss() self.assertTrue(os.path.exists(expected_dest)) self.assertTrue(os.path.exists(os.path.join(self.test_data, 'static', 'foo.css')))
def test_update_scss_nothing_to_update(self): self.set_layout() css_path = self.create_static_file('foo.css') scss_path = self.create_asset_file('foo.scss') os.utime(scss_path, (time.time() - 10, time.time() - 10)) os.utime(css_path, (time.time() - 5, time.time() - 5)) scss_inst = flask_scss.Scss(self.app) # check that the css file is newer than the scss file self.assertGreater(op.getmtime(css_path), op.getmtime(scss_path)) scss_inst.update_scss() #verifies that css file has been modified self.assertGreater(op.getmtime(css_path), op.getmtime(scss_path)) # verifies that the content of the css file has NOT changed with open(css_path) as css_file: css_content = css_file.read() self.assertEqual(css_content, "nothing")
def test_update_scss_with_unicode_content(self): self.set_layout() css_path = self.create_static_file('foo.css') scss_path = self.create_asset_file('foo.scss', content=SCSS_UNICODE_CONTENT) os.utime(css_path, (time.time() - 10, time.time() - 10)) os.utime(scss_path, (time.time() - 5, time.time() - 5)) scss_inst = flask_scss.Scss(self.app) # check that the css file is older than the scss file self.assertGreater(op.getmtime(scss_path), op.getmtime(css_path)) scss_inst.update_scss() #verifies that css file has been modified self.assertGreater(op.getmtime(css_path), op.getmtime(scss_path)) # verifies that the content of the css file has changed with open(css_path) as css_file: css_content = css_file.read() self.assertIn("๛", css_content)
def create_app(config=None): app = flask.Flask( 'scoreboard', static_folder='../static', template_folder='../templates', ) app.config.from_object('scoreboard.config_defaults.Defaults') if config is not None: app.config.update(**config) if not on_appengine(): # Configure Scss to watch the files scss_compiler = flask_scss.Scss( app, static_dir='static/css', asset_dir='static/scss') scss_compiler.update_scss() for c in exceptions.default_exceptions.iterkeys(): app.register_error_handler(c, api_error_handler) setup_logging(app) return app
def test_css_is_refreshed_if_partials_are_updated(self): self.set_layout() css_must_be_compiled_path = self.create_static_file('foo.css') scss_path = self.create_asset_file('foo.scss') scss_partial_path = self.create_asset_file('_bar.scss') scss_inst = flask_scss.Scss(self.app) os.utime(scss_partial_path, (time.time() - 25, time.time() - 25)) scss_inst.discover_scss() os.utime(scss_partial_path, (time.time() - 5, time.time() - 5)) os.utime(scss_path, (time.time() - 15, time.time() - 15)) os.utime(css_must_be_compiled_path, (time.time() - 10, time.time() - 10)) self.assertGreater(op.getmtime(css_must_be_compiled_path), op.getmtime(scss_path)) self.assertGreater(op.getmtime(scss_partial_path), op.getmtime(css_must_be_compiled_path)) scss_inst.update_scss() self.assertGreater(op.getmtime(css_must_be_compiled_path), op.getmtime(scss_path)) self.assertGreater(op.getmtime(css_must_be_compiled_path), op.getmtime(scss_partial_path), "not refreshed") with open(css_must_be_compiled_path) as file_in: css_newer_content = file_in.read() self.assertNotEqual(css_newer_content, "nothing")
def test_update_scss_update_only_changed_scss_files(self): self.set_layout() css_must_be_compiled_path = self.create_static_file('foo.css') css_must_not_change_path = self.create_static_file('bar.css') scss_newer_path = self.create_asset_file('foo.scss') scss_older_path = self.create_asset_file('bar.scss') os.utime(scss_older_path, (time.time() - 10, time.time() - 10)) os.utime(css_must_not_change_path, (time.time() - 5, time.time() - 5)) os.utime(scss_newer_path, (time.time() - 5, time.time() - 5)) os.utime(css_must_be_compiled_path, (time.time() - 10, time.time() - 10)) scss_inst = flask_scss.Scss(self.app) self.assertGreater(op.getmtime(css_must_not_change_path), op.getmtime(scss_older_path)) self.assertGreater(op.getmtime(scss_newer_path), op.getmtime(css_must_be_compiled_path)) scss_inst.update_scss() self.assertGreater(op.getmtime(css_must_not_change_path), op.getmtime(scss_older_path)) self.assertGreater(op.getmtime(css_must_be_compiled_path), op.getmtime(scss_newer_path)) with open(css_must_not_change_path) as file_in: css_older_content = file_in.read() self.assertEqual(css_older_content, "nothing") with open(css_must_be_compiled_path) as file_in: css_newer_content = file_in.read() self.assertNotEqual(css_newer_content, "nothing")
def test_set_asset_dir_from_app_conf(self): asset_scss_dir = op.join(self.test_data, 'assets', 'bar') self.app.config['SCSS_ASSET_DIR'] = asset_scss_dir os.makedirs(asset_scss_dir) scss_inst = flask_scss.Scss(self.app) self.assertEqual(scss_inst.asset_dir, asset_scss_dir)
def test_set_asset_dir_user_input(self): asset_scss_dir = op.join(self.test_data, 'assets2', 'scss') os.makedirs(asset_scss_dir) scss_inst = flask_scss.Scss(self.app, asset_dir=op.join(self.test_data, 'assets2')) self.assertEqual(scss_inst.asset_dir, asset_scss_dir)
def test_set_asset_dir_none(self): scss_inst = flask_scss.Scss(self.app) self.assertIsNone(scss_inst.asset_dir)
def test_set_asset_dir_assets(self): asset_dir = op.join(self.test_data, 'assets') os.makedirs(asset_dir) scss_inst = flask_scss.Scss(self.app) self.assertEqual(scss_inst.asset_dir, asset_dir)
def test_set_static_dir_from_app_conf(self): static_scss_dir = op.join(self.test_data, 'static', 'bar') self.app.config['SCSS_STATIC_DIR'] = static_scss_dir os.makedirs(static_scss_dir) scss_inst = flask_scss.Scss(self.app) self.assertEqual(scss_inst.static_dir, static_scss_dir)
def test_set_hooks_no_asset_dir(self): static_dir = op.join(self.test_data, 'static') os.makedirs(static_dir) flask_scss.Scss(self.app) self.assertFalse(self.app.before_request.called)
def test_the_asset_dir_is_in_the_load_path(self): self.set_layout() inst = flask_scss.Scss(self.app, load_paths=['bar', 'baz']) self.assertIn(pathlib.Path(inst.asset_dir), inst.compiler.search_path)
def test_set_hooks_ok(self): self.set_layout() scss_inst = flask_scss.Scss(self.app) self.assertTrue(self.app.before_request.called) self.assertEqual(self.app.before_request.call_count, 1) self.app.before_request.assert_called_with(scss_inst.update_scss)
def test_partial_scss_are_considered_partials(self): self.set_layout() self.create_asset_file('_bar.scss') scss_inst = flask_scss.Scss(self.app) scss_inst.discover_scss() self.assertIn(op.join(self.asset_dir, '_bar.scss'), scss_inst.partials)
def test_it_looks_for_an_app_load_path_settings(self): self.app.config['SCSS_LOAD_PATHS'].append('foo') scss = flask_scss.Scss(self.app) self.assertIn(pathlib.Path(os.getcwd(), 'foo'), scss.compiler.search_path)
def test_set_static_dir_user_input(self): static_css_dir = op.join(self.test_data, 'static2', 'css') os.makedirs(static_css_dir) scss_inst = flask_scss.Scss(self.app, static_dir=op.join(self.test_data, 'static2')) self.assertEqual(scss_inst.static_dir, static_css_dir)
#import flask_profiler import flask_scss from peewee import * from playhouse.sqlite_ext import * from gerby.configuration import * from gerby.database import * db.init(DATABASE) # Flask setup code app = Flask(__name__) app.config.from_object(__name__) flask_scss.Scss(app, static_dir="gerby/static/css", asset_dir="gerby/assets") #app.config["flask_profiler"] = { # "enabled": "true", # "storage": { # "engine": "sqlite" # }, # "basicAuth": { # "enabled": False, # }, # "ignore": ["^/static/.*"] #} @app.route("/kerodon.pdf") def download_file():
def test_it_sets_up_refresh_hooks_if_application_is_in_debug_and_testing_mode(self): self.app.testing = True self.app.debug = True with patch.object(flask_scss.Scss, 'set_hooks') as mock_set_hooks: flask_scss.Scss(self.app) self.assertTrue(mock_set_hooks.called)
def test_it_does_not_set_up_refresh_hooks_if_application_is_not_in_debug_or_testing_mode(self): self.app.testing = False self.app.debug = False with patch.object(flask_scss.Scss, 'set_hooks') as mock_set_hooks: flask_scss.Scss(self.app) self.assertFalse(mock_set_hooks.called)
def test_set_static_dir_static(self): static_dir = op.join(self.test_data, 'static') os.makedirs(static_dir) scss_inst = flask_scss.Scss(self.app) self.assertEqual(scss_inst.static_dir, static_dir)