diff --git a/flask_bootstrap/__init__.py b/flask_bootstrap/__init__.py index d8fdd68e..c87323a6 100644 --- a/flask_bootstrap/__init__.py +++ b/flask_bootstrap/__init__.py @@ -7,7 +7,7 @@ """ from flask import current_app, Markup, Blueprint, url_for -try: +try: # pragma: no cover from wtforms.fields import HiddenField except ImportError: def is_hidden_field_filter(field): diff --git a/setup.cfg b/setup.cfg index 445c46c9..de9602f1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,6 +7,11 @@ universal = 1 [coverage:run] source = flask_bootstrap +[coverage:report] +exclude_lines = + pragma: no cover + except ImportError: + [flake8] exclude = static,.git,*migrations*,build,.tox,docs max-line-length = 119 @@ -20,5 +25,4 @@ tests_require = pytest test = pytest [tool:pytest] -addopts = --verbose testpaths = tests \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index ebd09f83..b09e315b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,16 +18,6 @@ def hello_form(): return HelloForm -@pytest.fixture -def bootswatch_themes(): - themes = [ - 'cerulean', 'cosmo', 'cyborg', 'darkly', 'default', 'flatly', 'journal', 'litera', - 'lumen', 'lux', 'materia', 'minty', 'pulse', 'sandstone', 'simplex', 'sketchy', 'slate', - 'solar', 'spacelab', 'superhero', 'united', 'yeti' - ] - return themes - - @pytest.fixture(autouse=True) def app(): app = Flask(__name__) diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 1ed55a1b..1c266cbe 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -1,19 +1,21 @@ +import pytest from flask import current_app -class TestBootstrap(object): - def test_extension_init(self, client, bootstrap): +@pytest.mark.usefixtures('client') +class TestBootstrap: + def test_extension_init(self, bootstrap): assert 'bootstrap' in current_app.extensions - def test_load_css(self, client, bootstrap): + def test_load_css(self, bootstrap): rv = bootstrap.load_css() assert 'bootstrap.min.css' in rv - def test_load_js(self, client, bootstrap): + def test_load_js(self, bootstrap): rv = bootstrap.load_js() assert 'bootstrap.min.js' in rv - def test_local_resources(self, client, bootstrap): + def test_local_resources(self, bootstrap, client): current_app.config['BOOTSTRAP_SERVE_LOCAL'] = True response = client.get('/') @@ -37,7 +39,7 @@ def test_local_resources(self, client, bootstrap): assert 'https://cdn.jsdelivr.net/npm/bootstrap' not in css_rv assert 'https://cdn.jsdelivr.net/npm/bootstrap' not in js_rv - def test_cdn_resources(self, client, bootstrap): + def test_cdn_resources(self, bootstrap, client): current_app.config['BOOTSTRAP_SERVE_LOCAL'] = False response = client.get('/') @@ -53,26 +55,19 @@ def test_cdn_resources(self, client, bootstrap): assert '/bootstrap/static/js/bootstrap.min.js' not in js_rv assert 'https://cdn.jsdelivr.net/npm/bootstrap' in css_rv assert 'https://cdn.jsdelivr.net/npm/bootstrap' in js_rv - - def test_bootswatch_local(self, client, bootswatch_themes): + + @pytest.mark.parametrize( + ['with_jquery', 'with_popper'], + [ + (True, True), + (False, False), + (True, False), + (False, True), + ] + ) + def test_load_js_args(self, with_jquery, with_popper, bootstrap, client): current_app.config['BOOTSTRAP_SERVE_LOCAL'] = True + js_rv = bootstrap.load_js(with_jquery=with_jquery, with_popper=with_popper) - for theme in bootswatch_themes: - current_app.config['BOOTSTRAP_BOOTSWATCH_THEME'] = theme - data = client.get('/').get_data(as_text=True) - assert 'https://cdn.jsdelivr.net/npm/bootswatch' not in data - assert 'swatch/%s/bootstrap.min.css' % theme in data - with client.get('/bootstrap/static/css/swatch/%s/bootstrap.min.css' % theme) as css_response: - assert css_response.status_code != 404 - - def test_bootswatch_cdn(self, client, bootstrap, bootswatch_themes): - current_app.config['BOOTSTRAP_SERVE_LOCAL'] = False - - for theme in bootswatch_themes: - current_app.config['BOOTSTRAP_BOOTSWATCH_THEME'] = theme - data = client.get('/').get_data(as_text=True) - assert 'https://cdn.jsdelivr.net/npm/bootswatch' in data - assert 'dist/%s/bootstrap.min.css' % theme in data - css_rv = bootstrap.load_css() - assert '/bootstrap/static/css/swatch/%s/bootstrap.min.css' % theme not in data - assert 'https://cdn.jsdelivr.net/npm/bootswatch' in css_rv + assert ('jquery.min.js' in js_rv) == with_jquery + assert ('popper.min.js' in js_rv) == with_popper diff --git a/tests/test_render.py b/tests/test_render.py deleted file mode 100644 index c75deccd..00000000 --- a/tests/test_render.py +++ /dev/null @@ -1,680 +0,0 @@ -from flask import current_app, flash, render_template_string, request -from flask_sqlalchemy import SQLAlchemy -from flask_wtf import FlaskForm -from wtforms import BooleanField, FileField, HiddenField, MultipleFileField,\ - PasswordField, RadioField, StringField, SubmitField -from wtforms.validators import DataRequired - - -class TestRender(object): - def test_render_field(self, app, client, hello_form): - @app.route('/field') - def test(): - form = hello_form() - return render_template_string(''' - {% from 'bootstrap/form.html' import render_field %} - {{ render_field(form.username) }} - {{ render_field(form.password) }} - ''', form=form) - - response = client.get('/field') - data = response.get_data(as_text=True) - assert '' in data - assert '
' in data - - def test_render_form_row_row_class(self, app, client, hello_form): - @app.route('/form') - def test(): - form = hello_form() - return render_template_string(''' - {% from 'bootstrap/form.html' import render_form_row %} - {{ render_form_row([form.username, form.password], row_class='row') }} - ''', form=form) - response = client.get('/form') - data = response.get_data(as_text=True) - assert '
' in data - - def test_render_form_row_col_class_default(self, app, client, hello_form): - @app.route('/form') - def test(): - form = hello_form() - return render_template_string(''' - {% from 'bootstrap/form.html' import render_form_row %} - {{ render_form_row([form.username, form.password], col_class_default='col-md-6') }} - ''', form=form) - response = client.get('/form') - data = response.get_data(as_text=True) - assert '
' in data - - def test_render_form_row_col_map(self, app, client, hello_form): - @app.route('/form') - def test(): - form = hello_form() - return render_template_string(''' - {% from 'bootstrap/form.html' import render_form_row %} - {{ render_form_row([form.username, form.password], col_map={'username': 'col-md-6'}) }} - ''', form=form) - response = client.get('/form') - data = response.get_data(as_text=True) - assert '
' in data - assert '
' in data - - def test_render_pager(self, app, client): - db = SQLAlchemy(app) - - class Message(db.Model): - id = db.Column(db.Integer, primary_key=True) - - @app.route('/pager') - def test(): - db.drop_all() - db.create_all() - for i in range(100): - m = Message() - db.session.add(m) - db.session.commit() - page = request.args.get('page', 1, type=int) - pagination = Message.query.paginate(page, per_page=10) - messages = pagination.items - return render_template_string(''' - {% from 'bootstrap/pagination.html' import render_pager %} - {{ render_pager(pagination) }} - ''', pagination=pagination, messages=messages) - - response = client.get('/pager') - data = response.get_data(as_text=True) - assert '