Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
Add coverage to tox, cleanup buildout, reorganize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gyst committed Jan 12, 2018
1 parent 0e1488a commit c194192
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ recipe = zc.recipe.testrunner
eggs =
grokcore.rest
grokcore.rest[test]
defaults = ['--tests-pattern', '^f?tests$', '-v', '--auto-color']
defaults = ['-v', '--auto-color']

[omelette]
recipe = collective.recipe.omelette
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ def read(*rnames):
'grokcore.view[test]',
'six',
'zope.app.appsetup',
'zope.app.wsgi',
'zope.app.wsgi[test]',
'zope.errorview',
'zope.testbrowser',
'zope.testing',
]

Expand Down
2 changes: 1 addition & 1 deletion src/grokcore/rest/ftesting.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

<include package="grokcore.rest" />

<grok:grok package=".ftests" />
<grok:grok package=".tests.functional" />

</configure>
25 changes: 25 additions & 0 deletions src/grokcore/rest/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
##############################################################################
#
# Copyright (c) 2006-2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################

from grokcore.component import *
from grokcore.security import *
from grokcore.view import *
from grokcore.rest.interfaces import IREST
from grokcore.rest.interfaces import IRESTLayer
from grokcore.rest.interfaces import IRESTSkinType
from grokcore.rest.components import REST
from grokcore.rest.directive import restskin
from zope.interface import moduleProvides
moduleProvides(IREST)
__all__ = list(IREST)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Let's create a simple application with REST support::
>>> from grokcore.rest.ftests.rest.rest import MyApp
>>> from grokcore.rest.tests.functional.rest.rest import MyApp
>>> root = getRootFolder()
>>> root['app'] = MyApp()
>>> root['app']['alpha'] = MyContent()
Expand Down Expand Up @@ -63,7 +63,7 @@
Traceback (most recent call last):
...
grokcore.rest.rest.GrokMethodNotAllowed: \
<grokcore.rest.ftests.rest.rest.MyApp object at ...>,
<grokcore.rest.tests.functional.rest.rest.MyApp object at ...>,
<zope.publisher.browser.BrowserRequest instance URL=http://localhost/++rest++b/app>
DELETE is also not defined, so we also expect a 405 error::
Expand All @@ -72,7 +72,7 @@
Traceback (most recent call last):
...
grokcore.rest.rest.GrokMethodNotAllowed: \
<grokcore.rest.ftests.rest.rest.MyApp object at ...>,
<grokcore.rest.tests.functional.rest.rest.MyApp object at ...>,
<zope.publisher.http.HTTPRequest instance URL=http://localhost/++rest++b/app>
Let's examine protocol c where no method is allowed::
Expand All @@ -81,45 +81,45 @@
Traceback (most recent call last):
...
grokcore.rest.rest.GrokMethodNotAllowed: \
<grokcore.rest.ftests.rest.rest.MyApp object at ...
<grokcore.rest.tests.functional.rest.rest.MyApp object at ...
>>> response = http_call(wsgi_app(), 'POST', 'http://localhost/++rest++c/app')
Traceback (most recent call last):
...
grokcore.rest.rest.GrokMethodNotAllowed: \
<grokcore.rest.ftests.rest.rest.MyApp object at ...
<grokcore.rest.tests.functional.rest.rest.MyApp object at ...
>>> response = http_call(wsgi_app(), 'PUT', 'http://localhost/++rest++c/app')
Traceback (most recent call last):
...
grokcore.rest.rest.GrokMethodNotAllowed: \
<grokcore.rest.ftests.rest.rest.MyApp object at ...
<grokcore.rest.tests.functional.rest.rest.MyApp object at ...
>>> response = http_call(wsgi_app(), 'DELETE', 'http://localhost/++rest++c/app')
Traceback (most recent call last):
...
grokcore.rest.rest.GrokMethodNotAllowed: \
<grokcore.rest.ftests.rest.rest.MyApp object at ...
<grokcore.rest.tests.functional.rest.rest.MyApp object at ...
Let's examine the default protocol d, where nothing should work as well::
>>> response = http_call(wsgi_app(), 'GET', 'http://localhost/++rest++d/app')
Traceback (most recent call last):
...
grokcore.rest.rest.GrokMethodNotAllowed: \
<grokcore.rest.ftests.rest.rest.MyApp object at ...
<grokcore.rest.tests.functional.rest.rest.MyApp object at ...
>>> response = http_call(wsgi_app(), 'POST', 'http://localhost/++rest++d/app')
Traceback (most recent call last):
...
grokcore.rest.rest.GrokMethodNotAllowed: \
<grokcore.rest.ftests.rest.rest.MyApp object at ...
<grokcore.rest.tests.functional.rest.rest.MyApp object at ...
>>> response = http_call(wsgi_app(), 'PUT', 'http://localhost/++rest++d/app')
Traceback (most recent call last):
...
grokcore.rest.rest.GrokMethodNotAllowed: \
<grokcore.rest.ftests.rest.rest.MyApp object at ...
<grokcore.rest.tests.functional.rest.rest.MyApp object at ...
>>> response = http_call(wsgi_app(), 'DELETE', 'http://localhost/++rest++d/app')
Traceback (most recent call last):
...
grokcore.rest.rest.GrokMethodNotAllowed: \
<grokcore.rest.ftests.rest.rest.MyApp object at ...
<grokcore.rest.tests.functional.rest.rest.MyApp object at ...
We have added support for GET for the ``alpha`` subobject only, in
the default rest layer::
Expand All @@ -134,7 +134,7 @@
Traceback (most recent call last):
...
grokcore.rest.rest.GrokMethodNotAllowed: \
<grokcore.rest.ftests.rest.rest.MyContent object at ...
<grokcore.rest.tests.functional.rest.rest.MyContent object at ...
According to the HTTP spec, in case of a 405 Method Not Allowed error,
the response MUST include an Allow header containing a list of valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ def http_call(app, method, path, data=None, handle_errors=False, **kw):


def suiteFromPackage(name):
files = resource_listdir(__name__, name)
layer_dir = 'functional'
files = resource_listdir(__name__, '{}/{}'.format(layer_dir, name))
suite = unittest.TestSuite()
for filename in files:
if not filename.endswith('.py'):
continue
if filename == '__init__.py':
continue

dottedname = 'grokcore.rest.ftests.%s.%s' % (name, filename[:-3])
dottedname = 'grokcore.rest.tests.%s.%s.%s' % (
layer_dir, name, filename[:-3])
test = doctest.DocTestSuite(
dottedname,
checker=checker,
Expand Down

0 comments on commit c194192

Please sign in to comment.