Skip to content

Commit

Permalink
global: configuration and test cleanup
Browse files Browse the repository at this point in the history
* Improves code style and fixes failing tests.  (closes #1)

Signed-off-by: Jiri Kuncar <jiri.kuncar@cern.ch>
  • Loading branch information
jirikuncar committed Oct 7, 2015
1 parent c9f8669 commit ece151d
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 32 deletions.
9 changes: 8 additions & 1 deletion .travis.invenio.cfg
Expand Up @@ -21,6 +21,8 @@

import getpass

from invenio_base.config import EXTENSIONS as _EXTENSIONS

CFG_BIBSCHED_PROCESS_USER = getpass.getuser()

DEBUG = False
Expand All @@ -29,10 +31,15 @@ SECRET_KEY = 'MY_SECRET'
# Disable all automatic asset building - false is /usr/bin/false.
ASSETS_AUTO_BUILD = False

# Disable search query enhancers
SEARCH_QUERY_ENHANCERS = []

PACKAGES = [
'invenio_oauth2server',
'invenio_search',
'invenio_collections',
'invenio_access',
'invenio_accounts',
'invenio_base',
]

EXTENSIONS = _EXTENSIONS + ['invenio_ext.es']
6 changes: 5 additions & 1 deletion invenio_ext/arxiv/__init__.py
Expand Up @@ -161,7 +161,11 @@ def search(self, arxiv=None):

# query the database
result = get_unique_record_json(
"\"{0}{1}\"".format(self.app.config.get("ARXIV_SEARCH_PREFIX", ""), arxiv))
"\"{0}{1}\"".format(
self.app.config.get(
"ARXIV_SEARCH_PREFIX",
""),
arxiv))
if result["status"] == "notfound":
# query arxiv
result = self.get_json(arxiv)
Expand Down
1 change: 1 addition & 0 deletions invenio_ext/email/__init__.py
Expand Up @@ -60,6 +60,7 @@ def getContentType(pageUrl):
contentType = pageHeaders.getheader('content-type')
return contentType


