From df0607c0b93708494b17e9407388bda669f1ba6c Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Thu, 25 Dec 2014 06:01:37 +0100 Subject: [PATCH 01/18] Fix buildout. --- bootstrap.py => bootstrap-buildout.py | 32 ++++++++++++++++++--------- buildout.cfg | 18 +++++---------- 2 files changed, 27 insertions(+), 23 deletions(-) rename bootstrap.py => bootstrap-buildout.py (89%) diff --git a/bootstrap.py b/bootstrap-buildout.py similarity index 89% rename from bootstrap.py rename to bootstrap-buildout.py index 6b7e45ccac..a629566735 100644 --- a/bootstrap.py +++ b/bootstrap-buildout.py @@ -35,7 +35,7 @@ Simply run this script in a directory containing a buildout.cfg, using the Python that you want bin/buildout to use. -Note that by using --find-links to point to local resources, you can keep +Note that by using --find-links to point to local resources, you can keep this script from going over the network. ''' @@ -59,6 +59,8 @@ parser.add_option("--allow-site-packages", action="store_true", default=False, help=("Let bootstrap.py use existing site packages")) +parser.add_option("--setuptools-version", + help="use a specific setuptools version") options, args = parser.parse_args() @@ -75,20 +77,24 @@ from urllib2 import urlopen ez = {} -exec(urlopen('https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py' - ).read(), ez) +exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez) + if not options.allow_site_packages: # ez_setup imports site, which adds site packages - # this will remove them from the path to ensure that incompatible versions + # this will remove them from the path to ensure that incompatible versions # of setuptools are not in the path import site - # inside a virtualenv, there is no 'getsitepackages'. + # inside a virtualenv, there is no 'getsitepackages'. # We can't remove these reliably if hasattr(site, 'getsitepackages'): for sitepackage_path in site.getsitepackages(): sys.path[:] = [x for x in sys.path if sitepackage_path not in x] setup_args = dict(to_dir=tmpeggs, download_delay=0) + +if options.setuptools_version is not None: + setup_args['version'] = options.setuptools_version + ez['use_setuptools'](**setup_args) import setuptools import pkg_resources @@ -128,10 +134,15 @@ _final_parts = '*final-', '*final' def _final_version(parsed_version): - for part in parsed_version: - if (part[:1] == '*') and (part not in _final_parts): - return False - return True + try: + return not parsed_version.is_prerelease + except AttributeError: + # Older setuptools + for part in parsed_version: + if (part[:1] == '*') and (part not in _final_parts): + return False + return True + index = setuptools.package_index.PackageIndex( search_path=[setuptools_path]) if find_links: @@ -158,8 +169,7 @@ def _final_version(parsed_version): import subprocess if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0: raise Exception( - "Failed to execute command:\n%s", - repr(cmd)[1:-1]) + "Failed to execute command:\n%s" % repr(cmd)[1:-1]) ###################################################################### # Import and run buildout diff --git a/buildout.cfg b/buildout.cfg index 0b3897bba8..63f0ab30a6 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -1,22 +1,11 @@ [buildout] -extends = http://dist.plone.org/release/4.3-latest/versions.cfg -find-links = - http://localhost:3141/root/pypi/+simple/ - http://dist.plone.org/release/4.3-latest/ - http://dist.plone.org/thirdparty/ - -#develop = . +extends = http://dist.plone.org/release/4.3.4/versions.cfg parts = instance test sphinxbuilder templer -[versions] -setuptools = 2.1 -zc.buildout = 2.2.1 -zope.interface = 4.0.5 - [instance] recipe = plone.recipe.zope2instance user = admin:admin @@ -44,3 +33,8 @@ eggs = templer.buildout templer.plone templer.dexterity + +[versions] +setuptools = 8.3 +zc.buildout = 2.3.1 +zope.interface = 4.0.5 From b6e1e1629550e408a942ecc94314bda2fccd938b Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Thu, 25 Dec 2014 06:09:31 +0100 Subject: [PATCH 02/18] Add plone.restapi pkg. --- .gitignore | 1 + buildout.cfg | 7 +- src/plone.restapi/CHANGES.txt | 8 + src/plone.restapi/CONTRIBUTORS.txt | 6 + src/plone.restapi/README.txt | 5 + src/plone.restapi/docs/LICENSE.GPL | 339 ++++++++++++++++++ src/plone.restapi/docs/LICENSE.txt | 16 + src/plone.restapi/setup.cfg | 3 + src/plone.restapi/setup.py | 53 +++ src/plone.restapi/src/plone/__init__.py | 1 + .../src/plone/restapi/__init__.py | 5 + .../src/plone/restapi/configure.zcml | 21 ++ .../restapi/profiles/default/metadata.xml | 4 + .../src/plone/restapi/testing.py | 43 +++ .../src/plone/restapi/tests/__init__.py | 1 + .../src/plone/restapi/tests/robot_test.txt | 22 ++ .../src/plone/restapi/tests/test_example.py | 25 ++ .../src/plone/restapi/tests/test_robot.py | 13 + 18 files changed, 572 insertions(+), 1 deletion(-) create mode 100644 src/plone.restapi/CHANGES.txt create mode 100644 src/plone.restapi/CONTRIBUTORS.txt create mode 100644 src/plone.restapi/README.txt create mode 100644 src/plone.restapi/docs/LICENSE.GPL create mode 100644 src/plone.restapi/docs/LICENSE.txt create mode 100644 src/plone.restapi/setup.cfg create mode 100644 src/plone.restapi/setup.py create mode 100644 src/plone.restapi/src/plone/__init__.py create mode 100644 src/plone.restapi/src/plone/restapi/__init__.py create mode 100644 src/plone.restapi/src/plone/restapi/configure.zcml create mode 100644 src/plone.restapi/src/plone/restapi/profiles/default/metadata.xml create mode 100644 src/plone.restapi/src/plone/restapi/testing.py create mode 100644 src/plone.restapi/src/plone/restapi/tests/__init__.py create mode 100644 src/plone.restapi/src/plone/restapi/tests/robot_test.txt create mode 100644 src/plone.restapi/src/plone/restapi/tests/test_example.py create mode 100644 src/plone.restapi/src/plone/restapi/tests/test_robot.py diff --git a/.gitignore b/.gitignore index 655a14ad77..4e958bb77b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ /local.cfg .coverage *.egg-info +*.eggs /.installed.cfg *.pyc /.Python diff --git a/buildout.cfg b/buildout.cfg index 63f0ab30a6..9d1bc1e5f5 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -1,10 +1,12 @@ [buildout] extends = http://dist.plone.org/release/4.3.4/versions.cfg +extensions = mr.developer parts = instance test sphinxbuilder templer +auto-checkout = plone.restapi [instance] recipe = plone.recipe.zope2instance @@ -13,7 +15,7 @@ http-address = 8080 eggs = Plone Pillow -# plone.restapi [test] + plone.restapi [test] [test] recipe = zc.recipe.testrunner @@ -34,6 +36,9 @@ eggs = templer.plone templer.dexterity +[sources] +plone.restapi = fs plone.restapi + [versions] setuptools = 8.3 zc.buildout = 2.3.1 diff --git a/src/plone.restapi/CHANGES.txt b/src/plone.restapi/CHANGES.txt new file mode 100644 index 0000000000..59856bd9bd --- /dev/null +++ b/src/plone.restapi/CHANGES.txt @@ -0,0 +1,8 @@ +Changelog +========= + +0.1-dev (unreleased) +-------------------- + +- Package created using templer + [] \ No newline at end of file diff --git a/src/plone.restapi/CONTRIBUTORS.txt b/src/plone.restapi/CONTRIBUTORS.txt new file mode 100644 index 0000000000..d83f0568cb --- /dev/null +++ b/src/plone.restapi/CONTRIBUTORS.txt @@ -0,0 +1,6 @@ +Note: place names and roles of the people who contribute to this package + in this file, one to a line, like so: + +- Joe Schmoe, Original Author +- Bob Slob, contributed monkey patches +- Jane Main, wrote flibberty module diff --git a/src/plone.restapi/README.txt b/src/plone.restapi/README.txt new file mode 100644 index 0000000000..87f6662cc8 --- /dev/null +++ b/src/plone.restapi/README.txt @@ -0,0 +1,5 @@ +.. contents:: + +Introduction +============ + diff --git a/src/plone.restapi/docs/LICENSE.GPL b/src/plone.restapi/docs/LICENSE.GPL new file mode 100644 index 0000000000..d159169d10 --- /dev/null +++ b/src/plone.restapi/docs/LICENSE.GPL @@ -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/src/plone.restapi/docs/LICENSE.txt b/src/plone.restapi/docs/LICENSE.txt new file mode 100644 index 0000000000..cc119947cf --- /dev/null +++ b/src/plone.restapi/docs/LICENSE.txt @@ -0,0 +1,16 @@ +plone.restapi Copyright 2014, + +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., 59 Temple Place, Suite 330, Boston, +MA 02111-1307 USA. diff --git a/src/plone.restapi/setup.cfg b/src/plone.restapi/setup.cfg new file mode 100644 index 0000000000..46725688b7 --- /dev/null +++ b/src/plone.restapi/setup.cfg @@ -0,0 +1,3 @@ +[templer.local] +template = plone_basic + diff --git a/src/plone.restapi/setup.py b/src/plone.restapi/setup.py new file mode 100644 index 0000000000..2b01f21020 --- /dev/null +++ b/src/plone.restapi/setup.py @@ -0,0 +1,53 @@ +from setuptools import setup, find_packages +import os + +version = '0.1' + +long_description = ( + open('README.txt').read() + + '\n' + + 'Contributors\n' + '============\n' + + '\n' + + open('CONTRIBUTORS.txt').read() + + '\n' + + open('CHANGES.txt').read() + + '\n') + +setup(name='plone.restapi', + version=version, + description="RESTful API for Plone", + long_description=long_description, + # Get more strings from + # http://pypi.python.org/pypi?%3Aaction=list_classifiers + classifiers=[ + "Environment :: Web Environment", + "Framework :: Plone", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 2.6", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + keywords='', + author='', + author_email='', + url='http://svn.plone.org/svn/collective/', + license='gpl', + packages=find_packages('src'), + package_dir={'': 'src'}, + namespace_packages=['plone', ], + include_package_data=True, + zip_safe=False, + install_requires=[ + 'setuptools', + # -*- Extra requirements: -*- + ], + extras_require={'test': ['plone.app.testing[robot]>=4.2.2']}, + entry_points=""" + # -*- Entry points: -*- + [z3c.autoinclude.plugin] + target = plone + """, + setup_requires=["PasteScript"], + paster_plugins=["templer.localcommands"], + ) diff --git a/src/plone.restapi/src/plone/__init__.py b/src/plone.restapi/src/plone/__init__.py new file mode 100644 index 0000000000..de40ea7ca0 --- /dev/null +++ b/src/plone.restapi/src/plone/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/src/plone.restapi/src/plone/restapi/__init__.py b/src/plone.restapi/src/plone/restapi/__init__.py new file mode 100644 index 0000000000..41078453da --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/__init__.py @@ -0,0 +1,5 @@ +# -*- extra stuff goes here -*- + + +def initialize(context): + """Initializer called when used as a Zope 2 product.""" diff --git a/src/plone.restapi/src/plone/restapi/configure.zcml b/src/plone.restapi/src/plone/restapi/configure.zcml new file mode 100644 index 0000000000..5d92b553e8 --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/configure.zcml @@ -0,0 +1,21 @@ + + + + + + + + + + diff --git a/src/plone.restapi/src/plone/restapi/profiles/default/metadata.xml b/src/plone.restapi/src/plone/restapi/profiles/default/metadata.xml new file mode 100644 index 0000000000..000197f21d --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/profiles/default/metadata.xml @@ -0,0 +1,4 @@ + + + 0001 + diff --git a/src/plone.restapi/src/plone/restapi/testing.py b/src/plone.restapi/src/plone/restapi/testing.py new file mode 100644 index 0000000000..56ad9f4bfa --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/testing.py @@ -0,0 +1,43 @@ +from plone.app.testing import PloneSandboxLayer +from plone.app.testing import applyProfile +from plone.app.testing import PLONE_FIXTURE +from plone.app.testing import IntegrationTesting +from plone.app.testing import FunctionalTesting + +from plone.testing import z2 + +from zope.configuration import xmlconfig + + +class PlonerestapiLayer(PloneSandboxLayer): + + defaultBases = (PLONE_FIXTURE,) + + def setUpZope(self, app, configurationContext): + # Load ZCML + import plone.restapi + xmlconfig.file( + 'configure.zcml', + plone.restapi, + context=configurationContext + ) + + # Install products that use an old-style initialize() function + #z2.installProduct(app, 'Products.PloneFormGen') + +# def tearDownZope(self, app): +# # Uninstall products installed above +# z2.uninstallProduct(app, 'Products.PloneFormGen') + + def setUpPloneSite(self, portal): + applyProfile(portal, 'plone.restapi:default') + +PLONE_RESTAPI_FIXTURE = PlonerestapiLayer() +PLONE_RESTAPI_INTEGRATION_TESTING = IntegrationTesting( + bases=(PLONE_RESTAPI_FIXTURE,), + name="PlonerestapiLayer:Integration" +) +PLONE_RESTAPI_FUNCTIONAL_TESTING = FunctionalTesting( + bases=(PLONE_RESTAPI_FIXTURE, z2.ZSERVER_FIXTURE), + name="PlonerestapiLayer:Functional" +) diff --git a/src/plone.restapi/src/plone/restapi/tests/__init__.py b/src/plone.restapi/src/plone/restapi/tests/__init__.py new file mode 100644 index 0000000000..4287ca8617 --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/tests/__init__.py @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/src/plone.restapi/src/plone/restapi/tests/robot_test.txt b/src/plone.restapi/src/plone/restapi/tests/robot_test.txt new file mode 100644 index 0000000000..f4bbd4b1be --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/tests/robot_test.txt @@ -0,0 +1,22 @@ +*** Settings *** + +Library Selenium2Library timeout=10 implicit_wait=0.5 + +Suite Setup Start browser +Suite Teardown Close All Browsers + +*** Variables *** + +${BROWSER} = firefox + +*** Test Cases *** + +Plone site + [Tags] start + Go to http://localhost:55001/plone/ + Page should contain Plone site + +*** Keywords *** + +Start browser + Open browser http://localhost:55001/plone/ browser=${BROWSER} diff --git a/src/plone.restapi/src/plone/restapi/tests/test_example.py b/src/plone.restapi/src/plone/restapi/tests/test_example.py new file mode 100644 index 0000000000..c8726d2a26 --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/tests/test_example.py @@ -0,0 +1,25 @@ +import unittest2 as unittest + +from Products.CMFCore.utils import getToolByName + +from plone.restapi.testing import \ + PLONE_RESTAPI_INTEGRATION_TESTING + + +class TestExample(unittest.TestCase): + + layer = PLONE_RESTAPI_INTEGRATION_TESTING + + def setUp(self): + self.app = self.layer['app'] + self.portal = self.layer['portal'] + self.qi_tool = getToolByName(self.portal, 'portal_quickinstaller') + + def test_product_is_installed(self): + """ Validate that our products GS profile has been run and the product + installed + """ + pid = 'plone.restapi' + installed = [p['id'] for p in self.qi_tool.listInstalledProducts()] + self.assertTrue(pid in installed, + 'package appears not to have been installed') diff --git a/src/plone.restapi/src/plone/restapi/tests/test_robot.py b/src/plone.restapi/src/plone/restapi/tests/test_robot.py new file mode 100644 index 0000000000..a757ca310a --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/tests/test_robot.py @@ -0,0 +1,13 @@ +from plone.restapi.testing import PLONE_RESTAPI_FUNCTIONAL_TESTING +from plone.testing import layered +import robotsuite +import unittest + + +def test_suite(): + suite = unittest.TestSuite() + suite.addTests([ + layered(robotsuite.RobotTestSuite("robot_test.txt"), + layer=PLONE_RESTAPI_FUNCTIONAL_TESTING) + ]) + return suite \ No newline at end of file From 40cffa4e9c451ca2b109c82d76e0f0eeb284335d Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Thu, 25 Dec 2014 06:14:38 +0100 Subject: [PATCH 03/18] Clean up pkg. --- .../src/plone/restapi/__init__.py | 5 ---- .../src/plone/restapi/configure.zcml | 3 --- .../src/plone/restapi/testing.py | 8 ------ .../{robot_test.txt => robot/test.robot} | 0 .../src/plone/restapi/tests/test_robot.py | 26 ++++++++++++++----- 5 files changed, 20 insertions(+), 22 deletions(-) rename src/plone.restapi/src/plone/restapi/tests/{robot_test.txt => robot/test.robot} (100%) diff --git a/src/plone.restapi/src/plone/restapi/__init__.py b/src/plone.restapi/src/plone/restapi/__init__.py index 41078453da..e69de29bb2 100644 --- a/src/plone.restapi/src/plone/restapi/__init__.py +++ b/src/plone.restapi/src/plone/restapi/__init__.py @@ -1,5 +0,0 @@ -# -*- extra stuff goes here -*- - - -def initialize(context): - """Initializer called when used as a Zope 2 product.""" diff --git a/src/plone.restapi/src/plone/restapi/configure.zcml b/src/plone.restapi/src/plone/restapi/configure.zcml index 5d92b553e8..94bb181e42 100644 --- a/src/plone.restapi/src/plone/restapi/configure.zcml +++ b/src/plone.restapi/src/plone/restapi/configure.zcml @@ -5,8 +5,6 @@ xmlns:genericsetup="http://namespaces.zope.org/genericsetup" i18n_domain="plone.restapi"> - - - diff --git a/src/plone.restapi/src/plone/restapi/testing.py b/src/plone.restapi/src/plone/restapi/testing.py index 56ad9f4bfa..36714efe65 100644 --- a/src/plone.restapi/src/plone/restapi/testing.py +++ b/src/plone.restapi/src/plone/restapi/testing.py @@ -14,7 +14,6 @@ class PlonerestapiLayer(PloneSandboxLayer): defaultBases = (PLONE_FIXTURE,) def setUpZope(self, app, configurationContext): - # Load ZCML import plone.restapi xmlconfig.file( 'configure.zcml', @@ -22,13 +21,6 @@ def setUpZope(self, app, configurationContext): context=configurationContext ) - # Install products that use an old-style initialize() function - #z2.installProduct(app, 'Products.PloneFormGen') - -# def tearDownZope(self, app): -# # Uninstall products installed above -# z2.uninstallProduct(app, 'Products.PloneFormGen') - def setUpPloneSite(self, portal): applyProfile(portal, 'plone.restapi:default') diff --git a/src/plone.restapi/src/plone/restapi/tests/robot_test.txt b/src/plone.restapi/src/plone/restapi/tests/robot/test.robot similarity index 100% rename from src/plone.restapi/src/plone/restapi/tests/robot_test.txt rename to src/plone.restapi/src/plone/restapi/tests/robot/test.robot diff --git a/src/plone.restapi/src/plone/restapi/tests/test_robot.py b/src/plone.restapi/src/plone/restapi/tests/test_robot.py index a757ca310a..0d990c09bd 100644 --- a/src/plone.restapi/src/plone/restapi/tests/test_robot.py +++ b/src/plone.restapi/src/plone/restapi/tests/test_robot.py @@ -1,13 +1,27 @@ -from plone.restapi.testing import PLONE_RESTAPI_FUNCTIONAL_TESTING +from plone.app.testing import ROBOT_TEST_LEVEL +from plone.restapi.testing import PLONE_RESTAPI_FUNCTIONAL_TESTING from plone.testing import layered import robotsuite import unittest +import os def test_suite(): suite = unittest.TestSuite() - suite.addTests([ - layered(robotsuite.RobotTestSuite("robot_test.txt"), - layer=PLONE_RESTAPI_FUNCTIONAL_TESTING) - ]) - return suite \ No newline at end of file + current_dir = os.path.abspath(os.path.dirname(__file__)) + robot_dir = os.path.join(current_dir, 'robot') + robot_tests = [ + os.path.join('robot', doc) for doc in + os.listdir(robot_dir) if doc.endswith('.robot') and + doc.startswith('test_') + ] + for robot_test in robot_tests: + robottestsuite = robotsuite.RobotTestSuite(robot_test) + robottestsuite.level = ROBOT_TEST_LEVEL + suite.addTests([ + layered( + robottestsuite, + layer=PLONE_RESTAPI_FUNCTIONAL_TESTING + ), + ]) + return suite From 309af1d9102be9f697e6f7488faf8a644af9013d Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Thu, 25 Dec 2014 06:15:56 +0100 Subject: [PATCH 04/18] Add code analysis. --- buildout.cfg | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/buildout.cfg b/buildout.cfg index 9d1bc1e5f5..c9fb44a5e7 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -4,6 +4,7 @@ extensions = mr.developer parts = instance test + code-analysis sphinxbuilder templer auto-checkout = plone.restapi @@ -22,6 +23,10 @@ recipe = zc.recipe.testrunner eggs = ${instance:eggs} defaults = ['-s', 'plone.restapi', '--auto-color', '--auto-progress'] +[code-analysis] +recipe = plone.recipe.codeanalysis +directory = ${buildout:directory}/src + [sphinxbuilder] recipe = collective.recipe.sphinxbuilder source = ${buildout:directory}/docs/source From dd2c4dfcf26783c19696c4bedb80fb3ce14262f4 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Thu, 25 Dec 2014 06:17:31 +0100 Subject: [PATCH 05/18] Pep8. --- src/plone.restapi/setup.py | 21 +++++++++---------- .../src/plone/restapi/tests/__init__.py | 1 - 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/plone.restapi/setup.py b/src/plone.restapi/setup.py index 2b01f21020..2c7d84fb30 100644 --- a/src/plone.restapi/setup.py +++ b/src/plone.restapi/setup.py @@ -1,5 +1,4 @@ from setuptools import setup, find_packages -import os version = '0.1' @@ -21,17 +20,17 @@ # Get more strings from # http://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - "Environment :: Web Environment", - "Framework :: Plone", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 2.6", - "Topic :: Software Development :: Libraries :: Python Modules", - ], + "Environment :: Web Environment", + "Framework :: Plone", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 2.6", + "Topic :: Software Development :: Libraries :: Python Modules", + ], keywords='', - author='', - author_email='', - url='http://svn.plone.org/svn/collective/', + author='Timo Stollenwerk', + author_email='tisto@plone.org', + url='https://github.com/plone/plone.restapi/', license='gpl', packages=find_packages('src'), package_dir={'': 'src'}, diff --git a/src/plone.restapi/src/plone/restapi/tests/__init__.py b/src/plone.restapi/src/plone/restapi/tests/__init__.py index 4287ca8617..e69de29bb2 100644 --- a/src/plone.restapi/src/plone/restapi/tests/__init__.py +++ b/src/plone.restapi/src/plone/restapi/tests/__init__.py @@ -1 +0,0 @@ -# \ No newline at end of file From f05588f883cbc8af9c57d5a2b93759dc57bcc6ca Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Thu, 25 Dec 2014 08:57:40 +0100 Subject: [PATCH 06/18] Implement ISerializeToJson adapter. --- buildout.cfg | 1 + src/plone.restapi/setup.py | 5 +- .../src/plone/restapi/adapter.py | 64 ++++++++++++++ .../src/plone/restapi/browser/__init__.py | 0 .../src/plone/restapi/browser/configure.zcml | 16 ++++ .../src/plone/restapi/browser/traversal.py | 36 ++++++++ .../src/plone/restapi/configure.zcml | 4 + .../src/plone/restapi/interfaces.py | 12 +++ .../src/plone/restapi/testing.py | 5 +- .../src/plone/restapi/tests/test_adapter.py | 86 +++++++++++++++++++ .../src/plone/restapi/tests/test_example.py | 1 + .../src/plone/restapi/tests/test_robot.py | 1 + .../src/plone/restapi/tests/test_traversal.py | 30 +++++++ .../src/plone/restapi/tests/test_utils.py | 84 ++++++++++++++++++ src/plone.restapi/src/plone/restapi/utils.py | 30 +++++++ 15 files changed, 372 insertions(+), 3 deletions(-) create mode 100644 src/plone.restapi/src/plone/restapi/adapter.py create mode 100644 src/plone.restapi/src/plone/restapi/browser/__init__.py create mode 100644 src/plone.restapi/src/plone/restapi/browser/configure.zcml create mode 100644 src/plone.restapi/src/plone/restapi/browser/traversal.py create mode 100644 src/plone.restapi/src/plone/restapi/interfaces.py create mode 100644 src/plone.restapi/src/plone/restapi/tests/test_adapter.py create mode 100644 src/plone.restapi/src/plone/restapi/tests/test_traversal.py create mode 100644 src/plone.restapi/src/plone/restapi/tests/test_utils.py create mode 100644 src/plone.restapi/src/plone/restapi/utils.py diff --git a/buildout.cfg b/buildout.cfg index c9fb44a5e7..05b03a9681 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -16,6 +16,7 @@ http-address = 8080 eggs = Plone Pillow + plone.app.debugtoolbar plone.restapi [test] [test] diff --git a/src/plone.restapi/setup.py b/src/plone.restapi/setup.py index 2c7d84fb30..6cb20041d3 100644 --- a/src/plone.restapi/setup.py +++ b/src/plone.restapi/setup.py @@ -41,7 +41,10 @@ 'setuptools', # -*- Extra requirements: -*- ], - extras_require={'test': ['plone.app.testing[robot]>=4.2.2']}, + extras_require={'test': [ + 'plone.app.contenttypes', + 'plone.app.testing[robot]>=4.2.2' + ]}, entry_points=""" # -*- Entry points: -*- [z3c.autoinclude.plugin] diff --git a/src/plone.restapi/src/plone/restapi/adapter.py b/src/plone.restapi/src/plone/restapi/adapter.py new file mode 100644 index 0000000000..5c183a942e --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/adapter.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +from plone.app.textfield import RichText +from zope.schema import Datetime +from Products.CMFCore.interfaces import IFolderish + +import json + +from zope.interface import implementer +from zope.component import adapter + +from plone.restapi.utils import get_object_schema +from plone.restapi.interfaces import ISerializeToJson +from plone.dexterity.interfaces import IDexterityContent + + +@implementer(ISerializeToJson) +@adapter(IDexterityContent) +def SerializeToJson(context): + result = { + "@context": "http://www.w3.org/ns/hydra/context.jsonld", + "@id": context.absolute_url(), + } + if IFolderish.providedBy(context): + result['@type'] = 'Collection' + result['member'] = [ + { + '@id': member.absolute_url() + '/@@json', + 'title': member.title + } + for member_id, member in context.objectItems() + ] + else: + result['@type'] = 'Resource' + for title, schema_object in get_object_schema(context): + value = getattr(context, title, None) + if value is not None: + # RichText + if isinstance(schema_object, RichText): + result[title] = value.output + # DateTime + elif isinstance(schema_object, Datetime): + # Return DateTime in ISO-8601 format. See + # https://pypi.python.org/pypi/DateTime/3.0 and + # http://www.w3.org/TR/NOTE-datetime for details. + # XXX: We might want to change that in the future. + result[title] = value().ISO8601() + # Callables + elif callable(schema_object): + result[title] = value() + # Tuple + elif isinstance(value, tuple): + result[title] = list(value) + # List + elif isinstance(value, list): + result[title] = value + # String + elif isinstance(value, str): + result[title] = value + # Unicode + elif isinstance(value, unicode): + result[title] = value + else: + result[title] = str(value) + return json.dumps(result) diff --git a/src/plone.restapi/src/plone/restapi/browser/__init__.py b/src/plone.restapi/src/plone/restapi/browser/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/plone.restapi/src/plone/restapi/browser/configure.zcml b/src/plone.restapi/src/plone/restapi/browser/configure.zcml new file mode 100644 index 0000000000..8c8313b5c2 --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/browser/configure.zcml @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/src/plone.restapi/src/plone/restapi/browser/traversal.py b/src/plone.restapi/src/plone/restapi/browser/traversal.py new file mode 100644 index 0000000000..a892ed6834 --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/browser/traversal.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +from OFS.SimpleItem import SimpleItem +from zope.interface import implements +from zope.publisher.interfaces import IPublishTraverse +from plone.restapi.interfaces import IAPIRequest +from zope.interface import alsoProvides +from plone.dexterity.interfaces import IDexterityContent +from zope.component import adapter +from ZPublisher.BaseRequest import DefaultPublishTraverse +from Products.Five.browser import BrowserView +from plone.restapi.interfaces import ISerializeToJson + + +class ApiTraverse(SimpleItem): + """Mark the @@json view with the IAPIRequest interface. + """ + implements(IPublishTraverse) + + def publishTraverse(self, request, name): + alsoProvides(self.request, IAPIRequest) + return self.context + + +class JsonView(BrowserView): + + def __call__(self): + self.request.response.setHeader('Content-Type', 'application/json') + return ISerializeToJson(self.context) + + +@adapter(IDexterityContent, IAPIRequest) +class APIInnerTraverser(DefaultPublishTraverse): + + def publishTraverse(self, request, name): + return JsonView(self.context, request) + return super(APIInnerTraverser, self).publishTraverse(request, name) diff --git a/src/plone.restapi/src/plone/restapi/configure.zcml b/src/plone.restapi/src/plone/restapi/configure.zcml index 94bb181e42..76594fcb5b 100644 --- a/src/plone.restapi/src/plone/restapi/configure.zcml +++ b/src/plone.restapi/src/plone/restapi/configure.zcml @@ -15,4 +15,8 @@ provides="Products.GenericSetup.interfaces.EXTENSION" /> + + + + diff --git a/src/plone.restapi/src/plone/restapi/interfaces.py b/src/plone.restapi/src/plone/restapi/interfaces.py new file mode 100644 index 0000000000..ab6e7863f2 --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/interfaces.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +from zope.interface import Interface + + +class IAPIRequest(Interface): + """Marker for API requests. + """ + + +class ISerializeToJson(Interface): + """Adapter to serialize a Dexterity object into a JSON object. + """ diff --git a/src/plone.restapi/src/plone/restapi/testing.py b/src/plone.restapi/src/plone/restapi/testing.py index 36714efe65..c234c12c8b 100644 --- a/src/plone.restapi/src/plone/restapi/testing.py +++ b/src/plone.restapi/src/plone/restapi/testing.py @@ -1,6 +1,7 @@ +# -*- coding: utf-8 -*- +from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE from plone.app.testing import PloneSandboxLayer from plone.app.testing import applyProfile -from plone.app.testing import PLONE_FIXTURE from plone.app.testing import IntegrationTesting from plone.app.testing import FunctionalTesting @@ -11,7 +12,7 @@ class PlonerestapiLayer(PloneSandboxLayer): - defaultBases = (PLONE_FIXTURE,) + defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,) def setUpZope(self, app, configurationContext): import plone.restapi diff --git a/src/plone.restapi/src/plone/restapi/tests/test_adapter.py b/src/plone.restapi/src/plone/restapi/tests/test_adapter.py new file mode 100644 index 0000000000..2b52542b2d --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/tests/test_adapter.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +import unittest2 as unittest + +from plone.restapi.interfaces import ISerializeToJson +from plone.app.textfield.value import RichTextValue + +from plone.restapi.testing import \ + PLONE_RESTAPI_INTEGRATION_TESTING +from DateTime import DateTime + +import json + + +class TestSerializeToJsonAdapter(unittest.TestCase): + + layer = PLONE_RESTAPI_INTEGRATION_TESTING + + def setUp(self): + self.app = self.layer['app'] + self.portal = self.layer['portal'] + self.portal_url = self.portal.absolute_url() + self.portal.invokeFactory('Document', id='doc1', title='Document 1') + + def test_serialize_to_json_adapter_returns_hydra_context(self): + self.assertEqual( + json.loads(ISerializeToJson(self.portal.doc1))['@context'], + u'http://www.w3.org/ns/hydra/context.jsonld' + ) + + def test_serialize_to_json_adapter_returns_hydra_id(self): + self.assertEqual( + json.loads(ISerializeToJson(self.portal.doc1))['@id'], + self.portal_url + '/doc1' + ) + + def test_serialize_to_json_adapter_returns_hydra_type(self): + self.assertEqual( + json.loads(ISerializeToJson(self.portal.doc1))['@type'], + u'Resource' + ) + + def test_serialize_to_json_adapter_returns_title(self): + self.assertEqual( + json.loads(ISerializeToJson(self.portal.doc1))['title'], + u'Document 1' + ) + + def test_serialize_to_json_adapter_returns_desciption(self): + self.portal.doc1.description = u'This is a document' + self.assertEqual( + json.loads(ISerializeToJson(self.portal.doc1))['description'], + u'This is a document' + ) + + def test_serialize_to_json_adapter_returns_rich_text(self): + self.portal.doc1.text = RichTextValue( + u"Lorem ipsum.", + 'text/plain', + 'text/html' + ) + self.assertEqual( + json.loads(ISerializeToJson(self.portal.doc1)).get('text'), + u'

Lorem ipsum.

' + ) + + def test_serialize_to_json_adapter_returns_effective(self): + self.portal.doc1.setEffectiveDate(DateTime('2014/04/04')) + self.assertEqual( + json.loads(ISerializeToJson(self.portal.doc1))['effective'], + '2014-04-04T00:00:00' + ) + + def test_serialize_to_json_adapter_returns_expires(self): + self.portal.doc1.setExpirationDate(DateTime('2017/01/01')) + self.assertEqual( + json.loads(ISerializeToJson(self.portal.doc1))['expires'], + '2017-01-01T00:00:00' + ) + + def test_serialize_to_json_adapter_ignores_underscore_values(self): + self.assertFalse( + '__name__' in json.loads(ISerializeToJson(self.portal.doc1)) + ) + self.assertFalse( + 'manage_options' in json.loads(ISerializeToJson(self.portal.doc1)) + ) diff --git a/src/plone.restapi/src/plone/restapi/tests/test_example.py b/src/plone.restapi/src/plone/restapi/tests/test_example.py index c8726d2a26..8475afb7ee 100644 --- a/src/plone.restapi/src/plone/restapi/tests/test_example.py +++ b/src/plone.restapi/src/plone/restapi/tests/test_example.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import unittest2 as unittest from Products.CMFCore.utils import getToolByName diff --git a/src/plone.restapi/src/plone/restapi/tests/test_robot.py b/src/plone.restapi/src/plone/restapi/tests/test_robot.py index 0d990c09bd..e9e124c865 100644 --- a/src/plone.restapi/src/plone/restapi/tests/test_robot.py +++ b/src/plone.restapi/src/plone/restapi/tests/test_robot.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from plone.app.testing import ROBOT_TEST_LEVEL from plone.restapi.testing import PLONE_RESTAPI_FUNCTIONAL_TESTING from plone.testing import layered diff --git a/src/plone.restapi/src/plone/restapi/tests/test_traversal.py b/src/plone.restapi/src/plone/restapi/tests/test_traversal.py new file mode 100644 index 0000000000..d8f9d88752 --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/tests/test_traversal.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +from plone.restapi.testing import\ + PLONE_RESTAPI_FUNCTIONAL_TESTING +from plone.app.testing import setRoles +from plone.app.testing import TEST_USER_ID +from plone.app.testing import SITE_OWNER_NAME +from plone.app.testing import SITE_OWNER_PASSWORD +from plone.testing.z2 import Browser + +import unittest2 as unittest + + +class TestTraversal(unittest.TestCase): + + layer = PLONE_RESTAPI_FUNCTIONAL_TESTING + + def setUp(self): + self.app = self.layer['app'] + self.portal = self.layer['portal'] + self.portal_url = self.portal.absolute_url() + setRoles(self.portal, TEST_USER_ID, ['Manager']) + self.browser = Browser(self.app) + self.browser.handleErrors = False + self.browser.addHeader( + 'Authorization', + 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) + ) + + def test_traversal_with_json_format(self): + self.browser.open(self.portal_url + '?format=json') diff --git a/src/plone.restapi/src/plone/restapi/tests/test_utils.py b/src/plone.restapi/src/plone/restapi/tests/test_utils.py new file mode 100644 index 0000000000..0dc499952f --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/tests/test_utils.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- +import unittest2 as unittest +from plone.restapi.utils import underscore_to_camelcase +from plone.restapi.utils import get_object_schema +from plone.restapi.testing import\ + PLONE_RESTAPI_INTEGRATION_TESTING +from plone.app.testing import setRoles +from plone.app.testing import TEST_USER_ID + + +class GetObjectSchemaUnitTest(unittest.TestCase): + + layer = PLONE_RESTAPI_INTEGRATION_TESTING + + def setUp(self): + self.app = self.layer['app'] + self.portal = self.layer['portal'] + setRoles(self.portal, TEST_USER_ID, ['Manager']) + + def test_document(self): + self.portal.invokeFactory('Document', id='doc1', title='Doc 1') + schema = [x[0] for x in get_object_schema(self.portal.doc1)] + self.assertEqual( + schema, + [ + 'text', + 'title', + 'allow_discussion', + 'exclude_from_nav', + 'relatedItems', + 'table_of_contents', + 'meta_type', + 'isPrincipiaFolderish', + 'icon', + 'rights', + 'contributors', + 'effective', + 'expires', + 'language', + 'subjects', + 'creators', + 'description', + 'changeNote' + ] + ) + + def test_folder(self): + self.portal.invokeFactory('Folder', id='folder1', title='Folder 1') + schema = [x[0] for x in get_object_schema(self.portal.folder1)] + self.assertEqual( + schema, + [ + 'title', + 'allow_discussion', + 'exclude_from_nav', + 'relatedItems', + 'nextPreviousEnabled', + 'isAnObjectManager', + 'meta_type', + 'meta_types', + 'isPrincipiaFolderish', + 'icon', + 'rights', + 'contributors', + 'effective', + 'expires', + 'language', + 'subjects', + 'creators', + 'description' + ] + ) + + +class UnderscoreToCamelcaseUnitTest(unittest.TestCase): + + def test_empty(self): + self.assertEqual(underscore_to_camelcase(''), '') + + def test_simple_term(self): + self.assertEqual(underscore_to_camelcase('lorem'), 'Lorem') + + def test_two_simple_terms(self): + self.assertEqual(underscore_to_camelcase('lorem_ipsum'), 'LoremIpsum') diff --git a/src/plone.restapi/src/plone/restapi/utils.py b/src/plone.restapi/src/plone/restapi/utils.py new file mode 100644 index 0000000000..ad6fb15090 --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/utils.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +from zope.schema import getFields +from zope.interface import providedBy +from plone.behavior.interfaces import IBehaviorAssignable + + +def get_object_schema(obj): + object_schema = set() + for iface in providedBy(obj).flattened(): + for name, field in getFields(iface).items(): + no_underscore_method = not name.startswith('_') + no_manage_method = not name.startswith('manage') + if no_underscore_method and no_manage_method: + if name not in object_schema: + object_schema.add(name) + yield name, field + + assignable = IBehaviorAssignable(obj, None) + if assignable: + for behavior in assignable.enumerateBehaviors(): + for name, field in getFields(behavior.interface).items(): + if name not in object_schema: + object_schema.add(name) + yield name, field + + +def underscore_to_camelcase(underscore_string): + return ''.join( + x for x in underscore_string.title() if not x.isspace() + ).replace('_', '') From f790fb01671fc6cdf7f43a7e4e6328107cdce24d Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Thu, 25 Dec 2014 12:17:48 +0100 Subject: [PATCH 07/18] Add SerializeSiteRootToJson adapter. --- .../src/plone/restapi/adapter.py | 36 ++++++++++++++----- .../src/plone/restapi/browser/configure.zcml | 17 ++++++--- .../src/plone/restapi/browser/traversal.py | 15 ++++---- .../src/plone/restapi/configure.zcml | 1 + .../src/plone/restapi/tests/test_traversal.py | 35 ++++++++++++++++-- 5 files changed, 83 insertions(+), 21 deletions(-) diff --git a/src/plone.restapi/src/plone/restapi/adapter.py b/src/plone.restapi/src/plone/restapi/adapter.py index 5c183a942e..7806545c85 100644 --- a/src/plone.restapi/src/plone/restapi/adapter.py +++ b/src/plone.restapi/src/plone/restapi/adapter.py @@ -1,20 +1,40 @@ # -*- coding: utf-8 -*- -from plone.app.textfield import RichText -from zope.schema import Datetime +from Products.CMFCore.interfaces import IContentish from Products.CMFCore.interfaces import IFolderish +from Products.CMFPlone.interfaces import IPloneSiteRoot -import json +from plone.app.textfield import RichText +from plone.restapi.utils import get_object_schema +from plone.restapi.interfaces import ISerializeToJson +from zope.schema import Datetime from zope.interface import implementer from zope.component import adapter -from plone.restapi.utils import get_object_schema -from plone.restapi.interfaces import ISerializeToJson -from plone.dexterity.interfaces import IDexterityContent +import json + + +@implementer(ISerializeToJson) +@adapter(IPloneSiteRoot) +def SerializeSiteRootToJson(context): + result = { + "@context": "http://www.w3.org/ns/hydra/context.jsonld", + "@id": context.absolute_url(), + '@type': 'Collection', + } + result['member'] = [ + { + '@id': member.absolute_url() + '/@@json', + 'title': member.title + } + for member_id, member in context.objectItems() + if IContentish.providedBy(member) + ] + return json.dumps(result, indent=2, sort_keys=True) @implementer(ISerializeToJson) -@adapter(IDexterityContent) +@adapter(IContentish) def SerializeToJson(context): result = { "@context": "http://www.w3.org/ns/hydra/context.jsonld", @@ -61,4 +81,4 @@ def SerializeToJson(context): result[title] = value else: result[title] = str(value) - return json.dumps(result) + return json.dumps(result, indent=2, sort_keys=True) diff --git a/src/plone.restapi/src/plone/restapi/browser/configure.zcml b/src/plone.restapi/src/plone/restapi/browser/configure.zcml index 8c8313b5c2..a3f5678840 100644 --- a/src/plone.restapi/src/plone/restapi/browser/configure.zcml +++ b/src/plone.restapi/src/plone/restapi/browser/configure.zcml @@ -3,14 +3,23 @@ xmlns:five="http://namespaces.zope.org/five" xmlns:browser="http://namespaces.zope.org/browser"> - + - + + + + + diff --git a/src/plone.restapi/src/plone/restapi/browser/traversal.py b/src/plone.restapi/src/plone/restapi/browser/traversal.py index a892ed6834..8fda4d2779 100644 --- a/src/plone.restapi/src/plone/restapi/browser/traversal.py +++ b/src/plone.restapi/src/plone/restapi/browser/traversal.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from Products.CMFPlone.interfaces import IPloneSiteRoot from OFS.SimpleItem import SimpleItem from zope.interface import implements from zope.publisher.interfaces import IPublishTraverse @@ -7,11 +8,10 @@ from plone.dexterity.interfaces import IDexterityContent from zope.component import adapter from ZPublisher.BaseRequest import DefaultPublishTraverse -from Products.Five.browser import BrowserView from plone.restapi.interfaces import ISerializeToJson -class ApiTraverse(SimpleItem): +class MarkAsApiRequest(SimpleItem): """Mark the @@json view with the IAPIRequest interface. """ implements(IPublishTraverse) @@ -21,16 +21,17 @@ def publishTraverse(self, request, name): return self.context -class JsonView(BrowserView): +@adapter(IPloneSiteRoot, IAPIRequest) +class APISiteRootTraverser(DefaultPublishTraverse): - def __call__(self): + def publishTraverse(self, request, name): self.request.response.setHeader('Content-Type', 'application/json') return ISerializeToJson(self.context) @adapter(IDexterityContent, IAPIRequest) -class APIInnerTraverser(DefaultPublishTraverse): +class APIDexterityTraverser(DefaultPublishTraverse): def publishTraverse(self, request, name): - return JsonView(self.context, request) - return super(APIInnerTraverser, self).publishTraverse(request, name) + self.request.response.setHeader('Content-Type', 'application/json') + return ISerializeToJson(self.context) diff --git a/src/plone.restapi/src/plone/restapi/configure.zcml b/src/plone.restapi/src/plone/restapi/configure.zcml index 76594fcb5b..a904521172 100644 --- a/src/plone.restapi/src/plone/restapi/configure.zcml +++ b/src/plone.restapi/src/plone/restapi/configure.zcml @@ -18,5 +18,6 @@ + diff --git a/src/plone.restapi/src/plone/restapi/tests/test_traversal.py b/src/plone.restapi/src/plone/restapi/tests/test_traversal.py index d8f9d88752..446fd4177f 100644 --- a/src/plone.restapi/src/plone/restapi/tests/test_traversal.py +++ b/src/plone.restapi/src/plone/restapi/tests/test_traversal.py @@ -9,6 +9,8 @@ import unittest2 as unittest +import json + class TestTraversal(unittest.TestCase): @@ -19,6 +21,14 @@ def setUp(self): self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ['Manager']) + self.portal.invokeFactory('Document', id='document1') + self.document = self.portal.document1 + self.document_url = self.document.absolute_url() + self.portal.invokeFactory('Folder', id='folder1') + self.folder = self.portal.folder1 + self.folder_url = self.folder.absolute_url() + import transaction + transaction.commit() self.browser = Browser(self.app) self.browser.handleErrors = False self.browser.addHeader( @@ -26,5 +36,26 @@ def setUp(self): 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) ) - def test_traversal_with_json_format(self): - self.browser.open(self.portal_url + '?format=json') + def test_document_traversal(self): + self.browser.open(self.document_url + '/@@json') + self.assertTrue(json.loads(self.browser.contents)) + self.assertEqual( + json.loads(self.browser.contents).get('@id'), + self.document_url + ) + + def test_folder_traversal(self): + self.browser.open(self.folder_url + '/@@json') + self.assertTrue(json.loads(self.browser.contents)) + self.assertEqual( + json.loads(self.browser.contents).get('@id'), + self.folder_url + ) + + def test_site_root_traversal_with_json_format(self): + self.browser.open(self.portal_url + '/@@json') + self.assertTrue(json.loads(self.browser.contents)) + self.assertEqual( + json.loads(self.browser.contents).get('@id'), + self.portal_url + ) From db80679857b2ffb563a868d32dbc3066783d2dac Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Thu, 25 Dec 2014 22:16:43 +0100 Subject: [PATCH 08/18] Fix unauthorized on non-published folders. --- .../src/plone/restapi/browser/traversal.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/plone.restapi/src/plone/restapi/browser/traversal.py b/src/plone.restapi/src/plone/restapi/browser/traversal.py index 8fda4d2779..761bdafc68 100644 --- a/src/plone.restapi/src/plone/restapi/browser/traversal.py +++ b/src/plone.restapi/src/plone/restapi/browser/traversal.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- -from Products.CMFPlone.interfaces import IPloneSiteRoot from OFS.SimpleItem import SimpleItem +from Products.CMFPlone.interfaces import IPloneSiteRoot +from Products.Five.browser import BrowserView from zope.interface import implements from zope.publisher.interfaces import IPublishTraverse from plone.restapi.interfaces import IAPIRequest @@ -21,17 +22,22 @@ def publishTraverse(self, request, name): return self.context +class SerializeToJsonView(BrowserView): + + def __call__(self): + self.request.response.setHeader('Content-Type', 'application/json') + return ISerializeToJson(self.context) + + @adapter(IPloneSiteRoot, IAPIRequest) class APISiteRootTraverser(DefaultPublishTraverse): def publishTraverse(self, request, name): - self.request.response.setHeader('Content-Type', 'application/json') - return ISerializeToJson(self.context) + return SerializeToJsonView(self.context, request) @adapter(IDexterityContent, IAPIRequest) class APIDexterityTraverser(DefaultPublishTraverse): def publishTraverse(self, request, name): - self.request.response.setHeader('Content-Type', 'application/json') - return ISerializeToJson(self.context) + return SerializeToJsonView(self.context, request) From 19a342a62befbc611cb632c7245b8810355c7b16 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Fri, 26 Dec 2014 13:37:12 +0100 Subject: [PATCH 09/18] Add test coverage. --- .coveragerc | 3 +++ .gitignore | 1 + buildout.cfg | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000000..60220d83c0 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,3 @@ +[report] +omit = + src/plone.restapi/src/plone/restapi/tests/test_robot diff --git a/.gitignore b/.gitignore index 4e958bb77b..7aba39d0a4 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ docs/Makefile docs/make.bat docs/doctrees docs/html +htmlcov bower_components diff --git a/buildout.cfg b/buildout.cfg index 05b03a9681..89b83930fb 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -4,6 +4,9 @@ extensions = mr.developer parts = instance test + coverage + report + test-coverage code-analysis sphinxbuilder templer @@ -24,6 +27,29 @@ recipe = zc.recipe.testrunner eggs = ${instance:eggs} defaults = ['-s', 'plone.restapi', '--auto-color', '--auto-progress'] +[coverage] +recipe = zc.recipe.egg +eggs = coverage +initialization = + include = '--source=${buildout:directory}/src/plone.restapi' + sys.argv = sys.argv[:] + ['run', include, 'bin/test'] + +[report] +recipe = zc.recipe.egg +eggs = coverage +scripts = coverage=report +initialization = + sys.argv = sys.argv[:] + ['html', '-i'] + +[test-coverage] +recipe = collective.recipe.template +input = inline: + #!/bin/sh + ${buildout:directory}/bin/coverage + ${buildout:directory}/bin/report +output = ${buildout:directory}/bin/test-coverage +mode = 755 + [code-analysis] recipe = plone.recipe.codeanalysis directory = ${buildout:directory}/src From 48cda8239aee42d1425aa953bb62b3d85f077453 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Fri, 26 Dec 2014 13:38:47 +0100 Subject: [PATCH 10/18] Add notes why we need to wrap the json response into a browser view. --- src/plone.restapi/src/plone/restapi/browser/traversal.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plone.restapi/src/plone/restapi/browser/traversal.py b/src/plone.restapi/src/plone/restapi/browser/traversal.py index 761bdafc68..a5f6b98c2b 100644 --- a/src/plone.restapi/src/plone/restapi/browser/traversal.py +++ b/src/plone.restapi/src/plone/restapi/browser/traversal.py @@ -25,6 +25,8 @@ def publishTraverse(self, request, name): class SerializeToJsonView(BrowserView): def __call__(self): + # The json response needs to be wrapped in a browser view to have + # access to context and request. self.request.response.setHeader('Content-Type', 'application/json') return ISerializeToJson(self.context) From 6f2a17f0492acecf01922a37bae461ded6588b9f Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Fri, 26 Dec 2014 22:31:20 +0100 Subject: [PATCH 11/18] Implement an IBeforeTraverseEvent subscriber to set the IAPIRequest interface. --- src/plone.restapi/setup.py | 5 ++- .../src/plone/restapi/browser/configure.zcml | 9 +++- .../src/plone/restapi/browser/traversal.py | 30 ++++++++----- .../src/plone/restapi/tests/test_traversal.py | 44 +++++++++++++++++-- 4 files changed, 72 insertions(+), 16 deletions(-) diff --git a/src/plone.restapi/setup.py b/src/plone.restapi/setup.py index 6cb20041d3..0293d338b2 100644 --- a/src/plone.restapi/setup.py +++ b/src/plone.restapi/setup.py @@ -39,11 +39,12 @@ zip_safe=False, install_requires=[ 'setuptools', - # -*- Extra requirements: -*- + 'plone.validatehook', ], extras_require={'test': [ 'plone.app.contenttypes', - 'plone.app.testing[robot]>=4.2.2' + 'plone.app.testing[robot]>=4.2.2', + 'requests', ]}, entry_points=""" # -*- Entry points: -*- diff --git a/src/plone.restapi/src/plone/restapi/browser/configure.zcml b/src/plone.restapi/src/plone/restapi/browser/configure.zcml index a3f5678840..629e584c48 100644 --- a/src/plone.restapi/src/plone/restapi/browser/configure.zcml +++ b/src/plone.restapi/src/plone/restapi/browser/configure.zcml @@ -19,7 +19,14 @@ permission="zope2.View" /> - + + + + diff --git a/src/plone.restapi/src/plone/restapi/browser/traversal.py b/src/plone.restapi/src/plone/restapi/browser/traversal.py index a5f6b98c2b..151c3ab818 100644 --- a/src/plone.restapi/src/plone/restapi/browser/traversal.py +++ b/src/plone.restapi/src/plone/restapi/browser/traversal.py @@ -2,15 +2,25 @@ from OFS.SimpleItem import SimpleItem from Products.CMFPlone.interfaces import IPloneSiteRoot from Products.Five.browser import BrowserView -from zope.interface import implements -from zope.publisher.interfaces import IPublishTraverse -from plone.restapi.interfaces import IAPIRequest -from zope.interface import alsoProvides -from plone.dexterity.interfaces import IDexterityContent -from zope.component import adapter from ZPublisher.BaseRequest import DefaultPublishTraverse + +from plone.dexterity.interfaces import IDexterityContent +from plone.restapi.interfaces import IAPIRequest from plone.restapi.interfaces import ISerializeToJson +from zope.component import adapter +from zope.interface import alsoProvides +from zope.interface import implements +from zope.publisher.interfaces import IPublishTraverse + + +def mark_as_api_request(context, event): + """Mark views with application/json as Content-Type with the IAPIRequest + interface. + """ + if event.request.getHeader('Content-Type') == 'application/json': + alsoProvides(event.request, IAPIRequest) + class MarkAsApiRequest(SimpleItem): """Mark the @@json view with the IAPIRequest interface. @@ -31,15 +41,15 @@ def __call__(self): return ISerializeToJson(self.context) -@adapter(IPloneSiteRoot, IAPIRequest) -class APISiteRootTraverser(DefaultPublishTraverse): +@adapter(IDexterityContent, IAPIRequest) +class APIDexterityTraverser(DefaultPublishTraverse): def publishTraverse(self, request, name): return SerializeToJsonView(self.context, request) -@adapter(IDexterityContent, IAPIRequest) -class APIDexterityTraverser(DefaultPublishTraverse): +@adapter(IPloneSiteRoot, IAPIRequest) +class APISiteRootTraverser(DefaultPublishTraverse): def publishTraverse(self, request, name): return SerializeToJsonView(self.context, request) diff --git a/src/plone.restapi/src/plone/restapi/tests/test_traversal.py b/src/plone.restapi/src/plone/restapi/tests/test_traversal.py index 446fd4177f..9567d02a5e 100644 --- a/src/plone.restapi/src/plone/restapi/tests/test_traversal.py +++ b/src/plone.restapi/src/plone/restapi/tests/test_traversal.py @@ -10,6 +10,7 @@ import unittest2 as unittest import json +import requests class TestTraversal(unittest.TestCase): @@ -36,7 +37,7 @@ def setUp(self): 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) ) - def test_document_traversal(self): + def test_json_view_document_traversal(self): self.browser.open(self.document_url + '/@@json') self.assertTrue(json.loads(self.browser.contents)) self.assertEqual( @@ -44,7 +45,7 @@ def test_document_traversal(self): self.document_url ) - def test_folder_traversal(self): + def test_json_view_folder_traversal(self): self.browser.open(self.folder_url + '/@@json') self.assertTrue(json.loads(self.browser.contents)) self.assertEqual( @@ -52,10 +53,47 @@ def test_folder_traversal(self): self.folder_url ) - def test_site_root_traversal_with_json_format(self): + @unittest.skip('not working yet') + def test_json_view_site_root_traversal(self): self.browser.open(self.portal_url + '/@@json') self.assertTrue(json.loads(self.browser.contents)) self.assertEqual( json.loads(self.browser.contents).get('@id'), self.portal_url ) + + def test_document_traversal(self): + response = requests.get( + self.document_url, + headers={'content-type': 'application/json'}, + auth=(SITE_OWNER_NAME, SITE_OWNER_PASSWORD) + ) + self.assertEqual(response.status_code, 200) + self.assertEqual( + response.headers.get('content-type'), + 'application/json', + 'When sending a GET request with content-type: application/json ' + + 'the server should respond with sending back application/json.' + ) + self.assertEqual( + response.json()['@id'], + self.document_url + ) + + def test_folder_traversal(self): + response = requests.get( + self.folder_url, + headers={'content-type': 'application/json'}, + auth=(SITE_OWNER_NAME, SITE_OWNER_PASSWORD) + ) + self.assertEqual(response.status_code, 200) + self.assertEqual( + response.headers.get('content-type'), + 'application/json', + 'When sending a GET request with content-type: application/json ' + + 'the server should respond with sending back application/json.' + ) + self.assertEqual( + response.json()['@id'], + self.folder_url + ) From 7a3448965e99856f518f8e1c569e4ec5aded72d5 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Fri, 26 Dec 2014 23:05:34 +0100 Subject: [PATCH 12/18] Fix the APISiteRootTraverser. --- .../src/plone/restapi/browser/configure.zcml | 2 +- .../src/plone/restapi/browser/traversal.py | 11 ++++++++++- .../src/plone/restapi/tests/test_traversal.py | 19 ++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/plone.restapi/src/plone/restapi/browser/configure.zcml b/src/plone.restapi/src/plone/restapi/browser/configure.zcml index 629e584c48..6ad5854d09 100644 --- a/src/plone.restapi/src/plone/restapi/browser/configure.zcml +++ b/src/plone.restapi/src/plone/restapi/browser/configure.zcml @@ -26,7 +26,7 @@ /> - + diff --git a/src/plone.restapi/src/plone/restapi/browser/traversal.py b/src/plone.restapi/src/plone/restapi/browser/traversal.py index 151c3ab818..f9e25f0220 100644 --- a/src/plone.restapi/src/plone/restapi/browser/traversal.py +++ b/src/plone.restapi/src/plone/restapi/browser/traversal.py @@ -52,4 +52,13 @@ def publishTraverse(self, request, name): class APISiteRootTraverser(DefaultPublishTraverse): def publishTraverse(self, request, name): - return SerializeToJsonView(self.context, request) + # Traversal in Plone always starts with the site root. Therefore we + # have to guess if this is a real request for the portal root. What + # Plone does on portal root is pretty complex, therefore we have to + # check for multiple different scenarios. It would be good if this + # could be refactored to be simpler and more reliable. + if name == '' or name == 'folder_listing' or name == 'front-page': + return SerializeToJsonView(self.context, request) + # If this is just the first traversal step, make sure the traversal + # continues. + return DefaultPublishTraverse.publishTraverse(self, request, name) diff --git a/src/plone.restapi/src/plone/restapi/tests/test_traversal.py b/src/plone.restapi/src/plone/restapi/tests/test_traversal.py index 9567d02a5e..47be1950ab 100644 --- a/src/plone.restapi/src/plone/restapi/tests/test_traversal.py +++ b/src/plone.restapi/src/plone/restapi/tests/test_traversal.py @@ -53,7 +53,6 @@ def test_json_view_folder_traversal(self): self.folder_url ) - @unittest.skip('not working yet') def test_json_view_site_root_traversal(self): self.browser.open(self.portal_url + '/@@json') self.assertTrue(json.loads(self.browser.contents)) @@ -97,3 +96,21 @@ def test_folder_traversal(self): response.json()['@id'], self.folder_url ) + + def test_site_root_traversal(self): + response = requests.get( + self.portal_url, + headers={'content-type': 'application/json'}, + auth=(SITE_OWNER_NAME, SITE_OWNER_PASSWORD) + ) + self.assertEqual(response.status_code, 200) + self.assertEqual( + response.headers.get('content-type'), + 'application/json', + 'When sending a GET request with content-type: application/json ' + + 'the server should respond with sending back application/json.' + ) + self.assertEqual( + response.json()['@id'], + self.portal_url + ) From 6b6e36b313406347622841706a7e3601a7249f0a Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Fri, 26 Dec 2014 23:09:27 +0100 Subject: [PATCH 13/18] Rename test_traversal. --- .../tests/{test_traversal.py => test_browser_traversal.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/plone.restapi/src/plone/restapi/tests/{test_traversal.py => test_browser_traversal.py} (100%) diff --git a/src/plone.restapi/src/plone/restapi/tests/test_traversal.py b/src/plone.restapi/src/plone/restapi/tests/test_browser_traversal.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/tests/test_traversal.py rename to src/plone.restapi/src/plone/restapi/tests/test_browser_traversal.py From 304643d63e00ca17e955e80f87cbc1524b8108a8 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sat, 27 Dec 2014 09:19:06 +0100 Subject: [PATCH 14/18] Rename *.txt -> *.rst; Add real world generated json data to docs. --- docs/source/hydra.rst | 20 ++++++++++++++++++- docs/source/index.rst | 1 + .../{CHANGES.txt => CHANGES.rst} | 0 .../{CONTRIBUTORS.txt => CONTRIBUTORS.rst} | 0 src/plone.restapi/{README.txt => README.rst} | 1 - src/plone.restapi/setup.py | 6 +++--- .../restapi/tests/test_browser_traversal.py | 9 +++++++++ 7 files changed, 32 insertions(+), 5 deletions(-) rename src/plone.restapi/{CHANGES.txt => CHANGES.rst} (100%) rename src/plone.restapi/{CONTRIBUTORS.txt => CONTRIBUTORS.rst} (100%) rename src/plone.restapi/{README.txt => README.rst} (97%) diff --git a/docs/source/hydra.rst b/docs/source/hydra.rst index dc2990d506..a567ffbdd9 100644 --- a/docs/source/hydra.rst +++ b/docs/source/hydra.rst @@ -43,7 +43,6 @@ Plone Portal Root (A Hydra Collection):: ] } - - @context: Defines what kind of resource this is and the meaning of the terms used within this resource. - @id: Unique identifier for resources (IRIs). The @id property can be used to @@ -76,6 +75,25 @@ Plone Document (A Hydra Resource):: "text": "

Lorem Ipsum

", } +Implementation +-------------- + +Plone Document: + +.. literalinclude:: _json/document.json + :language: jsonld + +Plone Folder: + +.. literalinclude:: _json/folder.json + :language: jsonld + + +Plone Portal Root: + +.. literalinclude:: _json/siteroot.json + :language: json-ld + Resource Operations / CRUD -------------------------- diff --git a/docs/source/index.rst b/docs/source/index.rst index 428964ae01..7bc9db70b9 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -20,6 +20,7 @@ Contents .. toctree:: :maxdepth: 3 + hydra item folder site-search diff --git a/src/plone.restapi/CHANGES.txt b/src/plone.restapi/CHANGES.rst similarity index 100% rename from src/plone.restapi/CHANGES.txt rename to src/plone.restapi/CHANGES.rst diff --git a/src/plone.restapi/CONTRIBUTORS.txt b/src/plone.restapi/CONTRIBUTORS.rst similarity index 100% rename from src/plone.restapi/CONTRIBUTORS.txt rename to src/plone.restapi/CONTRIBUTORS.rst diff --git a/src/plone.restapi/README.txt b/src/plone.restapi/README.rst similarity index 97% rename from src/plone.restapi/README.txt rename to src/plone.restapi/README.rst index 87f6662cc8..b4ab4131fa 100644 --- a/src/plone.restapi/README.txt +++ b/src/plone.restapi/README.rst @@ -2,4 +2,3 @@ Introduction ============ - diff --git a/src/plone.restapi/setup.py b/src/plone.restapi/setup.py index 0293d338b2..4e27ab96a1 100644 --- a/src/plone.restapi/setup.py +++ b/src/plone.restapi/setup.py @@ -3,14 +3,14 @@ version = '0.1' long_description = ( - open('README.txt').read() + open('README.rst').read() + '\n' + 'Contributors\n' '============\n' + '\n' + - open('CONTRIBUTORS.txt').read() + open('CONTRIBUTORS.rst').read() + '\n' + - open('CHANGES.txt').read() + open('CHANGES.rst').read() + '\n') setup(name='plone.restapi', diff --git a/src/plone.restapi/src/plone/restapi/tests/test_browser_traversal.py b/src/plone.restapi/src/plone/restapi/tests/test_browser_traversal.py index 47be1950ab..1d5520e432 100644 --- a/src/plone.restapi/src/plone/restapi/tests/test_browser_traversal.py +++ b/src/plone.restapi/src/plone/restapi/tests/test_browser_traversal.py @@ -13,6 +13,12 @@ import requests +def save_response_for_documentation(filename, response): + f = open('../../docs/source/_json/%s' % filename, 'w') + f.write(response.text) + f.close() + + class TestTraversal(unittest.TestCase): layer = PLONE_RESTAPI_FUNCTIONAL_TESTING @@ -78,6 +84,7 @@ def test_document_traversal(self): response.json()['@id'], self.document_url ) + save_response_for_documentation('document.json', response) def test_folder_traversal(self): response = requests.get( @@ -96,6 +103,7 @@ def test_folder_traversal(self): response.json()['@id'], self.folder_url ) + save_response_for_documentation('folder.json', response) def test_site_root_traversal(self): response = requests.get( @@ -114,3 +122,4 @@ def test_site_root_traversal(self): response.json()['@id'], self.portal_url ) + save_response_for_documentation('siteroot.json', response) From b938290307380b5afffbed83e4b497973d72eb1e Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sat, 27 Dec 2014 09:23:37 +0100 Subject: [PATCH 15/18] Add json files for tests. --- docs/source/_json/document.json | 20 ++++++++++++++++++++ docs/source/_json/folder.json | 24 ++++++++++++++++++++++++ docs/source/_json/siteroot.json | 19 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 docs/source/_json/document.json create mode 100644 docs/source/_json/folder.json create mode 100644 docs/source/_json/siteroot.json diff --git a/docs/source/_json/document.json b/docs/source/_json/document.json new file mode 100644 index 0000000000..58df14b606 --- /dev/null +++ b/docs/source/_json/document.json @@ -0,0 +1,20 @@ +{ + "@context": "http://www.w3.org/ns/hydra/context.jsonld", + "@id": "http://localhost:55001/plone/document1", + "@type": "Resource", + "contributors": [], + "creators": [ + "test_user_1_" + ], + "description": "", + "effective": "1969-12-31T00:00:00+01:00", + "exclude_from_nav": "False", + "expires": "2499-12-31T00:00:00+01:00", + "icon": "++resource++plone.dexterity.item.gif", + "isPrincipiaFolderish": "0", + "language": "", + "meta_type": "Dexterity Item", + "relatedItems": [], + "rights": "", + "title": "" +} \ No newline at end of file diff --git a/docs/source/_json/folder.json b/docs/source/_json/folder.json new file mode 100644 index 0000000000..98ba4f7260 --- /dev/null +++ b/docs/source/_json/folder.json @@ -0,0 +1,24 @@ +{ + "@context": "http://www.w3.org/ns/hydra/context.jsonld", + "@id": "http://localhost:55001/plone/folder1", + "@type": "Collection", + "contributors": [], + "creators": [ + "test_user_1_" + ], + "description": "", + "effective": "1969-12-31T00:00:00+01:00", + "exclude_from_nav": "False", + "expires": "2499-12-31T00:00:00+01:00", + "icon": "++resource++plone.dexterity.item.gif", + "isAnObjectManager": "1", + "isPrincipiaFolderish": "1", + "language": "", + "member": [], + "meta_type": "Dexterity Container", + "meta_types": [], + "nextPreviousEnabled": "False", + "relatedItems": [], + "rights": "", + "title": "" +} \ No newline at end of file diff --git a/docs/source/_json/siteroot.json b/docs/source/_json/siteroot.json new file mode 100644 index 0000000000..6fbd5c6c50 --- /dev/null +++ b/docs/source/_json/siteroot.json @@ -0,0 +1,19 @@ +{ + "@context": "http://www.w3.org/ns/hydra/context.jsonld", + "@id": "http://localhost:55001/plone", + "@type": "Collection", + "member": [ + { + "@id": "http://localhost:55001/plone/robot-test-folder/@@json", + "title": "Test Folder" + }, + { + "@id": "http://localhost:55001/plone/document1/@@json", + "title": "" + }, + { + "@id": "http://localhost:55001/plone/folder1/@@json", + "title": "" + } + ] +} \ No newline at end of file From 0de16169ca5c19242659f4217cae6d1bb94ace82 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sat, 27 Dec 2014 10:13:39 +0100 Subject: [PATCH 16/18] Add test_documentation.py. --- docs/source/_json/document.json | 7 ++- docs/source/_json/siteroot.json | 19 ------ .../src/plone/restapi/browser/traversal.py | 2 +- .../restapi/tests/test_browser_traversal.py | 9 --- .../plone/restapi/tests/test_documentation.py | 59 +++++++++++++++++++ 5 files changed, 64 insertions(+), 32 deletions(-) delete mode 100644 docs/source/_json/siteroot.json create mode 100644 src/plone.restapi/src/plone/restapi/tests/test_documentation.py diff --git a/docs/source/_json/document.json b/docs/source/_json/document.json index 58df14b606..b530caed5b 100644 --- a/docs/source/_json/document.json +++ b/docs/source/_json/document.json @@ -1,12 +1,12 @@ { "@context": "http://www.w3.org/ns/hydra/context.jsonld", - "@id": "http://localhost:55001/plone/document1", + "@id": "http://localhost:55001/plone/front-page", "@type": "Resource", "contributors": [], "creators": [ "test_user_1_" ], - "description": "", + "description": "Congratulations! You have successfully installed Plone.", "effective": "1969-12-31T00:00:00+01:00", "exclude_from_nav": "False", "expires": "2499-12-31T00:00:00+01:00", @@ -16,5 +16,6 @@ "meta_type": "Dexterity Item", "relatedItems": [], "rights": "", - "title": "" + "text": "

If you're seeing this instead of the web site you were expecting, the owner of this web site has just installed Plone. Do not contact the Plone Team or the Plone mailing lists about this.

", + "title": "Welcome to Plone" } \ No newline at end of file diff --git a/docs/source/_json/siteroot.json b/docs/source/_json/siteroot.json deleted file mode 100644 index 6fbd5c6c50..0000000000 --- a/docs/source/_json/siteroot.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "@context": "http://www.w3.org/ns/hydra/context.jsonld", - "@id": "http://localhost:55001/plone", - "@type": "Collection", - "member": [ - { - "@id": "http://localhost:55001/plone/robot-test-folder/@@json", - "title": "Test Folder" - }, - { - "@id": "http://localhost:55001/plone/document1/@@json", - "title": "" - }, - { - "@id": "http://localhost:55001/plone/folder1/@@json", - "title": "" - } - ] -} \ No newline at end of file diff --git a/src/plone.restapi/src/plone/restapi/browser/traversal.py b/src/plone.restapi/src/plone/restapi/browser/traversal.py index f9e25f0220..b1272744be 100644 --- a/src/plone.restapi/src/plone/restapi/browser/traversal.py +++ b/src/plone.restapi/src/plone/restapi/browser/traversal.py @@ -57,7 +57,7 @@ def publishTraverse(self, request, name): # Plone does on portal root is pretty complex, therefore we have to # check for multiple different scenarios. It would be good if this # could be refactored to be simpler and more reliable. - if name == '' or name == 'folder_listing' or name == 'front-page': + if name == '' or name == 'folder_listing': return SerializeToJsonView(self.context, request) # If this is just the first traversal step, make sure the traversal # continues. diff --git a/src/plone.restapi/src/plone/restapi/tests/test_browser_traversal.py b/src/plone.restapi/src/plone/restapi/tests/test_browser_traversal.py index 1d5520e432..47be1950ab 100644 --- a/src/plone.restapi/src/plone/restapi/tests/test_browser_traversal.py +++ b/src/plone.restapi/src/plone/restapi/tests/test_browser_traversal.py @@ -13,12 +13,6 @@ import requests -def save_response_for_documentation(filename, response): - f = open('../../docs/source/_json/%s' % filename, 'w') - f.write(response.text) - f.close() - - class TestTraversal(unittest.TestCase): layer = PLONE_RESTAPI_FUNCTIONAL_TESTING @@ -84,7 +78,6 @@ def test_document_traversal(self): response.json()['@id'], self.document_url ) - save_response_for_documentation('document.json', response) def test_folder_traversal(self): response = requests.get( @@ -103,7 +96,6 @@ def test_folder_traversal(self): response.json()['@id'], self.folder_url ) - save_response_for_documentation('folder.json', response) def test_site_root_traversal(self): response = requests.get( @@ -122,4 +114,3 @@ def test_site_root_traversal(self): response.json()['@id'], self.portal_url ) - save_response_for_documentation('siteroot.json', response) diff --git a/src/plone.restapi/src/plone/restapi/tests/test_documentation.py b/src/plone.restapi/src/plone/restapi/tests/test_documentation.py new file mode 100644 index 0000000000..281213c0d1 --- /dev/null +++ b/src/plone.restapi/src/plone/restapi/tests/test_documentation.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +from plone.restapi.testing import\ + PLONE_RESTAPI_FUNCTIONAL_TESTING +from plone.app.testing import setRoles +from plone.app.testing import TEST_USER_ID +from plone.app.testing import SITE_OWNER_NAME +from plone.app.testing import SITE_OWNER_PASSWORD +from plone.app.textfield.value import RichTextValue +from plone.testing.z2 import Browser + +import unittest2 as unittest + +import requests + + +def save_response_for_documentation(filename, response): + f = open('../../docs/source/_json/%s' % filename, 'w') + f.write(response.text) + f.close() + + +class TestTraversal(unittest.TestCase): + + layer = PLONE_RESTAPI_FUNCTIONAL_TESTING + + def setUp(self): + self.app = self.layer['app'] + self.request = self.layer['request'] + self.portal = self.layer['portal'] + self.portal_url = self.portal.absolute_url() + setRoles(self.portal, TEST_USER_ID, ['Manager']) + self.portal.invokeFactory('Document', id='front-page') + self.document = self.portal['front-page'] + self.document.title = u"Welcome to Plone" + self.document.description = u"Congratulations! You have successfully installed Plone." + self.document.text = RichTextValue( + u"If you're seeing this instead of the web site you were " + + u"expecting, the owner of this web site has just installed " + + u"Plone. Do not contact the Plone Team or the Plone mailing " + + u"lists about this.", + 'text/plain', + 'text/html' + ) + import transaction + transaction.commit() + self.browser = Browser(self.app) + self.browser.handleErrors = False + self.browser.addHeader( + 'Authorization', + 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) + ) + + def test_documentation_document(self): + response = requests.get( + self.document.absolute_url(), + headers={'content-type': 'application/json'}, + auth=(SITE_OWNER_NAME, SITE_OWNER_PASSWORD) + ) + save_response_for_documentation('document.json', response) From f6aa40ea95df77fbb1a31c8b16791c4bf762ff32 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sat, 27 Dec 2014 10:55:58 +0100 Subject: [PATCH 17/18] Move src dir one level up. --- src/plone.restapi/CHANGES.rst => CHANGES.rst | 0 .../CONTRIBUTORS.rst => CONTRIBUTORS.rst | 0 src/plone.restapi/README.rst => README.rst | 0 buildout.cfg | 5 +- src/plone.restapi/setup.cfg => setup.cfg | 0 src/plone.restapi/setup.py => setup.py | 0 src/plone.restapi/docs/LICENSE.GPL | 339 ------------------ src/plone.restapi/docs/LICENSE.txt | 16 - src/{plone.restapi/src => }/plone/__init__.py | 0 .../src => }/plone/restapi/__init__.py | 0 .../src => }/plone/restapi/adapter.py | 0 .../plone/restapi/browser/__init__.py | 0 .../plone/restapi/browser/configure.zcml | 0 .../plone/restapi/browser/traversal.py | 0 .../src => }/plone/restapi/configure.zcml | 0 .../src => }/plone/restapi/interfaces.py | 0 .../restapi/profiles/default/metadata.xml | 0 .../src => }/plone/restapi/testing.py | 0 .../src => }/plone/restapi/tests/__init__.py | 0 .../plone/restapi/tests/robot/test.robot | 0 .../plone/restapi/tests/test_adapter.py | 0 .../restapi/tests/test_browser_traversal.py | 0 .../plone/restapi/tests/test_documentation.py | 0 .../plone/restapi/tests/test_example.py | 0 .../plone/restapi/tests/test_robot.py | 0 .../plone/restapi/tests/test_utils.py | 0 .../src => }/plone/restapi/utils.py | 0 27 files changed, 1 insertion(+), 359 deletions(-) rename src/plone.restapi/CHANGES.rst => CHANGES.rst (100%) rename src/plone.restapi/CONTRIBUTORS.rst => CONTRIBUTORS.rst (100%) rename src/plone.restapi/README.rst => README.rst (100%) rename src/plone.restapi/setup.cfg => setup.cfg (100%) rename src/plone.restapi/setup.py => setup.py (100%) delete mode 100644 src/plone.restapi/docs/LICENSE.GPL delete mode 100644 src/plone.restapi/docs/LICENSE.txt rename src/{plone.restapi/src => }/plone/__init__.py (100%) rename src/{plone.restapi/src => }/plone/restapi/__init__.py (100%) rename src/{plone.restapi/src => }/plone/restapi/adapter.py (100%) rename src/{plone.restapi/src => }/plone/restapi/browser/__init__.py (100%) rename src/{plone.restapi/src => }/plone/restapi/browser/configure.zcml (100%) rename src/{plone.restapi/src => }/plone/restapi/browser/traversal.py (100%) rename src/{plone.restapi/src => }/plone/restapi/configure.zcml (100%) rename src/{plone.restapi/src => }/plone/restapi/interfaces.py (100%) rename src/{plone.restapi/src => }/plone/restapi/profiles/default/metadata.xml (100%) rename src/{plone.restapi/src => }/plone/restapi/testing.py (100%) rename src/{plone.restapi/src => }/plone/restapi/tests/__init__.py (100%) rename src/{plone.restapi/src => }/plone/restapi/tests/robot/test.robot (100%) rename src/{plone.restapi/src => }/plone/restapi/tests/test_adapter.py (100%) rename src/{plone.restapi/src => }/plone/restapi/tests/test_browser_traversal.py (100%) rename src/{plone.restapi/src => }/plone/restapi/tests/test_documentation.py (100%) rename src/{plone.restapi/src => }/plone/restapi/tests/test_example.py (100%) rename src/{plone.restapi/src => }/plone/restapi/tests/test_robot.py (100%) rename src/{plone.restapi/src => }/plone/restapi/tests/test_utils.py (100%) rename src/{plone.restapi/src => }/plone/restapi/utils.py (100%) diff --git a/src/plone.restapi/CHANGES.rst b/CHANGES.rst similarity index 100% rename from src/plone.restapi/CHANGES.rst rename to CHANGES.rst diff --git a/src/plone.restapi/CONTRIBUTORS.rst b/CONTRIBUTORS.rst similarity index 100% rename from src/plone.restapi/CONTRIBUTORS.rst rename to CONTRIBUTORS.rst diff --git a/src/plone.restapi/README.rst b/README.rst similarity index 100% rename from src/plone.restapi/README.rst rename to README.rst diff --git a/buildout.cfg b/buildout.cfg index 89b83930fb..ea8a4c7a19 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -10,7 +10,7 @@ parts = code-analysis sphinxbuilder templer -auto-checkout = plone.restapi +develop = . [instance] recipe = plone.recipe.zope2instance @@ -68,9 +68,6 @@ eggs = templer.plone templer.dexterity -[sources] -plone.restapi = fs plone.restapi - [versions] setuptools = 8.3 zc.buildout = 2.3.1 diff --git a/src/plone.restapi/setup.cfg b/setup.cfg similarity index 100% rename from src/plone.restapi/setup.cfg rename to setup.cfg diff --git a/src/plone.restapi/setup.py b/setup.py similarity index 100% rename from src/plone.restapi/setup.py rename to setup.py diff --git a/src/plone.restapi/docs/LICENSE.GPL b/src/plone.restapi/docs/LICENSE.GPL deleted file mode 100644 index d159169d10..0000000000 --- a/src/plone.restapi/docs/LICENSE.GPL +++ /dev/null @@ -1,339 +0,0 @@ - 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/src/plone.restapi/docs/LICENSE.txt b/src/plone.restapi/docs/LICENSE.txt deleted file mode 100644 index cc119947cf..0000000000 --- a/src/plone.restapi/docs/LICENSE.txt +++ /dev/null @@ -1,16 +0,0 @@ -plone.restapi Copyright 2014, - -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., 59 Temple Place, Suite 330, Boston, -MA 02111-1307 USA. diff --git a/src/plone.restapi/src/plone/__init__.py b/src/plone/__init__.py similarity index 100% rename from src/plone.restapi/src/plone/__init__.py rename to src/plone/__init__.py diff --git a/src/plone.restapi/src/plone/restapi/__init__.py b/src/plone/restapi/__init__.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/__init__.py rename to src/plone/restapi/__init__.py diff --git a/src/plone.restapi/src/plone/restapi/adapter.py b/src/plone/restapi/adapter.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/adapter.py rename to src/plone/restapi/adapter.py diff --git a/src/plone.restapi/src/plone/restapi/browser/__init__.py b/src/plone/restapi/browser/__init__.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/browser/__init__.py rename to src/plone/restapi/browser/__init__.py diff --git a/src/plone.restapi/src/plone/restapi/browser/configure.zcml b/src/plone/restapi/browser/configure.zcml similarity index 100% rename from src/plone.restapi/src/plone/restapi/browser/configure.zcml rename to src/plone/restapi/browser/configure.zcml diff --git a/src/plone.restapi/src/plone/restapi/browser/traversal.py b/src/plone/restapi/browser/traversal.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/browser/traversal.py rename to src/plone/restapi/browser/traversal.py diff --git a/src/plone.restapi/src/plone/restapi/configure.zcml b/src/plone/restapi/configure.zcml similarity index 100% rename from src/plone.restapi/src/plone/restapi/configure.zcml rename to src/plone/restapi/configure.zcml diff --git a/src/plone.restapi/src/plone/restapi/interfaces.py b/src/plone/restapi/interfaces.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/interfaces.py rename to src/plone/restapi/interfaces.py diff --git a/src/plone.restapi/src/plone/restapi/profiles/default/metadata.xml b/src/plone/restapi/profiles/default/metadata.xml similarity index 100% rename from src/plone.restapi/src/plone/restapi/profiles/default/metadata.xml rename to src/plone/restapi/profiles/default/metadata.xml diff --git a/src/plone.restapi/src/plone/restapi/testing.py b/src/plone/restapi/testing.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/testing.py rename to src/plone/restapi/testing.py diff --git a/src/plone.restapi/src/plone/restapi/tests/__init__.py b/src/plone/restapi/tests/__init__.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/tests/__init__.py rename to src/plone/restapi/tests/__init__.py diff --git a/src/plone.restapi/src/plone/restapi/tests/robot/test.robot b/src/plone/restapi/tests/robot/test.robot similarity index 100% rename from src/plone.restapi/src/plone/restapi/tests/robot/test.robot rename to src/plone/restapi/tests/robot/test.robot diff --git a/src/plone.restapi/src/plone/restapi/tests/test_adapter.py b/src/plone/restapi/tests/test_adapter.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/tests/test_adapter.py rename to src/plone/restapi/tests/test_adapter.py diff --git a/src/plone.restapi/src/plone/restapi/tests/test_browser_traversal.py b/src/plone/restapi/tests/test_browser_traversal.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/tests/test_browser_traversal.py rename to src/plone/restapi/tests/test_browser_traversal.py diff --git a/src/plone.restapi/src/plone/restapi/tests/test_documentation.py b/src/plone/restapi/tests/test_documentation.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/tests/test_documentation.py rename to src/plone/restapi/tests/test_documentation.py diff --git a/src/plone.restapi/src/plone/restapi/tests/test_example.py b/src/plone/restapi/tests/test_example.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/tests/test_example.py rename to src/plone/restapi/tests/test_example.py diff --git a/src/plone.restapi/src/plone/restapi/tests/test_robot.py b/src/plone/restapi/tests/test_robot.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/tests/test_robot.py rename to src/plone/restapi/tests/test_robot.py diff --git a/src/plone.restapi/src/plone/restapi/tests/test_utils.py b/src/plone/restapi/tests/test_utils.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/tests/test_utils.py rename to src/plone/restapi/tests/test_utils.py diff --git a/src/plone.restapi/src/plone/restapi/utils.py b/src/plone/restapi/utils.py similarity index 100% rename from src/plone.restapi/src/plone/restapi/utils.py rename to src/plone/restapi/utils.py From 848c5a9fab4c65c0d7e6c8127292178de838ec08 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sat, 27 Dec 2014 11:08:11 +0100 Subject: [PATCH 18/18] Use readthedocs sphinx theme. --- buildout.cfg | 7 +++++++ docs/source/conf.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/buildout.cfg b/buildout.cfg index ea8a4c7a19..c5ade3fad6 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -9,6 +9,7 @@ parts = test-coverage code-analysis sphinxbuilder + sphinx-python templer develop = . @@ -58,6 +59,12 @@ directory = ${buildout:directory}/src recipe = collective.recipe.sphinxbuilder source = ${buildout:directory}/docs/source build = ${buildout:directory}/docs +interpreter = ${buildout:directory}/bin/${sphinx-python:interpreter} + +[sphinx-python] +recipe = zc.recipe.egg +eggs = sphinx_rtd_theme +interpreter = sphinxPython [templer] recipe = zc.recipe.egg diff --git a/docs/source/conf.py b/docs/source/conf.py index 1a1656fb28..3055d7edd2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -3,7 +3,8 @@ # plone.restapi documentation build configuration file, created by # sphinx-quickstart on Mon Apr 28 13:04:12 2014. # -# This file is execfile()d with the current directory set to its containing dir. +# This file is execfile()d with the current directory set to its containing +# dir. # # Note that not all possible configuration values are present in this # autogenerated file. @@ -18,14 +19,14 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) -# -- General configuration ----------------------------------------------------- +# -- 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 = [] +extensions = ['sphinx_rtd_theme'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -91,7 +92,10 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +#html_theme = 'default' +import sphinx_rtd_theme +html_theme = "sphinx_rtd_theme" +html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] # 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