From 00f7fee271c7fd749e212856d182af8905047d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Ducceschi?= Date: Thu, 2 Feb 2017 11:09:29 +0100 Subject: [PATCH] global: release checklist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * FIX Adds changes according to release preparation checklist. Signed-off-by: Rémi Ducceschi --- .editorconfig | 4 +-- .gitignore | 7 +++- .travis.yml | 13 ++++---- .tx/config | 50 ---------------------------- AUTHORS.rst | 6 ++-- CHANGES.rst | 3 +- CONTRIBUTING.rst | 13 +++++--- INSTALL.rst | 10 ------ MANIFEST.in | 4 +-- README.rst | 9 ++--- babel.ini | 40 ---------------------- docs/Makefile | 8 ++--- docs/api.rst | 8 +---- docs/conf.py | 18 +++++----- docs/configuration.rst | 29 ++++++++++++++++ docs/examplesapp.rst | 28 ++++++++++++++++ docs/index.rst | 4 ++- docs/make.bat | 4 +-- docs/usage.rst | 9 ++--- examples/app-fixtures.sh | 14 ++++++++ examples/app-setup.sh | 2 ++ examples/app-teardown.sh | 10 ++++-- examples/app.py | 5 ++- invenio_rest/__init__.py | 68 ++++++++++++++++++++++++++++++++++++++ invenio_rest/config.py | 32 +++++++++++++++--- run-tests.sh | 8 ++--- setup.cfg | 20 +---------- setup.py | 6 ++-- tests/conftest.py | 29 +++++++++++++--- tests/test_examples_app.py | 46 +++++++++++++++----------- 30 files changed, 295 insertions(+), 212 deletions(-) delete mode 100644 .tx/config delete mode 100644 babel.ini create mode 100644 docs/configuration.rst create mode 100644 docs/examplesapp.rst create mode 100755 examples/app-fixtures.sh diff --git a/.editorconfig b/.editorconfig index 5531f5e..40a40d3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of Invenio. -# Copyright (C) 2015 CERN. +# Copyright (C) 2015, 2017 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as @@ -22,7 +22,6 @@ # waive the privileges and immunities granted to it by virtue of its status # as an Intergovernmental Organization or submit itself to any jurisdiction. - root = true [*] @@ -40,6 +39,7 @@ known_first_party = invenio_rest known_third_party = flask_limiter, flask_cors multi_line_output = 2 default_section = THIRDPARTY +skip = .eggs # RST files (used by sphinx) [*.rst] diff --git a/.gitignore b/.gitignore index ba74660..f2229c3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ __pycache__/ *.py[cod] +# Idea software family +.idea/ + # C extensions *.so @@ -45,7 +48,6 @@ coverage.xml # Translations *.mo -*.pot # Django stuff: *.log @@ -55,3 +57,6 @@ docs/_build/ # PyBuilder target/ + +# Vim swapfiles +.*.sw? diff --git a/.travis.yml b/.travis.yml index 9e739d3..05645b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of Invenio. -# Copyright (C) 2015 CERN. +# Copyright (C) 2015, 2016, 2017 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as @@ -22,7 +22,6 @@ # waive the privileges and immunities granted to it by virtue of its status # as an Intergovernmental Organization or submit itself to any jurisdiction. - notifications: email: false @@ -30,6 +29,11 @@ sudo: false language: python +matrix: + fast_finish: true + allow_failures: + - python: pypy + cache: - pip @@ -43,11 +47,6 @@ python: - "3.5" - "pypy" -matrix: - fast_finish: true - allow_failures: - - python: pypy - before_install: - "travis_retry pip install --upgrade pip setuptools py" - "travis_retry pip install twine wheel coveralls requirements-builder" diff --git a/.tx/config b/.tx/config deleted file mode 100644 index 3392ec8..0000000 --- a/.tx/config +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of Invenio. -# Copyright (C) 2015 CERN. -# -# Invenio is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# Invenio is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Invenio; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, -# MA 02111-1307, USA. -# -# In applying this license, CERN does not -# waive the privileges and immunities granted to it by virtue of its status -# as an Intergovernmental Organization or submit itself to any jurisdiction. - - -# TODO: Transifex integration -# -# 1) Create message catalog: -# $ python setup.py extract_messages -# $ python setup.py init_catalog -l -# $ python setup.py compile_catalog -# 2) Ensure project has been created on Transifex under the inveniosoftware -# organisation. -# 3) Install the transifex-client -# $ pip install transifex-client -# 4) Push source (.pot) and translations (.po) to Transifex -# $ tx push -s -t -# 5) Pull translations for a single language from Transifex -# $ tx pull -l -# 6) Pull translations for all languages from Transifex -# $ tx pull -a - -[main] -host = https://www.transifex.com - -[invenio.invenio-rest-messages] -file_filter = invenio_rest/translations//LC_MESSAGES/messages.po -source_file = invenio_rest/translations/messages.pot -source_lang = en -type = PO diff --git a/AUTHORS.rst b/AUTHORS.rst index bbb227d..f9b3f7c 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -1,6 +1,6 @@ .. This file is part of Invenio. - Copyright (C) 2015, 2016 CERN. + Copyright (C) 2015, 2016, 2017 CERN. Invenio is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -21,11 +21,11 @@ waive the privileges and immunities granted to it by virtue of its status as an Intergovernmental Organization or submit itself to any jurisdiction. - Authors ======= REST API module for Invenio. -- Lars Holm Nielsen - Jiri Kuncar +- Lars Holm Nielsen +- Rémi Ducceschi diff --git a/CHANGES.rst b/CHANGES.rst index de0be8d..ef463f6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,6 @@ .. This file is part of Invenio. - Copyright (C) 2015, 2016 CERN. + Copyright (C) 2015, 2016, 2017 CERN. Invenio is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -21,7 +21,6 @@ waive the privileges and immunities granted to it by virtue of its status as an Intergovernmental Organization or submit itself to any jurisdiction. - Changes ======= diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 7538259..ecc9159 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -53,9 +53,9 @@ If you are proposing a feature: Get Started! ------------ -Ready to contribute? Here's how to set up `invenio` for local development. +Ready to contribute? Here's how to set up `invenio-rest` for local development. -1. Fork the `invenio` repo on GitHub. +1. Fork the `inveniosoftware/invenio-rest` repo on GitHub. 2. Clone your fork locally: .. code-block:: console @@ -95,7 +95,12 @@ Ready to contribute? Here's how to set up `invenio` for local development. .. code-block:: console $ git add . - $ git commit -s -m "Your detailed description of your changes." + $ git commit -s + -m "component: title without verbs" + -m "* NEW Adds your new feature." + -m "* FIX Fixes an existing issue." + -m "* BETTER Improves and existing feature." + -m "* Changes something that should not be visible in release notes." $ git push origin name-of-your-bugfix-or-feature 7. Submit a pull request through the GitHub website. @@ -109,5 +114,5 @@ Before you submit a pull request, check that it meets these guidelines: 2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring. 3. The pull request should work for Python 2.7, 3.3, 3.4 and 3.5. Check - https://travis-ci.com/inveniosoftware/invenio-rest/pull_requests + https://travis-ci.org/inveniosoftware/invenio-rest/pull_requests and make sure that the tests pass for all supported Python versions. diff --git a/INSTALL.rst b/INSTALL.rst index c79ba8e..7a85b94 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -15,16 +15,6 @@ this: $ pip install invenio-rest[cors] -Configuration -------------- - -===================== ================================================= -`REST_ENABLE_CORS` Set to ``True`` to enable Cross-Origin Resource - Sharing. Defaults to ``False``. -`REST_CORS_RESOURCES` Dictionary for configuring CORS for endpoints. - See Flask-CORS for further details. -===================== ================================================= - Please also see `Flask-Limiter `_ and `Flask-CORS `_ for many more diff --git a/MANIFEST.in b/MANIFEST.in index ca9c354..db39898 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of Invenio. -# Copyright (C) 2015, 2016 CERN. +# Copyright (C) 2015, 2016, 2017 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as @@ -27,8 +27,8 @@ include *.sh include *.txt include .dockerignore include .editorconfig -include .tx/config include .lgtm +include .tx/config include LICENSE include MAINTAINERS include babel.ini diff --git a/README.rst b/README.rst index 7325da0..573ed71 100644 --- a/README.rst +++ b/README.rst @@ -1,6 +1,6 @@ .. This file is part of Invenio. - Copyright (C) 2015, 2016 CERN. + Copyright (C) 2015, 2016, 2017 CERN. Invenio is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -40,10 +40,11 @@ .. image:: https://img.shields.io/github/license/inveniosoftware/invenio-rest.svg :target: https://github.com/inveniosoftware/invenio-rest/blob/master/LICENSE - REST API module for Invenio. *This is an experimental developer preview release.* -* Free software: GPLv2 license -* Documentation: https://invenio-rest.readthedocs.io/ +* This module allows you to create a REST API with standard error codes... + +Further documentation is available on +https://invenio-rest.readthedocs.io/ diff --git a/babel.ini b/babel.ini deleted file mode 100644 index 44201ad..0000000 --- a/babel.ini +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of Invenio. -# Copyright (C) 2015 CERN. -# -# Invenio is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# Invenio is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Invenio; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, -# MA 02111-1307, USA. -# -# In applying this license, CERN does not -# waive the privileges and immunities granted to it by virtue of its status -# as an Intergovernmental Organization or submit itself to any jurisdiction. - -# Extraction from Python source files - -[python: **.py] -encoding = utf-8 - -# Extraction from Jinja2 templates - -[jinja2: **/templates/**.html] -encoding = utf-8 -extensions = jinja2.ext.autoescape, jinja2.ext.with_ - -# Extraction from JavaScript files - -[javascript: **.js] -encoding = utf-8 -extract_messages = $._, jQuery._ diff --git a/docs/Makefile b/docs/Makefile index 43f3caf..18f97da 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -87,9 +87,9 @@ qthelp: @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" - @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/cookiecutterproject_name.qhcp" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Invenio-REST.qhcp" @echo "To view the help file:" - @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/cookiecutterproject_name.qhc" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Invenio-REST.qhc" applehelp: $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp @@ -104,8 +104,8 @@ devhelp: @echo @echo "Build finished." @echo "To view the help file:" - @echo "# mkdir -p $$HOME/.local/share/devhelp/cookiecutterproject_name" - @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/cookiecutterproject_name" + @echo "# mkdir -p $$HOME/.local/share/devhelp/Invenio-REST" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Invenio-REST" @echo "# devhelp" epub: diff --git a/docs/api.rst b/docs/api.rst index d1d0e03..808128a 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1,6 +1,6 @@ .. This file is part of Invenio. - Copyright (C) 2015 CERN. + Copyright (C) 2015, 2016, 2017 CERN. Invenio is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -28,12 +28,6 @@ API Docs .. automodule:: invenio_rest.ext :members: -Configuration -------------- - -.. automodule:: invenio_rest.config - :members: - Decorators ---------- diff --git a/docs/conf.py b/docs/conf.py index 44faa13..a84363f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of Invenio. -# Copyright (C) 2015, 2016 CERN. +# Copyright (C) 2015, 2016, 2017 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as @@ -22,12 +22,18 @@ # waive the privileges and immunities granted to it by virtue of its status # as an Intergovernmental Organization or submit itself to any jurisdiction. +"""Sphinx configuration.""" + from __future__ import print_function import os +import sys import sphinx.environment +# Plug example application into module path +sys.path.append('examples') + # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. @@ -63,7 +69,7 @@ # General information about the project. project = u'Invenio-REST' -copyright = u'2015, CERN' +copyright = u'2015, 2016, 2017, CERN' author = u'CERN' # The version info for the project you're documenting, acts as replacement for @@ -330,12 +336,8 @@ # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { 'https://docs.python.org/': None, - 'Flask': ( - 'http://flask.pocoo.org/docs/0.11', None - ), - 'werkzeug': ( - 'http://werkzeug.pocoo.org/docs/0.11', None - ), + 'Flask': ('http://flask.pocoo.org/docs/0.11', None), + 'werkzeug': ('http://werkzeug.pocoo.org/docs/0.11', None), } # Autodoc configuraton. diff --git a/docs/configuration.rst b/docs/configuration.rst new file mode 100644 index 0000000..d67270e --- /dev/null +++ b/docs/configuration.rst @@ -0,0 +1,29 @@ +.. + This file is part of Invenio. + Copyright (C) 2017 CERN. + + Invenio is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + Invenio is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Invenio; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, + MA 02111-1307, USA. + + In applying this license, CERN does not + waive the privileges and immunities granted to it by virtue of its status + as an Intergovernmental Organization or submit itself to any jurisdiction. + + +Configuration +============= + +.. automodule:: invenio_rest.config + :members: diff --git a/docs/examplesapp.rst b/docs/examplesapp.rst new file mode 100644 index 0000000..7a7645f --- /dev/null +++ b/docs/examplesapp.rst @@ -0,0 +1,28 @@ +.. + This file is part of Invenio. + Copyright (C) 2017 CERN. + + Invenio is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + Invenio is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Invenio; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, + MA 02111-1307, USA. + + In applying this license, CERN does not + waive the privileges and immunities granted to it by virtue of its status + as an Intergovernmental Organization or submit itself to any jurisdiction. + + +Example application +=================== + +.. automodule:: app diff --git a/docs/index.rst b/docs/index.rst index 5b45439..8d734cf 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,6 +1,6 @@ .. This file is part of Invenio. - Copyright (C) 2015 CERN. + Copyright (C) 2015, 2016, 2017 CERN. Invenio is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -34,7 +34,9 @@ Invenio-REST. :maxdepth: 2 installation + configuration usage + examplesapp API Reference diff --git a/docs/make.bat b/docs/make.bat index 48589d4..91359a7 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -127,9 +127,9 @@ if "%1" == "qthelp" ( echo. echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in %BUILDDIR%/qthelp, like this: - echo.^> qcollectiongenerator %BUILDDIR%\qthelp\cookiecutterproject_name.qhcp + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Invenio-REST.qhcp echo.To view the help file: - echo.^> assistant -collectionFile %BUILDDIR%\qthelp\cookiecutterproject_name.ghc + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Invenio-REST.ghc goto end ) diff --git a/docs/usage.rst b/docs/usage.rst index e477b22..1192ef8 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -1,6 +1,6 @@ .. This file is part of Invenio. - Copyright (C) 2015 CERN. + Copyright (C) 2015, 2017 CERN. Invenio is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -22,8 +22,9 @@ as an Intergovernmental Organization or submit itself to any jurisdiction. -======= - Usage -======= +Usage +===== .. automodule:: invenio_rest + +For more information, please refer to the :ref:`api` documentation. diff --git a/examples/app-fixtures.sh b/examples/app-fixtures.sh new file mode 100755 index 0000000..d510120 --- /dev/null +++ b/examples/app-fixtures.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# quit on errors: +set -o errexit + +# quit on unbound symbols: +set -o nounset + +DIR=`dirname "$0"` + +cd $DIR +export FLASK_APP=app.py + +# Setup fixtures diff --git a/examples/app-setup.sh b/examples/app-setup.sh index 74678aa..d07f85f 100755 --- a/examples/app-setup.sh +++ b/examples/app-setup.sh @@ -10,6 +10,8 @@ DIR=`dirname "$0"` cd $DIR export FLASK_APP=app.py + +# Setup app mkdir $DIR/instance # Install specific dependencies diff --git a/examples/app-teardown.sh b/examples/app-teardown.sh index 96251e1..705632b 100755 --- a/examples/app-teardown.sh +++ b/examples/app-teardown.sh @@ -1,9 +1,15 @@ #!/bin/sh +# quit on errors: +set -o errexit + +# quit on unbound symbols: +set -o nounset + DIR=`dirname "$0"` cd $DIR export FLASK_APP=app.py -# clean environment -[ -e "$DIR/instance" ] && rm $DIR/instance -Rf +# Teardown app +[ -e "$DIR/instance" ] && rm -Rf $DIR/instance diff --git a/examples/app.py b/examples/app.py index bf6aa2d..84bb133 100644 --- a/examples/app.py +++ b/examples/app.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of Invenio. -# Copyright (C) 2015 CERN. +# Copyright (C) 2015, 2016, 2017 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as @@ -23,7 +23,7 @@ # as an Intergovernmental Organization or submit itself to any jurisdiction. -r"""Minimal Flask application example for development. +"""Minimal Flask application example for development. Run example development server: @@ -57,7 +57,6 @@ from __future__ import absolute_import, print_function -import os import dicttoxml from flask import Blueprint, Flask, jsonify, make_response diff --git a/invenio_rest/__init__.py b/invenio_rest/__init__.py index 89d3851..eab808b 100644 --- a/invenio_rest/__init__.py +++ b/invenio_rest/__init__.py @@ -27,6 +27,74 @@ Invenio-REST takes care of installing basic error handling on a Flask API application, as well as initializing Flask-Limiter for rate limiting and Flask-CORS for Cross-Origin Resources Sharing (not enabled by default). + +Initialization +-------------- +First create a Flask application: + + >>> from flask import Flask + >>> app = Flask('myapp') + +Next, initialize your extension: + + >>> from invenio_rest import InvenioREST + >>> InvenioREST(app) + + +Serializers +----------- +Let's create 2 serializers that will return our answer to the correct format. +For instance, our server will be able to either answer in JSON or in XML: + + >>> import dicttoxml + >>> from flask import jsonify, make_response + >>> def json_v1_search(search_result): + ... return make_response(jsonify(search_result)) + >>> def xml_v1_search(search_result): + ... return make_response(dicttoxml.dicttoxml((search_result,))) + +Views +----- +Now we create our view that will handle the requests and return the answer. To +do so, we need to create a class that inherit +:class:`~.views.ContentNegotiatedMethodView`. In the constructor, we register +our two serializers, and we create a `get` method for the `GET` requests: + + >>> from invenio_rest import ContentNegotiatedMethodView + >>> class RecordsListResource(ContentNegotiatedMethodView): + ... def __init__(self, **kwargs): + ... super(RecordsListResource, self).__init__( + ... method_serializers={ + ... 'GET': { + ... 'application/json': json_v1_search, + ... 'application/xml': xml_v1_search, + ... }, + ... }, + ... default_method_media_type={ + ... 'GET': 'application/json', + ... }, + ... default_media_type='application/json', + ... **kwargs) + ... def get(self, **kwargs): + ... return {"title": "Test"} + +To finish, we need to create a blueprint that defines an endpoint (here +`/records`) and that registers our class: + + >>> from flask import Blueprint + >>> blueprint = Blueprint( + ... 'mymodule', + ... 'myapp', + ... url_prefix='/records', + ... template_folder='templates', + ... static_folder='static', + ... ) + >>> records_view = RecordsListResource.as_view('records') + >>> blueprint.add_url_rule('/', view_func=records_view) + >>> app.register_blueprint(blueprint) + +Now you can launch your server and request it on the `/records` endpoint, as +described in :any:`examplesapp`. """ from __future__ import absolute_import, print_function diff --git a/invenio_rest/config.py b/invenio_rest/config.py index 429c68f..3e392fa 100644 --- a/invenio_rest/config.py +++ b/invenio_rest/config.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of Invenio. -# Copyright (C) 2016 CERN. +# Copyright (C) 2016, 2017 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as @@ -26,10 +26,25 @@ from __future__ import unicode_literals + +CORS_RESOURCES = '*' +"""Dictionary for configuring CORS for endpoints. + + See Flask-CORS for further details. + +.. note:: Overwrite + `Flask-CORS + `_ + configuration. +""" + CORS_SEND_WILDCARD = True """Sending wildcard CORS header. -Overwrite Flask-CORS configuration. +.. note:: Overwrite + `Flask-CORS + `_ + configuration. """ CORS_EXPOSE_HEADERS = [ @@ -42,7 +57,10 @@ ] """Expose the following headers. -.. note:: Overwrite Flask-CORS configuration. +.. note:: Overwrite + `Flask-CORS + `_ + configuration. """ REST_ENABLE_CORS = False @@ -51,11 +69,15 @@ RATELIMIT_GLOBAL = '5000/hour' """Global rate limit. -.. note:: Overwrite Flask-Limiter configuration. +.. note:: Overwrite + Flask-Limiter `_ + configuration. """ RATELIMIT_HEADERS_ENABLED = True """Enable rate limit headers. (Default: ``True``) -.. note:: Overwrite Flask-Limiter configuration. +.. note:: Overwrite + Flask-Limiter `_ + configuration. """ diff --git a/run-tests.sh b/run-tests.sh index d82ffcf..a29e42d 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,7 +1,8 @@ +#!/usr/bin/env sh # -*- coding: utf-8 -*- # # This file is part of Invenio. -# Copyright (C) 2015 CERN. +# Copyright (C) 2015, 2016, 2017 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as @@ -22,9 +23,8 @@ # waive the privileges and immunities granted to it by virtue of its status # as an Intergovernmental Organization or submit itself to any jurisdiction. - -pydocstyle invenio_rest && \ -isort -rc -c -df **/*.py && \ +pydocstyle invenio_rest tests docs && \ +isort -rc -c -df && \ check-manifest --ignore ".travis-*" && \ sphinx-build -qnNW docs docs/_build/html && \ python setup.py test && \ diff --git a/setup.cfg b/setup.cfg index 1840329..b5206fd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of Invenio. -# Copyright (C) 2015 CERN. +# Copyright (C) 2015, 2016, 2017 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as @@ -22,7 +22,6 @@ # waive the privileges and immunities granted to it by virtue of its status # as an Intergovernmental Organization or submit itself to any jurisdiction. - [aliases] test = pytest @@ -33,20 +32,3 @@ all_files = 1 [bdist_wheel] universal = 1 - -[compile_catalog] -directory = invenio_rest/translations/ - -[extract_messages] -copyright_holder = CERN -msgid_bugs_address = info@inveniosoftware.org -mapping-file = babel.ini -output-file = invenio_rest/translations/messages.pot - -[init_catalog] -input-file = invenio_rest/translations/messages.pot -output-dir = invenio_rest/translations/ - -[update_catalog] -input-file = invenio_rest/translations/messages.pot -output-dir = invenio_rest/translations/ diff --git a/setup.py b/setup.py index 316b247..48f3386 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of Invenio. -# Copyright (C) 2015 CERN. +# Copyright (C) 2015, 2016, 2017 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as @@ -36,6 +36,7 @@ tests_require = [ 'check-manifest>=0.25', 'coverage>=4.0', + 'dicttoxml>=1.7.4', 'isort>=4.2.2', 'mock>=1.3.0', 'pydocstyle>=1.0.0', @@ -61,7 +62,6 @@ setup_requires = [ 'pytest-runner>=2.6.2', - 'Babel>=1.3', ] install_requires = [ @@ -114,6 +114,6 @@ 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', - 'Development Status :: 3 - Alpha', + 'Development Status :: 4 - Beta', ], ) diff --git a/tests/conftest.py b/tests/conftest.py index 2f4b63a..ee335f3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -27,15 +27,34 @@ from __future__ import absolute_import, print_function +import shutil +import tempfile + import pytest from flask import Flask +@pytest.yield_fixture() +def instance_path(): + """Temporary instance path.""" + path = tempfile.mkdtemp() + yield path + shutil.rmtree(path) + + @pytest.fixture() -def app(): +def base_app(instance_path): """Flask application fixture.""" - app = Flask('testapp') - app.config.update( - TESTING=True + app_ = Flask('testapp', instance_path=instance_path) + app_.config.update( + SECRET_KEY='SECRET_KEY', + TESTING=True, ) - return app + return app_ + + +@pytest.yield_fixture() +def app(base_app): + """Flask application fixture.""" + with base_app.app_context(): + yield base_app diff --git a/tests/test_examples_app.py b/tests/test_examples_app.py index 2e65fc0..ff70718 100644 --- a/tests/test_examples_app.py +++ b/tests/test_examples_app.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of Invenio. -# Copyright (C) 2016 CERN. +# Copyright (C) 2016, 2017 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as @@ -29,6 +29,7 @@ import signal import subprocess import time +from os.path import abspath, dirname, join import pytest @@ -37,27 +38,32 @@ def example_app(): """Example app fixture.""" current_dir = os.getcwd() - # go to example directory - project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - exampleappdir = os.path.join(project_dir, 'examples') - os.chdir(exampleappdir) - # setup example - cmd = './app-setup.sh' - exit_status = subprocess.call(cmd, shell=True) - assert exit_status == 0 - # Starting example web app - cmd = 'FLASK_APP=app.py flask run --debugger -p 5000' - webapp = subprocess.Popen(cmd, stdout=subprocess.PIPE, - preexec_fn=os.setsid, shell=True) - time.sleep(10) - # return webapp + + # Go to example directory + project_dir = dirname(dirname(abspath(__file__))) + exampleapp_dir = join(project_dir, 'examples') + os.chdir(exampleapp_dir) + + # Setup application + assert subprocess.call('./app-setup.sh', shell=True) == 0 + + # Setup fixtures + assert subprocess.call('./app-fixtures.sh', shell=True) == 0 + + # Start example app + webapp = subprocess.Popen( + 'FLASK_APP=app.py flask run --debugger -p 5000', + stdout=subprocess.PIPE, preexec_fn=os.setsid, shell=True) + time.sleep(3) yield webapp - # stop server + + # Stop server os.killpg(webapp.pid, signal.SIGTERM) - # tear down example app - cmd = './app-teardown.sh' - subprocess.call(cmd, shell=True) - # return to the original directory + + # Tear down example app + subprocess.call('./app-teardown.sh', shell=True) + + # Return to the original directory os.chdir(current_dir)