def setup_app(app):
"""
Prepare application config from Invenio configuration.
Expand Down
10 changes: 4 additions & 6 deletions invenio_ext/email/backends/console_adminonly.py
Expand Up @@ -17,17 +17,15 @@
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

"""
Invenio Admin mail backend. send_email() will send emails only to
CFG_SITE_ADMIN_EMAIL.
"""
"""Invenio Admin mail backend.
__revision__ = "$Id$"
send_email() will send emails only to CFG_SITE_ADMIN_EMAIL.
"""

from flask_email.backends.console import Mail as Console

from . import adminonly_class

Mail = adminonly_class(Console)

__all__ = ['Mail']
__all__ = ('Mail', )
8 changes: 3 additions & 5 deletions invenio_ext/email/backends/smtp_adminonly.py
Expand Up @@ -17,12 +17,10 @@
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

"""
Invenio Admin mail backend. send_email() will send emails only to
CFG_SITE_ADMIN_EMAIL.
"""
"""Invenio Admin SMTP mail backend.
__revision__ = "$Id$"
send_email() will send emails only to CFG_SITE_ADMIN_EMAIL.
"""

from flask_email.backends.smtp import Mail as SMTP

Expand Down
4 changes: 2 additions & 2 deletions invenio_ext/logging/wrappers.py
Expand Up @@ -85,8 +85,8 @@ def get_traceback():
'file': trace_tuple[0],
'line': trace_tuple[1],
'function': trace_tuple[2],
'text': trace_tuple[3] is not None
and str(trace_tuple[3]) or ""
'text': trace_tuple[3] is not None and
str(trace_tuple[3]) or ""
}
return traceback_pretty

Expand Down
1 change: 0 additions & 1 deletion invenio_ext/login/legacy_user.py
Expand Up @@ -189,7 +189,6 @@ def _precache(self, info, force=False):
user_info.update(self.req)
user = User.query.get(user_info['uid'])


data = {}
data['precached_useadmin'] = getattr(user, 'has_admin_role', False)
data['precached_usesuperadmin'] = getattr(
Expand Down
4 changes: 2 additions & 2 deletions invenio_ext/restful/__init__.py
Expand Up @@ -111,8 +111,8 @@ def get_errors(self):
error_to_append = dict(
code=validation_errors['INCORRECT_TYPE']['error_code'],
message=(
validation_errors['INCORRECT_TYPE']['error_mesg']
+ ": " + "'" + key + "' " + msg_error
validation_errors['INCORRECT_TYPE']['error_mesg'] +
": " + "'" + key + "' " + msg_error
),
field=key
)
Expand Down
4 changes: 2 additions & 2 deletions invenio_ext/sso/__init__.py
Expand Up @@ -91,8 +91,8 @@ def fetch_groups(groups):
for group in groups:
if regexp.match(group):
groups.remove(group)
return dict(map(lambda x: (x, '@' in x and x + ' (Mailing list)'
or x + ' (Group)'), groups))
return dict(map(lambda x: (x, '@' in x and x + ' (Mailing list)' or
x + ' (Group)'), groups))

def fetch_external(external):
return '0' if external in ('CERN Registered', 'CERN Shared') else '1'
Expand Down
3 changes: 2 additions & 1 deletion invenio_ext/template/loader.py
Expand Up @@ -36,7 +36,8 @@
# Deprecated in Flask commit 817b72d484d353800d907b3580c899314bf7f3c6
from flask.templating import blueprint_is_module
except ImportError:
blueprint_is_module = lambda blueprint: False
def blueprint_is_module(blueprint):
return False


class OrderAwareDispatchingJinjaLoader(DispatchingJinjaLoader):
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Expand Up @@ -25,4 +25,5 @@
[pytest]
addopts = --pep8 --ignore=docs --cov=invenio_ext --cov-report=term-missing
pep8ignore =
* E501
tests/* ALL
2 changes: 2 additions & 0 deletions requirements-devel.txt
Expand Up @@ -27,6 +27,8 @@
-e git+git://github.com/inveniosoftware/invenio-base.git#egg=invenio-base
-e git+git://github.com/inveniosoftware/invenio-celery.git#egg=invenio-celery
-e git+git://github.com/inveniosoftware/invenio-collections.git#egg=invenio-collections
-e git+git://github.com/inveniosoftware/invenio-knowledge.git#egg=invenio-knowledge
-e git+git://github.com/inveniosoftware/invenio-oauth2server.git#egg=invenio-oauth2server
-e git+git://github.com/inveniosoftware/invenio-search.git#egg=invenio-search
-e git+git://github.com/inveniosoftware/invenio-testing.git#egg=invenio-testing
-e git+git://github.com/inveniosoftware/invenio-utils.git#egg=invenio-utils
15 changes: 8 additions & 7 deletions setup.py
Expand Up @@ -61,8 +61,8 @@
'elasticsearch>=1.3.0',
'fixture>=1.5',
'intbitset>=2.0.0',
'invenio-base>=0.3.0',
'invenio-celery>=0.1.0',
'invenio-base>=0.3.1',
'invenio-celery>=0.1.1',
'invenio-utils>=0.2.0',
'lxml>=3.3',
# FIXME new oauthlib release after 0.7.2 has some compatible problems with
Expand All @@ -81,12 +81,13 @@
'coverage>=4.0.0',
'Flask-SSO>=0.2',
'httpretty>=0.8.10',
'invenio-access>=0.1.0',
'invenio-accounts>=0.1.2',
'invenio-collections>=0.1.2',
'invenio-oauth2server>=0.1.1',
'invenio-access>=0.2.0',
'invenio-accounts>=0.2.0',
'invenio-collections>=0.2.0',
'invenio-records>=0.3.4.post1',
'invenio-oauth2server>=0.2.0',
'invenio-testing>=0.1.1',
'mock>=1.0.0',
'mock>=1.0.1',
'pytest>=2.8.0',
'pytest-cov>=2.1.0',
'pytest-isort>=0.1.0',
Expand Down
4 changes: 0 additions & 4 deletions tests/test_ext_arxiv.py
Expand Up @@ -43,11 +43,7 @@ class ArxivMixin(InvenioTestCase):
@property
def config(self):
"""Remove Arxiv from extensions to get full control of the test."""
from invenio_base.config import EXTENSIONS
cfg = super(ArxivMixin, self).config
cfg["EXTENSIONS"] = filter(
lambda k: not k.startswith("invenio_ext.arxiv"),
EXTENSIONS)
cfg["ARXIV_API_URL"] = "http://export.example.org/oai2"
cfg["CACHE_TYPE"] = "simple"
return cfg
Expand Down
16 changes: 16 additions & 0 deletions tests/test_ext_email.py
Expand Up @@ -33,11 +33,21 @@

from invenio_testing import InvenioTestCase

from mock import patch

import pkg_resources

from six import StringIO, iteritems


def _remove_temporary_emails(emails):
if type(emails) in (str, unicode):
emails = [email.strip()
for email in emails.split(',') if email.strip()]
return ','.join(emails)
return emails


class MailTestCase(InvenioTestCase):

EMAIL_BACKEND = 'flask_email.backends.console.Mail'
Expand All @@ -47,8 +57,14 @@ def setUp(self):
current_app.config['EMAIL_BACKEND'] = self.EMAIL_BACKEND
self.__stdout = sys.stdout
self.stream = sys.stdout = StringIO()
self.patcher = patch(
'invenio_ext.email.remove_temporary_emails',
side_effect=_remove_temporary_emails
)
self.patcher.start()

def tearDown(self):
self.patcher.stop()
del self.stream
sys.stdout = self.__stdout
del self.__stdout
Expand Down
2 changes: 2 additions & 0 deletions tests/test_ext_template.py
Expand Up @@ -73,6 +73,8 @@ class TemplateArgsTest(InvenioTestCase):

"""Test ``template_args`` decorator."""

render_templates = False

@classmethod
def setup_app(cls, app):
"""Custom setup function."""
Expand Down

0 comments on commit ece151d

Please sign in to comment.