From 7adadb59eab1dde241d2f041088dc79c1e190a56 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Mon, 3 Aug 2015 11:05:27 +0200 Subject: [PATCH] global: initial package separation Signed-off-by: Jiri Kuncar --- .dockerignore | 15 + .editorconfig | 32 ++ .gitignore | 16 + .travis.yml | 68 ++++ AUTHORS.rst | 29 ++ CHANGES.rst | 29 ++ LICENSE | 339 ++++++++++++++++++ MANIFEST.in | 36 ++ README.rst | 62 ++++ docs/Makefile | 192 ++++++++++ docs/_ext/ultramock.py | 98 +++++ docs/conf.py | 323 +++++++++++++++++ docs/index.rst | 113 ++++++ docs/make.bat | 263 ++++++++++++++ .../__init__.py | 26 +- client.py => invenio_oauthclient/client.py | 0 config.py => invenio_oauthclient/config.py | 17 +- .../contrib}/__init__.py | 0 .../contrib}/cern.py | 12 +- .../contrib}/github.py | 16 +- .../contrib}/orcid.py | 18 +- errors.py => invenio_oauthclient/errors.py | 0 forms.py => invenio_oauthclient/forms.py | 0 .../handlers.py | 0 models.py => invenio_oauthclient/models.py | 1 + .../templates}/oauthclient/rejected.html | 0 .../templates}/oauthclient/rejected_base.html | 0 .../oauthclient/settings/index.html | 0 .../oauthclient/settings/index_base.html | 0 .../templates}/oauthclient/signup.html | 0 .../templates}/oauthclient/signup_base.html | 0 .../upgrades}/__init__.py | 0 .../oauthclient_2014_03_02_initial.py | 2 +- .../oauthclient_2014_04_14_json_type_fix.py | 0 ...thclient_2014_08_25_extra_data_nullable.py | 0 ...lient_2014_10_21_encrypted_token_column.py | 0 utils.py => invenio_oauthclient/utils.py | 0 invenio_oauthclient/version.py | 31 ++ .../views}/__init__.py | 0 .../views}/client.py | 0 .../views}/settings.py | 2 - pytest.ini | 28 ++ requirements-devel.txt | 29 ++ requirements-docs.txt | 30 ++ requirements.py | 191 ++++++++++ setup.py | 140 ++++++++ {upgrades => tests}/__init__.py | 0 {testsuite => tests}/fixture.py | 0 {testsuite => tests}/helpers.py | 23 +- {testsuite => tests}/test_contrib_orcid.py | 17 +- {testsuite => tests}/test_forms.py | 4 +- {testsuite => tests}/test_models.py | 10 +- {testsuite => tests}/test_views.py | 35 +- tox.ini | 29 ++ 54 files changed, 2198 insertions(+), 78 deletions(-) create mode 100644 .dockerignore create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 AUTHORS.rst create mode 100644 CHANGES.rst create mode 100644 LICENSE create mode 100644 MANIFEST.in create mode 100644 README.rst create mode 100644 docs/Makefile create mode 100644 docs/_ext/ultramock.py create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/make.bat rename __init__.py => invenio_oauthclient/__init__.py (89%) rename client.py => invenio_oauthclient/client.py (100%) rename config.py => invenio_oauthclient/config.py (90%) rename {contrib => invenio_oauthclient/contrib}/__init__.py (100%) rename {contrib => invenio_oauthclient/contrib}/cern.py (94%) rename {contrib => invenio_oauthclient/contrib}/github.py (89%) rename {contrib => invenio_oauthclient/contrib}/orcid.py (90%) rename errors.py => invenio_oauthclient/errors.py (100%) rename forms.py => invenio_oauthclient/forms.py (100%) rename handlers.py => invenio_oauthclient/handlers.py (100%) rename models.py => invenio_oauthclient/models.py (99%) rename {templates => invenio_oauthclient/templates}/oauthclient/rejected.html (100%) rename {templates => invenio_oauthclient/templates}/oauthclient/rejected_base.html (100%) rename {templates => invenio_oauthclient/templates}/oauthclient/settings/index.html (100%) rename {templates => invenio_oauthclient/templates}/oauthclient/settings/index_base.html (100%) rename {templates => invenio_oauthclient/templates}/oauthclient/signup.html (100%) rename {templates => invenio_oauthclient/templates}/oauthclient/signup_base.html (100%) rename {testsuite => invenio_oauthclient/upgrades}/__init__.py (100%) rename {upgrades => invenio_oauthclient/upgrades}/oauthclient_2014_03_02_initial.py (98%) rename {upgrades => invenio_oauthclient/upgrades}/oauthclient_2014_04_14_json_type_fix.py (100%) rename {upgrades => invenio_oauthclient/upgrades}/oauthclient_2014_08_25_extra_data_nullable.py (100%) rename {upgrades => invenio_oauthclient/upgrades}/oauthclient_2014_10_21_encrypted_token_column.py (100%) rename utils.py => invenio_oauthclient/utils.py (100%) create mode 100644 invenio_oauthclient/version.py rename {views => invenio_oauthclient/views}/__init__.py (100%) rename {views => invenio_oauthclient/views}/client.py (100%) rename {views => invenio_oauthclient/views}/settings.py (97%) create mode 100644 pytest.ini create mode 100644 requirements-devel.txt create mode 100644 requirements-docs.txt create mode 100755 requirements.py create mode 100644 setup.py rename {upgrades => tests}/__init__.py (100%) rename {testsuite => tests}/fixture.py (100%) rename {testsuite => tests}/helpers.py (71%) rename {testsuite => tests}/test_contrib_orcid.py (95%) rename {testsuite => tests}/test_forms.py (93%) rename {testsuite => tests}/test_models.py (92%) rename {testsuite => tests}/test_views.py (93%) create mode 100644 tox.ini diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..231f82c3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +.git +*.gitignore + +*.mo +*.pyc +*.swp +*.swo +*.~ + +.dockerignore +Dockerfile +docker-compose.yml +docker-compose-dev.yml + +Procfile* diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..968e2370 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,32 @@ +root = true + +[*] +indent_style = space +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 + +# Python files +[*.py] +indent_size = 4 +# isort plugin configuration +known_first_party = invenio +multi_line_output = 2 +default_section = THIRDPARTY + +# RST files (used by sphinx) +[*.rst] +indent_size = 4 + +# CSS, HTML, JS, JSON, YML +[*.{css,html,js,json,yml}] +indent_size = 2 + +# Matches the exact files either package.json or .travis.yml +[{package.json,.travis.yml}] +indent_size = 2 + +# Dockerfile +[Dockerfile] +indent_size = 4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..8085bef1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +*~ +*.py[cod] + +# Packages +*.egg +*.egg-info +.eggs +__pycache__ + +# Unit test / coverage reports +.cache +.coverage +.tox + +# doc +docs/_build diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..5c8aec69 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# +# This file is part of Invenio-OAuthClient +# 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. + +notifications: + email: false + +services: + - mysql + - redis + +language: python + +cache: + - apt + - pip + +env: + - REQUIREMENTS=lowest REXTRAS=docs,test + - REQUIREMENTS=release REXTRAS=docs,test + - REQUIREMENTS=devel REXTRAS=docs,test + +python: + - "2.7" + +before_install: + - "sudo apt-get update" + - "sudo apt-get install python-dev" + - "travis_retry pip install --upgrade pip" + - "travis_retry pip install mock" + - "python requirements.py --extras=$REXTRAS --level=min > .travis-lowest-requirements.txt" + - "python requirements.py --extras=$REXTRAS --level=pypi > .travis-release-requirements.txt" + - "python requirements.py --extras=$REXTRAS --level=dev > .travis-devel-requirements.txt" + +install: + - "travis_retry pip install unittest2" + - "travis_retry pip install -r .travis-$REQUIREMENTS-requirements.txt --allow-all-external --quiet" + - "travis_retry pip install -e .[$REXTRAS] --quiet --process-dependency-links" + +before_script: + - "inveniomanage database init --yes-i-know || echo ':('" + - "inveniomanage database create --quiet || echo ':('" + +script: + - "sphinx-build -qnN docs docs/_build/html" + - "python setup.py test" + +after_success: + - coveralls diff --git a/AUTHORS.rst b/AUTHORS.rst new file mode 100644 index 00000000..b45b64e1 --- /dev/null +++ b/AUTHORS.rst @@ -0,0 +1,29 @@ +.. + 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. + +Authors +======= + +Invenio module that provides OAuth web authorization support. + +- CERN diff --git a/CHANGES.rst b/CHANGES.rst new file mode 100644 index 00000000..0ced25b6 --- /dev/null +++ b/CHANGES.rst @@ -0,0 +1,29 @@ +.. + 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. + +Changes +======= + +Version 0.1.0 (release TBD) + +- First release diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..d159169d --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program 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. + + This program 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 this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..58570774 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,36 @@ +# 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. + +include *.py +include *.rst +include *.txt +include .dockerignore .editorconfig +include LICENSE +include pytest.ini +include tox.ini +recursive-include docs *.bat +recursive-include docs *.py +recursive-include docs *.rst +recursive-include docs Makefile +recursive-include invenio_oauthclient *.html +recursive-include invenio_oauthclient *.py +recursive-include tests *.py diff --git a/README.rst b/README.rst new file mode 100644 index 00000000..1fa8074d --- /dev/null +++ b/README.rst @@ -0,0 +1,62 @@ +.. + 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. + +===================== + Invenio-OAuthClient +===================== + +.. image:: https://img.shields.io/travis/inveniosoftware/invenio-oauthclient.svg + :target: https://travis-ci.org/inveniosoftware/invenio-oauthclient + +.. image:: https://img.shields.io/coveralls/inveniosoftware/invenio-oauthclient.svg + :target: https://coveralls.io/r/inveniosoftware/invenio-oauthclient + +.. image:: https://img.shields.io/github/tag/inveniosoftware/invenio-oauthclient.svg + :target: https://github.com/inveniosoftware/invenio-oauthclient/releases + +.. image:: https://img.shields.io/pypi/dm/invenio-oauthclient.svg + :target: https://pypi.python.org/pypi/invenio-oauthclient + +.. image:: https://img.shields.io/github/license/inveniosoftware/invenio-oauthclient.svg + :target: https://github.com/inveniosoftware/invenio-oauthclient/blob/master/LICENSE + + +Invenio module that provides OAuth web authorization support. + +OAuth client support is typically used to allow features such as social login +(e.g. Sign in with Twitter) and access to resources owner by a specific user +at a remote service. Both OAuth 1.0 and OAuth 2.0 are supported. + +Features +======== + +The module contains: + +- Views: OAuth login and authorized endpoints, linked account settings and + sign-up handling. +- Client: A client to interact with remote applications. +- Contrib: Ready-to-use GitHub, ORCID, and CERN remote applications. +- Models: Persistence layer for OAuth access tokens including support for + storing extra data together with a token. +- Handlers: Customizable handlers for deciding what happens when a user + authorizes a request. diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..43f3caf7 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,192 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " applehelp to make an Apple Help Book" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + @echo " coverage to run coverage check of the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/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 "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/cookiecutterproject_name.qhc" + +applehelp: + $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp + @echo + @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." + @echo "N.B. You won't be able to view it unless you put it in" \ + "~/Library/Documentation/Help or install it in your application" \ + "bundle." + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/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 "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +coverage: + $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage + @echo "Testing of coverage in the sources finished, look at the " \ + "results in $(BUILDDIR)/coverage/python.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/_ext/ultramock.py b/docs/_ext/ultramock.py new file mode 100644 index 00000000..71287989 --- /dev/null +++ b/docs/_ext/ultramock.py @@ -0,0 +1,98 @@ +# -*- 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. + +"""Hijacks `mock` to fake as many non-available modules as possible.""" +import sys +import types + +try: + import unittest.mock as mock +except ImportError: + import mock + +# skip `_is_magic` check. +orig_is_magic = mock._is_magic +def always_false(*args, **kwargs): + return False + + +# avoid spec configuration for mocked classes with super classes. +# honestly this does not happen very often and is kind of a tricky case. +orig_mock_add_spec = mock.NonCallableMock._mock_add_spec +def mock_add_spec_fake(self, spec, spec_set): + orig_mock_add_spec(self, None, None) + + +# special MagicMock with empty docs +class MyMagicMock(mock.MagicMock): + """""" + + +# set up a fake class-metaclass hierarchy +class SuperMockMetaMeta(MyMagicMock): + __metaclass__ = MyMagicMock() + + +class SuperMockMeta(MyMagicMock): + __metaclass__ = SuperMockMetaMeta + + +class SuperMock(MyMagicMock): + __metaclass__ = SuperMockMeta + + +class MockedModule(types.ModuleType): + def __init__(self, name): + super(types.ModuleType, self).__init__(name) + self.__name__ = super.__name__ + self.__file__ = self.__name__.replace('.', '/') + '.py' + sys.modules[self.__name__] = self + + def __getattr__(self, key): + obj = SuperMock + setattr(self, key, obj) + return obj + + +# overwrite imports +orig_import = __import__ +def import_mock(name, *args, **kwargs): + try: + return orig_import(name, *args, **kwargs) + except ImportError: + return MockedModule(name) +import_patch = mock.patch('__builtin__.__import__', side_effect=import_mock) + + +# public methods +def activate(): + mock._is_magic = always_false + mock.NonCallableMock._mock_add_spec = mock_add_spec_fake + import_patch.start() + + +def deactivate(): + import_patch.stop() + mock.NonCallableMock._mock_add_spec = orig_mock_add_spec + mock._is_magic = orig_is_magic diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000..d7f838ad --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,323 @@ +# -*- 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. + +from __future__ import print_function + +import sys +import os +import shlex + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath('..')) +sys.path.insert(0, os.path.abspath('_ext')) + +import ultramock +ultramock.activate() + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'Invenio-OAuthClient' +copyright = u'2015, CERN' +author = u'CERN' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. + +# Get the version string. Cannot be done with import! +g = {} +with open(os.path.join('..', 'invenio_oauthclient', 'version.py'), 'rt') as fp: + exec(fp.read(), g) + version = g['__version__'] + +# The full version, including alpha/beta/rc tags. +release = version + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = [] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- +on_rtd = os.environ.get('READTHEDOCS', None) == 'True' + +# only set the theme when we are not on RTD +if not on_rtd: + try: + import sphinx_rtd_theme + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] + except ImportError: + print("`sphinx_rtd_theme` not found, pip install it", file=sys.stderr) + html_theme = 'alabaster' + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +#html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +#html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +#html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'invenio-oauthclient_namedoc' + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', + +# Latex figure (float) alignment +#'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'invenio-oauthclient.tex', u'invenio-oauthclient Documentation', + u'CERN', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'invenio-oauthclient', u'invenio-oauthclient Documentation', + [author], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'invenio-oauthclient', u'Invenio-OAuthClient Documentation', + author, 'invenio-oauthclient', 'Invenio module that provides OAuth web authorization support.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = {'https://docs.python.org/': None} diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..89dcfe91 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,113 @@ +.. + This file is part of Invenio. + Copyright (C) 2014, 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. + +.. _module_oauthclient: + +===================== + Invenio-OAuthClient +===================== + +.. automodule:: invenio_oauthclient + +Contents +-------- + +.. toctree:: + :maxdepth: 2 + +.. _module_oauthclient_conf: + +Configuration +------------- + +.. automodule:: invenio_oauthclient.config + +Contrib +------- + +GitHub +^^^^^^ +.. automodule:: invenio_oauthclient.contrib.github + +ORCID +^^^^^ +.. automodule:: invenio_oauthclient.contrib.orcid + +CERN +^^^^ +.. automodule:: invenio_oauthclient.contrib.cern + +API +---- + +Handlers +^^^^^^^^ + +.. automodule:: invenio_oauthclient.handlers + :members: + +Models +^^^^^^ + +.. automodule:: invenio_oauthclient.models + :members: + +Views +^^^^^ + +.. automodule:: invenio_oauthclient.views.client + :members: + +.. automodule:: invenio_oauthclient.views.settings + :members: + +Forms +^^^^^ + +.. automodule:: invenio_oauthclient.forms + :members: + +Utils +^^^^^ + +.. automodule:: invenio_oauthclient.utils + :members: + +Registries +^^^^^^^^^^ + +.. automodule:: invenio_oauthclient.client + :members: + +Errors +^^^^^^ + +.. automodule:: invenio_oauthclient.errors + :members: + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 00000000..48589d40 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,263 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + echo. coverage to run coverage check of the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + + +REM Check if sphinx-build is available and fallback to Python version if any +%SPHINXBUILD% 2> nul +if errorlevel 9009 goto sphinx_python +goto sphinx_ok + +:sphinx_python + +set SPHINXBUILD=python -m sphinx.__init__ +%SPHINXBUILD% 2> nul +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +:sphinx_ok + + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + 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.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\cookiecutterproject_name.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "coverage" ( + %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage + if errorlevel 1 exit /b 1 + echo. + echo.Testing of coverage in the sources finished, look at the ^ +results in %BUILDDIR%/coverage/python.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end diff --git a/__init__.py b/invenio_oauthclient/__init__.py similarity index 89% rename from __init__.py rename to invenio_oauthclient/__init__.py index 6ee6225f..dbf64f59 100644 --- a/__init__.py +++ b/invenio_oauthclient/__init__.py @@ -70,7 +70,9 @@ .. code-block:: http HTTP/1.1 302 FOUND - Location: https://orcid.org/oauth/authorize?response_type=code&client_id=&redirect_uri=https://localhost/oauth/authorized/orcid/&scope=/authenticate&state=... + Location: https://orcid.org/oauth/authorize?response_type=code&\ + client_id=&redirect_uri=https://localhost/oauth/\ + authorized/orcid/&scope=/authenticate&state=... Note, following query parameters in the authorize URL: @@ -99,7 +101,8 @@ .. code-block:: http HTTP/1.1 302 FOUND - Location: https://localhost/oauth/authorized/orcid/?code=&state=... + Location: https://localhost/oauth/authorized/orcid/?code=&\ + state=... Included in the redirect is a one-time *auth code* which is typically only valid for short time (seconds), as well as the ``state`` token initially @@ -137,18 +140,21 @@ Further reading: -- `RFC6749 - The OAuth 2.0 Authorization Framework `_ +- `RFC6749 - The OAuth 2.0 Authorization Framework + `_ -- `OAuth 2 Simplified `_ +- `OAuth 2 Simplified + `_ -- `Flask-OAuthlib `_ +- `Flask-OAuthlib + `_ - `OAuthlib `_ Usage ----- -1. Edit your configuration. Ensure ``invenio.modules.oauthclient`` is included +1. Edit your configuration. Ensure ``invenio_oauthclient`` is included in ``PACKAGES`` (by default it's included). @@ -158,7 +164,7 @@ PACKAGES = [ # ... - 'invenio.modules.oauthclient', + 'invenio_oauthclient', # ... ] @@ -169,3 +175,9 @@ See :ref:`module_oauthclient_conf` for how to define remote applications in ``OAUTHCLIENT_REMOTE_APPS``. """ + +from __future__ import absolute_import, print_function, unicode_literals + +from .version import __version__ + +__all__ = ('__version__', ) diff --git a/client.py b/invenio_oauthclient/client.py similarity index 100% rename from client.py rename to invenio_oauthclient/client.py diff --git a/config.py b/invenio_oauthclient/config.py similarity index 90% rename from config.py rename to invenio_oauthclient/config.py index e2e8bbf0..f67b1220 100644 --- a/config.py +++ b/invenio_oauthclient/config.py @@ -91,7 +91,8 @@ ^^^^^^^^^^^^^^^^^^^^^^^^^ The Flask-OAuthlib parameters defines the remote application OAuth endpoints as well as the client id and secret. Full description of these parameters are -given in the `Flask-OAuthlib documentation `_. +given in the `Flask-OAuthlib documentation +`_. Normally you will have to browse the remote application's API documentation to find which URLs and scopes to use. @@ -142,9 +143,9 @@ OAUTHCLIENT_REMOTE_APPS = dict( myapp=dict( # ... - authorized_handler="invenio.modules.oauthclient.handlers" + authorized_handler="invenio_oauthclient.handlers" ":authorized_default_handler", - disconnect_handler="invenio.modules.oauthclient.handlers" + disconnect_handler="invenio_oauthclient.handlers" ":disconnect_handler", ) # ... @@ -160,15 +161,15 @@ OAUTHCLIENT_REMOTE_APPS = dict( orcid=dict( # ... - authorized_handler="invenio.modules.oauthclient.handlers" + authorized_handler="invenio_oauthclient.handlers" ":authorized_signup_handler", - disconnect_handler="invenio.modules.oauthclient.handlers" + disconnect_handler="invenio_oauthclient.handlers" ":disconnect_handler", ) signup_handler=dict( - info="invenio.modules.oauthclient.contrib.orcid:account_info", - setup="invenio.modules.oauthclient.contrib.orcid:account_setup", - view="invenio.modules.oauthclient.handlers:signup_handler", + info="invenio_oauthclient.contrib.orcid:account_info", + setup="invenio_oauthclient.contrib.orcid:account_setup", + view="invenio_oauthclient.handlers:signup_handler", ), # ... ) diff --git a/contrib/__init__.py b/invenio_oauthclient/contrib/__init__.py similarity index 100% rename from contrib/__init__.py rename to invenio_oauthclient/contrib/__init__.py diff --git a/contrib/cern.py b/invenio_oauthclient/contrib/cern.py similarity index 94% rename from contrib/cern.py rename to invenio_oauthclient/contrib/cern.py index c8a4ef26..94eb293b 100644 --- a/contrib/cern.py +++ b/invenio_oauthclient/contrib/cern.py @@ -27,7 +27,7 @@ import copy - from invenio.modules.oauthclient.contrib import cern + from invenio_oauthclient.contrib import cern CERN_REMOTE_APP = copy.deepcopy(cern.REMOTE_APP) CERN_REMOTE_APP["params"].update(dict(request_token_params={ @@ -128,14 +128,14 @@ title="CERN", description="Connecting to CERN Organization.", icon="", - authorized_handler="invenio.modules.oauthclient.handlers" + authorized_handler="invenio_oauthclient.handlers" ":authorized_signup_handler", - disconnect_handler="invenio.modules.oauthclient.handlers" + disconnect_handler="invenio_oauthclient.handlers" ":disconnect_handler", signup_handler=dict( - info="invenio.modules.oauthclient.contrib.cern:account_info", - setup="invenio.modules.oauthclient.contrib.cern:account_setup", - view="invenio.modules.oauthclient.handlers:signup_handler", + info="invenio_oauthclient.contrib.cern:account_info", + setup="invenio_oauthclient.contrib.cern:account_setup", + view="invenio_oauthclient.handlers:signup_handler", ), params=dict( base_url="https://oauth.web.cern.ch/", diff --git a/contrib/github.py b/invenio_oauthclient/contrib/github.py similarity index 89% rename from contrib/github.py rename to invenio_oauthclient/contrib/github.py index 1414b0a6..f1407e50 100644 --- a/contrib/github.py +++ b/invenio_oauthclient/contrib/github.py @@ -32,7 +32,7 @@ .. code-block:: python - from invenio.modules.oauthclient.contrib import github + from invenio_oauthclient.contrib import github OAUTHCLIENT_REMOTE_APPS = dict( github=github.REMOTE_APP, ) @@ -74,7 +74,9 @@ .. code-block:: jinja - Sign in with GitHub + + Sign in with GitHub + """ import github3 @@ -83,14 +85,14 @@ title='GitHub', description='Software collaboration platform.', icon='fa fa-github', - authorized_handler="invenio.modules.oauthclient.handlers" + authorized_handler="invenio_oauthclient.handlers" ":authorized_signup_handler", - disconnect_handler="invenio.modules.oauthclient.handlers" + disconnect_handler="invenio_oauthclient.handlers" ":disconnect_handler", signup_handler=dict( - info="invenio.modules.oauthclient.contrib.github:account_info", - setup="invenio.modules.oauthclient.contrib.github:account_setup", - view="invenio.modules.oauthclient.handlers:signup_handler", + info="invenio_oauthclient.contrib.github:account_info", + setup="invenio_oauthclient.contrib.github:account_setup", + view="invenio_oauthclient.handlers:signup_handler", ), params=dict( request_token_params={'scope': 'user:email'}, diff --git a/contrib/orcid.py b/invenio_oauthclient/contrib/orcid.py similarity index 90% rename from contrib/orcid.py rename to invenio_oauthclient/contrib/orcid.py index 0a1082ae..f24cca2e 100644 --- a/contrib/orcid.py +++ b/invenio_oauthclient/contrib/orcid.py @@ -25,7 +25,7 @@ .. code-block:: python - from invenio.modules.oauthclient.contrib import orcid + from invenio_oauthclient.contrib import orcid OAUTHCLIENT_REMOTE_APPS = dict( orcid=orcid.REMOTE_APP, ) @@ -86,14 +86,14 @@ title='ORCID', description='Connecting Research and Researchers.', icon='', - authorized_handler="invenio.modules.oauthclient.handlers" + authorized_handler="invenio_oauthclient.handlers" ":authorized_signup_handler", - disconnect_handler="invenio.modules.oauthclient.contrib.orcid" + disconnect_handler="invenio_oauthclient.contrib.orcid" ":disconnect_handler", signup_handler=dict( - info="invenio.modules.oauthclient.contrib.orcid:account_info", - setup="invenio.modules.oauthclient.contrib.orcid:account_setup", - view="invenio.modules.oauthclient.handlers:signup_handler", + info="invenio_oauthclient.contrib.orcid:account_info", + setup="invenio_oauthclient.contrib.orcid:account_setup", + view="invenio_oauthclient.handlers:signup_handler", ), params=dict( request_token_params={'scope': '/authenticate', @@ -131,8 +131,8 @@ def account_info(remote, resp): def disconnect_handler(remote, *args, **kwargs): """Handle unlinking of remote account.""" - from invenio.modules.oauthclient.utils import oauth_unlink_external_id - from invenio.modules.oauthclient.models import RemoteAccount + from invenio_oauthclient.utils import oauth_unlink_external_id + from invenio_oauthclient.models import RemoteAccount if not current_user.is_authenticated(): return current_app.login_manager.unauthorized() @@ -152,7 +152,7 @@ def disconnect_handler(remote, *args, **kwargs): @session_manager def account_setup(remote, token, resp): """Perform additional setup after user have been logged in.""" - from invenio.modules.oauthclient.utils import oauth_link_external_id + from invenio_oauthclient.utils import oauth_link_external_id from invenio.ext.sqlalchemy import db # Retrieve ORCID from response. diff --git a/errors.py b/invenio_oauthclient/errors.py similarity index 100% rename from errors.py rename to invenio_oauthclient/errors.py diff --git a/forms.py b/invenio_oauthclient/forms.py similarity index 100% rename from forms.py rename to invenio_oauthclient/forms.py diff --git a/handlers.py b/invenio_oauthclient/handlers.py similarity index 100% rename from handlers.py rename to invenio_oauthclient/handlers.py diff --git a/models.py b/invenio_oauthclient/models.py similarity index 99% rename from models.py rename to invenio_oauthclient/models.py index 87c3c454..5599387e 100644 --- a/models.py +++ b/invenio_oauthclient/models.py @@ -26,6 +26,7 @@ from invenio.ext.sqlalchemy import db from invenio_accounts.models import User + class TextEncryptedType(EncryptedType): impl = db.Text diff --git a/templates/oauthclient/rejected.html b/invenio_oauthclient/templates/oauthclient/rejected.html similarity index 100% rename from templates/oauthclient/rejected.html rename to invenio_oauthclient/templates/oauthclient/rejected.html diff --git a/templates/oauthclient/rejected_base.html b/invenio_oauthclient/templates/oauthclient/rejected_base.html similarity index 100% rename from templates/oauthclient/rejected_base.html rename to invenio_oauthclient/templates/oauthclient/rejected_base.html diff --git a/templates/oauthclient/settings/index.html b/invenio_oauthclient/templates/oauthclient/settings/index.html similarity index 100% rename from templates/oauthclient/settings/index.html rename to invenio_oauthclient/templates/oauthclient/settings/index.html diff --git a/templates/oauthclient/settings/index_base.html b/invenio_oauthclient/templates/oauthclient/settings/index_base.html similarity index 100% rename from templates/oauthclient/settings/index_base.html rename to invenio_oauthclient/templates/oauthclient/settings/index_base.html diff --git a/templates/oauthclient/signup.html b/invenio_oauthclient/templates/oauthclient/signup.html similarity index 100% rename from templates/oauthclient/signup.html rename to invenio_oauthclient/templates/oauthclient/signup.html diff --git a/templates/oauthclient/signup_base.html b/invenio_oauthclient/templates/oauthclient/signup_base.html similarity index 100% rename from templates/oauthclient/signup_base.html rename to invenio_oauthclient/templates/oauthclient/signup_base.html diff --git a/testsuite/__init__.py b/invenio_oauthclient/upgrades/__init__.py similarity index 100% rename from testsuite/__init__.py rename to invenio_oauthclient/upgrades/__init__.py diff --git a/upgrades/oauthclient_2014_03_02_initial.py b/invenio_oauthclient/upgrades/oauthclient_2014_03_02_initial.py similarity index 98% rename from upgrades/oauthclient_2014_03_02_initial.py rename to invenio_oauthclient/upgrades/oauthclient_2014_03_02_initial.py index 9081db04..4397f020 100644 --- a/upgrades/oauthclient_2014_03_02_initial.py +++ b/invenio_oauthclient/upgrades/oauthclient_2014_03_02_initial.py @@ -51,7 +51,7 @@ def do_upgrade(): op.create_table( 'remoteTOKEN', db.Column('id_remote_account', db.Integer(display_width=15), - nullable=False), + nullable=False), db.Column('token_type', db.String(length=40), nullable=False), db.Column('access_token', db.Text(), nullable=False), db.Column('secret', db.Text(), nullable=False), diff --git a/upgrades/oauthclient_2014_04_14_json_type_fix.py b/invenio_oauthclient/upgrades/oauthclient_2014_04_14_json_type_fix.py similarity index 100% rename from upgrades/oauthclient_2014_04_14_json_type_fix.py rename to invenio_oauthclient/upgrades/oauthclient_2014_04_14_json_type_fix.py diff --git a/upgrades/oauthclient_2014_08_25_extra_data_nullable.py b/invenio_oauthclient/upgrades/oauthclient_2014_08_25_extra_data_nullable.py similarity index 100% rename from upgrades/oauthclient_2014_08_25_extra_data_nullable.py rename to invenio_oauthclient/upgrades/oauthclient_2014_08_25_extra_data_nullable.py diff --git a/upgrades/oauthclient_2014_10_21_encrypted_token_column.py b/invenio_oauthclient/upgrades/oauthclient_2014_10_21_encrypted_token_column.py similarity index 100% rename from upgrades/oauthclient_2014_10_21_encrypted_token_column.py rename to invenio_oauthclient/upgrades/oauthclient_2014_10_21_encrypted_token_column.py diff --git a/utils.py b/invenio_oauthclient/utils.py similarity index 100% rename from utils.py rename to invenio_oauthclient/utils.py diff --git a/invenio_oauthclient/version.py b/invenio_oauthclient/version.py new file mode 100644 index 00000000..57bc1ab9 --- /dev/null +++ b/invenio_oauthclient/version.py @@ -0,0 +1,31 @@ +# -*- 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. + +"""Version information for Invenio-OAuthClient. + +This file is imported by ``invenio_oauthclient.__init__``, +and parsed by ``setup.py``. +""" + +__version__ = "0.1.0.dev20150000" diff --git a/views/__init__.py b/invenio_oauthclient/views/__init__.py similarity index 100% rename from views/__init__.py rename to invenio_oauthclient/views/__init__.py diff --git a/views/client.py b/invenio_oauthclient/views/client.py similarity index 100% rename from views/client.py rename to invenio_oauthclient/views/client.py diff --git a/views/settings.py b/invenio_oauthclient/views/settings.py similarity index 97% rename from views/settings.py rename to invenio_oauthclient/views/settings.py index 01527e00..77732edf 100644 --- a/views/settings.py +++ b/invenio_oauthclient/views/settings.py @@ -24,13 +24,11 @@ import six from operator import itemgetter from flask import Blueprint, render_template, request -#from flask import redirect, url_for from flask_login import login_required, current_user from flask_breadcrumbs import register_breadcrumb from flask_menu import register_menu from invenio.base.i18n import _ from invenio.base.globals import cfg -#from invenio.ext.sqlalchemy import db from invenio.ext.sslify import ssl_required from ..models import RemoteAccount diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..7111d6aa --- /dev/null +++ b/pytest.ini @@ -0,0 +1,28 @@ +# -*- 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. + +[pytest] +addopts = --clearcache --pep8 --ignore=docs --cov=invenio_oauthclient --cov-report=term-missing +pep8ignore = + tests/* ALL diff --git a/requirements-devel.txt b/requirements-devel.txt new file mode 100644 index 00000000..246e9a1e --- /dev/null +++ b/requirements-devel.txt @@ -0,0 +1,29 @@ +# -*- 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: Add development versions of some important dependencies here to get a +# warning when there are breaking upstream changes, e.g.: +# +# -e git+git://github.com/mitsuhiko/werkzeug.git#egg=Werkzeug +# -e git+git://github.com/mitsuhiko/jinja2.git#egg=Jinja2 diff --git a/requirements-docs.txt b/requirements-docs.txt new file mode 100644 index 00000000..56252c7a --- /dev/null +++ b/requirements-docs.txt @@ -0,0 +1,30 @@ +# -*- 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. +# +# !WARNING! !WARNING! !WARNING! !WARNING! !WARNING! !WARNING! !WARNING! +# Do NOT delete this file, even when it seems to be useless! +# It used by read Read the Docs to build our documentation! +# !WARNING! !WARNING! !WARNING! !WARNING! !WARNING! !WARNING! !WARNING! + +-e .[docs] diff --git a/requirements.py b/requirements.py new file mode 100755 index 00000000..214ee282 --- /dev/null +++ b/requirements.py @@ -0,0 +1,191 @@ +#!/usr/bin/env python2 +# +# -*- 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. + +"""Generate minimal requirements from `setup.py` + `requirements-devel.txt`.""" + +from __future__ import print_function + +import argparse +import re +import sys + +import mock + +import pkg_resources + +import setuptools + + +def parse_set(string): + """Parse set from comma separated string.""" + string = string.strip() + if string: + return set(string.split(",")) + else: + return set() + + +def minver_error(pkg_name): + """Report error about missing minimum version constraint and exit.""" + print( + 'ERROR: specify minimal version of "{}" using ' + '">=" or "=="'.format(pkg_name), + file=sys.stderr + ) + sys.exit(1) + + +def parse_pip_file(path): + """Parse pip requirements file.""" + # requirement lines sorted by importance + # also collect other pip commands + rdev = dict() + rnormal = [] + stuff = [] + + try: + with open(path) as f: + for line in f: + line = line.strip() + + # see https://pip.readthedocs.org/en/1.1/requirements.html + if line.startswith('-e'): + # devel requirement + splitted = line.split('#egg=') + rdev[splitted[1].lower()] = line + + elif line.startswith('-r'): + # recursive file command + splitted = re.split('-r\\s+', line) + subrdev, subrnormal, substuff = parse_pip_file(splitted[1]) + for k, v in subrdev.iteritems(): + if k not in rdev: + rdev[k] = v + rnormal.extend(subrnormal) + result.extend(substuff) + + elif line.startswith('-'): + # another special command we don't recognize + stuff.append(line) + + else: + # ordenary requirement, similary to them used in setup.py + rnormal.append(line) + except IOError: + print( + 'Warning: could not parse requirements file "{}"!', + file=sys.stderr + ) + + return rdev, rnormal, stuff + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description='Calculates requirements for different purposes', + formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) + parser.add_argument( + '-l', '--level', + choices=['min', 'pypi', 'dev'], + default='pypi', + help='Specifies desired requirements level.' + '"min" requests the minimal requirement that is specified, ' + '"pypi" requests the maximum version that satisfies the ' + 'constrains and is available in PyPi. ' + '"dev" includes experimental developer versions for VCSs.' + ) + parser.add_argument( + '-e', '--extras', + default='', + help='Comma separated list of extras.', + type=parse_set + ) + args = parser.parse_args() + + result = dict() + requires = [] + stuff = [] + if args.level == 'dev': + result, requires, stuff = parse_pip_file('requirements-devel.txt') + + with mock.patch.object(setuptools, 'setup') as mock_setup: + import setup + assert setup # silence warning about unused imports + + # called arguments are in `mock_setup.call_args` + mock_args, mock_kwargs = mock_setup.call_args + requires = mock_kwargs.get('install_requires', []) + + requires_extras = mock_kwargs.get('extras_require', {}) + for e in args.extras: + if e in requires_extras: + requires.extend(requires_extras[e]) + + for pkg in pkg_resources.parse_requirements(requires): + # skip things we already know + # FIXME be smarter about merging things + if pkg.key in result: + continue + + specs = dict(pkg.specs) + if (('>=' in specs) and ('>' in specs)) \ + or (('<=' in specs) and ('<' in specs)): + print( + 'ERROR: Do not specify such weird constraints! ' + '("{}")'.format(pkg), + file=sys.stderr + ) + sys.exit(1) + + if '==' in specs: + result[pkg.key] = '{}=={}'.format(pkg.project_name, specs['==']) + + elif '>=' in specs: + if args.level == 'min': + result[pkg.key] = '{}=={}'.format( + pkg.project_name, + specs['>='] + ) + else: + result[pkg.key] = pkg + + elif '>' in specs: + if args.level == 'min': + minver_error(pkg.project_name) + else: + result[pkg.key] = pkg + + else: + if args.level == 'min': + minver_error(pkg.project_name) + else: + result[pkg.key] = pkg + + for s in stuff: + print(s) + + for k in sorted(result.iterkeys()): + print(result[k]) diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..de306c07 --- /dev/null +++ b/setup.py @@ -0,0 +1,140 @@ +# -*- 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. + +"""Invenio module that provides OAuth web authorization support.""" + +import os +import sys + +from setuptools import setup +from setuptools.command.test import test as TestCommand + +readme = open('README.rst').read() +history = open('CHANGES.rst').read() + +requirements = [ + 'Flask>=0.10.1', + 'six>=1.7.2', + 'invenio-accounts>=0.1.0', + 'Flask-OAuthlib>=0.6.0,<0.7', # quick fix for issue invenio#2158 + # FIXME new oauthlib release after 0.7.2 has some compatible problems with + # the used Flask-Oauthlib version. + 'oauthlib==0.7.2', +] + +test_requirements = [ + 'pytest>=2.7.0', + 'pytest-cov>=1.8.0', + 'pytest-pep8>=1.0.6', + 'coverage>=3.7.1', + 'flask-testing>=0.4.1', + 'httpretty>=0.8.10', +] + + +class PyTest(TestCommand): + """PyTest Test.""" + + user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")] + + def initialize_options(self): + """Init pytest.""" + TestCommand.initialize_options(self) + self.pytest_args = [] + try: + from ConfigParser import ConfigParser + except ImportError: + from configparser import ConfigParser + config = ConfigParser() + config.read('pytest.ini') + self.pytest_args = config.get('pytest', 'addopts').split(' ') + + def finalize_options(self): + """Finalize pytest.""" + TestCommand.finalize_options(self) + self.test_args = [] + self.test_suite = True + + def run_tests(self): + """Run tests.""" + # import here, cause outside the eggs aren't loaded + import pytest + import _pytest.config + pm = _pytest.config.get_plugin_manager() + pm.consider_setuptools_entrypoints() + errno = pytest.main(self.pytest_args) + sys.exit(errno) + +# Get the version string. Cannot be done with import! +g = {} +with open(os.path.join('invenio_oauthclient', 'version.py'), 'rt') as fp: + exec(fp.read(), g) + version = g['__version__'] + +setup( + name='invenio-oauthclient', + version=version, + description=__doc__, + long_description=readme + '\n\n' + history, + keywords='invenio oauth authentication', + license='GPLv2', + author='CERN', + author_email='info@invenio-software.org', + url='https://github.com/inveniosoftware/invenio-oauthclient', + packages=[ + 'invenio_oauthclient', + ], + zip_safe=False, + include_package_data=True, + platforms='any', + install_requires=requirements, + extras_require={ + 'docs': [ + 'Sphinx>=1.3', + 'sphinx_rtd_theme>=0.1.7' + ], + "github": [ + 'github3.py>=0.9', + ], + 'tests': test_requirements + }, + classifiers=[ + 'Environment :: Web Environment', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: GNU General Public License v2 (GPLv2)', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', + 'Topic :: Software Development :: Libraries :: Python Modules', + "Programming Language :: Python :: 2", + # 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + # 'Programming Language :: Python :: 3', + # 'Programming Language :: Python :: 3.3', + # 'Programming Language :: Python :: 3.4', + 'Development Status :: 1 - Planning', + ], + tests_require=test_requirements, + cmdclass={'test': PyTest}, +) diff --git a/upgrades/__init__.py b/tests/__init__.py similarity index 100% rename from upgrades/__init__.py rename to tests/__init__.py diff --git a/testsuite/fixture.py b/tests/fixture.py similarity index 100% rename from testsuite/fixture.py rename to tests/fixture.py diff --git a/testsuite/helpers.py b/tests/helpers.py similarity index 71% rename from testsuite/helpers.py rename to tests/helpers.py index 95ff45e1..ee763a71 100644 --- a/testsuite/helpers.py +++ b/tests/helpers.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of Invenio. -# Copyright (C) 2014 CERN. +# Copyright (C) 2014, 2015 CERN. # # Invenio is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -24,12 +24,23 @@ class OAuth2ClientTestCase(InvenioTestCase): - """ - Helper test case to make oauth client testing easier - """ + + """Helper test case to make oauth client testing easier.""" + + @property + def config(self): + cfg = super(OAuth2ClientTestCase, self).config + cfg['PACKAGES'] = [ + 'invenio_oauthclient', + 'invenio_accounts', + 'invenio.base', + ] + cfg['DEBUG'] = False + return cfg + def mock_response(self, app=None, data=None): - """ Mock the oauth response from a remote application """ - from invenio.modules.oauthclient.client import oauth + """Mock the oauth response from a remote application.""" + from invenio_oauthclient.client import oauth # Mock oauth remote application oauth.remote_apps[app].handle_oauth2_response = MagicMock( diff --git a/testsuite/test_contrib_orcid.py b/tests/test_contrib_orcid.py similarity index 95% rename from testsuite/test_contrib_orcid.py rename to tests/test_contrib_orcid.py index bd27f907..47f49b60 100644 --- a/testsuite/test_contrib_orcid.py +++ b/tests/test_contrib_orcid.py @@ -31,12 +31,13 @@ from invenio.testsuite import make_test_suite, run_test_suite +from invenio_oauthclient.contrib.orcid import REMOTE_APP, account_info + from mock import MagicMock from six.moves.urllib_parse import parse_qs, urlparse from .helpers import OAuth2ClientTestCase -from ..contrib.orcid import REMOTE_APP, account_info class OrcidTestCase(OAuth2ClientTestCase): @@ -75,7 +76,7 @@ def create_app(self): def setUp(self): """Setup test.""" - from invenio.modules.oauthclient.models import RemoteToken, \ + from invenio_oauthclient.models import RemoteToken, \ RemoteAccount from invenio_accounts.models import UserEXT, User RemoteToken.query.delete() @@ -90,7 +91,7 @@ def setUp(self): def tearDown(self): """Tear down test.""" - from invenio.modules.oauthclient.models import RemoteToken, \ + from invenio_oauthclient.models import RemoteToken, \ RemoteAccount from invenio_accounts.models import UserEXT, User RemoteToken.query.delete() @@ -105,7 +106,7 @@ def tearDown(self): def mock_response(self, app='test', data=None): """Mock the oauth response to use the remote.""" - from invenio.modules.oauthclient.client import oauth + from invenio_oauthclient.client import oauth # Mock oauth remote application oauth.remote_apps[app].handle_oauth2_response = MagicMock( @@ -113,13 +114,13 @@ def mock_response(self, app='test', data=None): ) def _get_state(self): - from invenio.modules.oauthclient.views.client import serializer + from invenio_oauthclient.views.client import serializer return serializer.dumps({'app': 'orcid', 'sid': session.sid, 'next': None, }) def test_account_info(self): """Test account info extraction.""" - from invenio.modules.oauthclient.client import oauth + from invenio_oauthclient.client import oauth # Ensure remote apps have been loaded (due to before first # request) self.client.get(url_for("oauthclient.login", remote_app='orcid')) @@ -158,7 +159,7 @@ def test_authorized_signup(self): from invenio_accounts.models import UserEXT, User with self.app.test_client() as c: - from invenio.modules.oauthclient.testsuite.fixture import orcid_bio + from .fixture import orcid_bio # Ensure remote apps have been loaded (due to before first # request) @@ -239,7 +240,7 @@ def test_authorized_reject(self): def test_authorized_already_authenticated(self): """Test authorized callback with sign-up.""" from invenio_accounts.models import UserEXT, User - from invenio.modules.oauthclient.testsuite.fixture import orcid_bio + from .fixture import orcid_bio # User logins self.login("tester", "tester") diff --git a/testsuite/test_forms.py b/tests/test_forms.py similarity index 93% rename from testsuite/test_forms.py rename to tests/test_forms.py index 56d88d7f..13766378 100644 --- a/testsuite/test_forms.py +++ b/tests/test_forms.py @@ -26,9 +26,9 @@ class FormTestCase(InvenioTestCase): - @patch('invenio.modules.oauthclient.forms.User') + @patch('invenio_oauthclient.forms.User') def test_validate_email(self, User): - from invenio.modules.oauthclient.forms import EmailSignUpForm + from invenio_oauthclient.forms import EmailSignUpForm self.assertFalse(EmailSignUpForm(email='invalidemail').validate()) diff --git a/testsuite/test_models.py b/tests/test_models.py similarity index 92% rename from testsuite/test_models.py rename to tests/test_models.py index 7d48dd2e..f106cb8a 100644 --- a/testsuite/test_models.py +++ b/tests/test_models.py @@ -26,14 +26,14 @@ class BaseTestCase(InvenioTestCase): def setUp(self): - from ..models import RemoteAccount, RemoteToken + from invenio_oauthclient.models import RemoteAccount, RemoteToken RemoteToken.query.delete() RemoteAccount.query.delete() db.session.commit() db.session.expunge_all() def tearDown(self): - from ..models import RemoteAccount, RemoteToken + from invenio_oauthclient.models import RemoteAccount, RemoteToken RemoteToken.query.delete() RemoteAccount.query.delete() db.session.commit() @@ -43,7 +43,7 @@ def tearDown(self): class RemoteAccountTestCase(BaseTestCase): def test_get_create(self): - from ..models import RemoteAccount + from invenio_oauthclient.models import RemoteAccount created_acc = RemoteAccount.create(1, "dev", dict(somekey="somevalue")) assert created_acc @@ -83,7 +83,7 @@ def tearDown(self): db.session.expunge_all() def test_get_create(self): - from ..models import RemoteAccount, RemoteToken + from invenio_oauthclient.models import RemoteAccount, RemoteToken t = RemoteToken.create(self.u1, "dev", "mytoken", "mysecret") assert t @@ -110,7 +110,7 @@ def test_get_create(self): assert RemoteToken.query.count() == 0 def test_get_regression(self): - from ..models import RemoteToken + from invenio_oauthclient.models import RemoteToken t3 = RemoteToken.create(self.u2, "dev", "mytoken", "mysecret") t4 = RemoteToken.create(self.u3, "dev", "mytoken", "mysecret") diff --git a/testsuite/test_views.py b/tests/test_views.py similarity index 93% rename from testsuite/test_views.py rename to tests/test_views.py index febee69c..e4d9bfd5 100644 --- a/testsuite/test_views.py +++ b/tests/test_views.py @@ -31,6 +31,7 @@ class RemoteAccountTestCase(OAuth2ClientTestCase): + def setUp(self): params = lambda x: dict( request_token_params={'scope': ''}, @@ -63,7 +64,7 @@ def setUp(self): self.handled_args = None self.handled_kwargs = None - from invenio.modules.oauthclient.models import RemoteToken, \ + from invenio_oauthclient.models import RemoteToken, \ RemoteAccount RemoteToken.query.delete() RemoteAccount.query.delete() @@ -75,7 +76,7 @@ def tearDown(self): self.handled_args = None self.handled_kwargs = None - from invenio.modules.oauthclient.models import RemoteToken, \ + from invenio_oauthclient.models import RemoteToken, \ RemoteAccount RemoteToken.query.delete() RemoteAccount.query.delete() @@ -96,7 +97,7 @@ def handler_invalid(self): def mock_response(self, app='test', data=None): """ Mock the oauth response to use the remote """ - from invenio.modules.oauthclient.client import oauth + from invenio_oauthclient.client import oauth # Mock oauth remote application oauth.remote_apps[app].handle_oauth2_response = MagicMock( @@ -108,7 +109,7 @@ def mock_response(self, app='test', data=None): ) def test_redirect_uri(self): - from invenio.modules.oauthclient.views.client import serializer + from invenio_oauthclient.views.client import serializer # Test redirect resp = self.client.get( @@ -176,7 +177,7 @@ def test_authorized(self): self.mock_response(app='test') self.mock_response(app='test_invalid') - from invenio.modules.oauthclient.views.client import serializer + from invenio_oauthclient.views.client import serializer state = serializer.dumps({ 'app': 'test', @@ -217,7 +218,7 @@ def test_authorized(self): def test_invalid_authorized_response(self): from simplejson import JSONDecodeError - from invenio.modules.oauthclient.client import oauth + from invenio_oauthclient.client import oauth # Fake an authorized request with self.app.test_client() as c: @@ -229,7 +230,7 @@ def test_invalid_authorized_response(self): side_effect=JSONDecodeError('Expecting value', '', 0) ) - from invenio.modules.oauthclient.views.client import serializer + from invenio_oauthclient.views.client import serializer state = serializer.dumps({ 'app': 'test', @@ -249,9 +250,9 @@ def test_invalid_authorized_response(self): ) - @patch('invenio.modules.oauthclient.views.client.session') + @patch('invenio_oauthclient.views.client.session') def test_state_token(self, session): - from invenio.modules.oauthclient.views.client import serializer + from invenio_oauthclient.views.client import serializer # Mock session id session.sid = '1234' @@ -309,11 +310,11 @@ def test_no_remote_app(self): )) @patch('invenio.ext.session.interface.SessionInterface.save_session') - @patch('invenio.modules.oauthclient.views.client.session') + @patch('invenio_oauthclient.views.client.session') def test_token_getter_setter(self, session, save_session): - from invenio.modules.oauthclient.models import RemoteToken - from invenio.modules.oauthclient.handlers import token_getter - from invenio.modules.oauthclient.client import oauth + from invenio_oauthclient.models import RemoteToken + from invenio_oauthclient.handlers import token_getter + from invenio_oauthclient.client import oauth # Mock user user = MagicMock() @@ -385,9 +386,9 @@ def test_token_getter_setter(self, session, save_session): assert t is None @patch('invenio.ext.session.interface.SessionInterface.save_session') - @patch('invenio.modules.oauthclient.views.client.session') + @patch('invenio_oauthclient.views.client.session') def test_rejected(self, session, save_session): - from invenio.modules.oauthclient.client import oauth + from invenio_oauthclient.client import oauth # Mock user id user = MagicMock() @@ -419,7 +420,7 @@ def test_rejected(self, session, save_session): # Imitate that the user authorized our request in the remote # application (however, the remote app will son reply with an # error) - from invenio.modules.oauthclient.views.client import serializer + from invenio_oauthclient.views.client import serializer state = serializer.dumps({ 'app': 'full', 'sid': '1234', 'next': None, }) @@ -432,7 +433,7 @@ def test_rejected(self, session, save_session): def test_settings_view(self): # Create a remove account (linked account) - from invenio.modules.oauthclient.models import RemoteAccount + from invenio_oauthclient.models import RemoteAccount RemoteAccount.create(1, 'testid', None) self.assert401(self.client.get(url_for('oauthclient_settings.index'), diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..01225796 --- /dev/null +++ b/tox.ini @@ -0,0 +1,29 @@ +# -*- 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. + +[tox] +envlist = py27 + +[testenv] +commands = {envpython} setup.py test