diff --git a/invenio_theme_tugraz/__init__.py b/invenio_theme_tugraz/__init__.py index 79d9f7e..985f569 100644 --- a/invenio_theme_tugraz/__init__.py +++ b/invenio_theme_tugraz/__init__.py @@ -8,7 +8,7 @@ """invenio module for TUGRAZ theme.""" -from .ext import inveniothemetugraz +from .ext import InvenioThemeTugraz from .version import __version__ -__all__ = ('__version__', 'inveniothemetugraz') +__all__ = ('__version__', 'InvenioThemeTugraz') diff --git a/invenio_theme_tugraz/ext.py b/invenio_theme_tugraz/ext.py index e645d62..74a721a 100644 --- a/invenio_theme_tugraz/ext.py +++ b/invenio_theme_tugraz/ext.py @@ -13,7 +13,7 @@ from flask_babelex import gettext as _ from . import config -class inveniothemetugraz(object): +class InvenioThemeTugraz(object): """invenio-theme-tugraz extension.""" def __init__(self, app=None): diff --git a/setup.py b/setup.py index 0f37061..791b3ca 100644 --- a/setup.py +++ b/setup.py @@ -79,7 +79,7 @@ setup( platforms='any', entry_points={ 'invenio_base.apps': [ - 'invenio_theme_tugraz = invenio_theme_tugraz:inveniothemetugraz', + 'invenio_theme_tugraz = invenio_theme_tugraz:InvenioThemeTugraz', ], 'invenio_base.blueprints': [ 'invenio_theme_tugraz = invenio_theme_tugraz.views:blueprint', diff --git a/tests/conftest.py b/tests/conftest.py index deda3d4..e1ddaa7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,31 +12,21 @@ See https://pytest-invenio.readthedocs.io/ for documentation on which test fixtures are available. """ +import os import shutil import tempfile import pytest from flask import Flask from flask_babelex import Babel +from invenio_db import InvenioDB, db from invenio_i18n import InvenioI18N +from invenio_search import InvenioSearch -from invenio_theme_tugraz import inveniothemetugraz +from invenio_theme_tugraz import InvenioThemeTugraz from invenio_theme_tugraz.views import blueprint -@pytest.fixture() -def app(): - """Flask app fixture.""" - app = Flask('myapp') - app.config.update( - I18N_LANGUAGES=[('en', 'English'), ('de', 'German')], - ) - Babel(app) - InvenioI18N(app) - app.register_blueprint(create_blueprint_from_app(app)) - return app - - @pytest.fixture(scope='module') def celery_config(): """Override pytest-invenio fixture. @@ -46,14 +36,37 @@ def celery_config(): return {} -@pytest.fixture(scope='module') -def create_app(instance_path): - """Application factory fixture.""" - def factory(**config): - app = Flask('testapp', instance_path=instance_path) - app.config.update(**config) - Babel(app) - inveniothemetugraz(app) - app.register_blueprint(blueprint) - return app - return factory +@pytest.fixture() +def app(request): + """Basic Flask application.""" + instance_path = tempfile.mkdtemp() + app = Flask("testapp") + DB = os.getenv("SQLALCHEMY_DATABASE_URI", "sqlite://") + app.config.update( + I18N_LANGUAGES=[('en', 'English'), ('de', 'German')], + SQLALCHEMY_DATABASE_URI=DB, + SQLALCHEMY_TRACK_MODIFICATIONS=False, + ) + Babel(app) + InvenioDB(app) + InvenioSearch(app) + InvenioThemeTugraz(app) + + with app.app_context(): + db_url = str(db.engine.url) + if db_url != "sqlite://" and not database_exists(db_url): + create_database(db_url) + db.create_all() + + def teardown(): + with app.app_context(): + db_url = str(db.engine.url) + db.session.close() + if db_url != "sqlite://": + drop_database(db_url) + shutil.rmtree(instance_path) + + request.addfinalizer(teardown) + app.test_request_context().push() + + return app diff --git a/tests/test_invenio_theme_tugraz.py b/tests/test_invenio_theme_tugraz.py index 462cbbd..bf4d9e6 100644 --- a/tests/test_invenio_theme_tugraz.py +++ b/tests/test_invenio_theme_tugraz.py @@ -10,7 +10,7 @@ from flask import Flask -from invenio_theme_tugraz import inveniothemetugraz +from invenio_theme_tugraz import InvenioThemeTugraz def test_version(): @@ -22,11 +22,16 @@ def test_version(): def test_init(): """Test extension initialization.""" app = Flask('testapp') - ext = inveniothemetugraz(app) + ext = InvenioThemeTugraz(app) assert 'invenio-theme-tugraz' in app.extensions app = Flask('testapp') - ext = inveniothemetugraz() + ext = InvenioThemeTugraz() assert 'invenio-theme-tugraz' not in app.extensions ext.init_app(app) assert 'invenio-theme-tugraz' in app.extensions + + +def test_app(app): + """Test extension initialization.""" + theme = InvenioThemeTugraz(app)