global: extension class to uppercase. (#105)

The extension class name is changed to uppercase.
This commit is contained in:
Mojib Wali
2020-10-12 09:42:12 +02:00
committed by GitHub
parent c5edf62a9d
commit f9993369f2
5 changed files with 50 additions and 32 deletions

View File

@@ -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')

View File

@@ -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):

View File

@@ -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',

View File

@@ -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

View File

@@ -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)