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

Commit

Permalink
fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
janwijbrand committed Jan 10, 2018
1 parent 849621f commit 3b436b0
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 31 deletions.
22 changes: 11 additions & 11 deletions src/grokcore/xmlrpc/ftests/xmlrpc/require.py
@@ -1,37 +1,37 @@
"""
>>> from zope.app.wsgi.testlayer import XMLRPCServerProxy
>>> server = XMLRPCServerProxy("http://localhost/")
>>> mgr_server = XMLRPCServerProxy("http://mgr:mgrpw@localhost/")
>>> server = XMLRPCServerProxy("http://localhost/", transport=transport)
>>> mgr_server = XMLRPCServerProxy("http://mgr:mgrpw@localhost/", transport=transport)
We can access a public method just fine, but a protected method will
raise Unauthorized:
>>> print server.stomp()
>>> print(server.stomp())
Manfred stomped.
>>> print server.dance()
>>> print(server.dance())
Traceback (most recent call last):
ProtocolError: <ProtocolError for localhost/: 401 401 Unauthorized>
xmlrpc.client.ProtocolError: <ProtocolError for localhost/: 401 401 Unauthorized>
With manager privileges, the protected method is accessible, however:
>>> print mgr_server.dance()
>>> print(mgr_server.dance())
Manfred doesn't like to dance.
The same applies when a default permission is defined for all XML-RPC
methods in a class:
>>> print server.hunt()
>>> print(server.hunt())
Traceback (most recent call last):
ProtocolError: <ProtocolError for localhost/: 401 401 Unauthorized>
xmlrpc.client.ProtocolError: <ProtocolError for localhost/: 401 401 Unauthorized>
>>> print mgr_server.hunt()
>>> print(mgr_server.hunt())
ME GROK LIKE MAMMOTH!
>>> print server.eat()
>>> print(server.eat())
MMM, MANFRED TASTE GOOD!
>>> print server.rest()
>>> print(server.rest())
ME GROK TIRED!
"""
import grokcore.component as grok
Expand Down
7 changes: 3 additions & 4 deletions src/grokcore/xmlrpc/ftests/xmlrpc/xmlrpc.py
Expand Up @@ -2,7 +2,7 @@
>>> getRootFolder()["Manfred"] = Mammoth()
>>> from zope.app.wsgi.testlayer import XMLRPCServerProxy
>>> server = XMLRPCServerProxy("http://localhost/")
>>> server = XMLRPCServerProxy("http://localhost/", transport=transport)
>>> server.Manfred.stomp()
'Manfred stomped.'
Expand All @@ -14,7 +14,7 @@
>>> server.Manfred.baby.pounce()
'baby pounced.'
"""
import grokcore.component as grok
import grokcore.xmlrpc
Expand All @@ -31,7 +31,7 @@ class MammothBaby(Model):

class MammothRPC(grokcore.xmlrpc.XMLRPC):
grok.context(Mammoth)

def stomp(self):
return '%s stomped.' % self.context.__name__

Expand All @@ -43,4 +43,3 @@ class BabyRPC(grokcore.xmlrpc.XMLRPC):

def pounce(self):
return '%s pounced.' % self.context.__name__

5 changes: 4 additions & 1 deletion src/grokcore/xmlrpc/tests/test_grok.py
Expand Up @@ -35,7 +35,10 @@ def suiteFromPackage(name):
dottedname,
tearDown=cleanUpZope,
checker=checker,
optionflags=doctest.ELLIPSIS + doctest.NORMALIZE_WHITESPACE)
optionflags=(
doctest.ELLIPSIS +
doctest.NORMALIZE_WHITESPACE +
renormalizing.IGNORE_EXCEPTION_MODULE_IN_PYTHON2))

suite.addTest(test)
return suite
Expand Down
8 changes: 4 additions & 4 deletions src/grokcore/xmlrpc/tests/xmlrpc/missing_permission.py
Expand Up @@ -6,9 +6,10 @@
>>> testing.grok(__name__)
Traceback (most recent call last):
...
ConfigurationExecutionError: martian.error.GrokError: Undefined permission
'doesnt.exist' in <class 'grokcore.xmlrpc.tests.xmlrpc.missing_permission.MissingPermission'>. Use grok.Permission first.
...
zope.configuration.config.ConfigurationExecutionError: \
martian.error.GrokError: Undefined permission 'doesnt.exist' in \
<class 'grokcore.xmlrpc.tests.xmlrpc.missing_permission.MissingPermission'>.\
Use grok.Permission first...
"""

Expand All @@ -23,4 +24,3 @@ class MissingPermission(grokcore.xmlrpc.XMLRPC):

def foo(self):
pass

10 changes: 6 additions & 4 deletions src/grokcore/xmlrpc/tests/xmlrpc/missing_permission2.py
Expand Up @@ -6,9 +6,12 @@
>>> testing.grok(__name__)
Traceback (most recent call last):
...
ConfigurationExecutionError: martian.error.GrokError: Undefined permission
'doesnt.exist' in <class 'grokcore.xmlrpc.tests.xmlrpc.missing_permission2.MissingPermission'>. Use grok.Permission first.
...
zope.configuration.config.ConfigurationExecutionError: \
martian.error.GrokError: Undefined permission \
'doesnt.exist' in \
<class \
'grokcore.xmlrpc.tests.xmlrpc.missing_permission2.MissingPermission'>.\
Use grok.Permission first...
"""

Expand All @@ -23,4 +26,3 @@ class MissingPermission(grokcore.xmlrpc.XMLRPC):
@grokcore.security.require('doesnt.exist')
def foo(self):
pass

4 changes: 3 additions & 1 deletion src/grokcore/xmlrpc/tests/xmlrpc/multiple_require.py
Expand Up @@ -5,7 +5,9 @@
>>> testing.grok(__name__)
Traceback (most recent call last):
...
GrokError: grok.require was called multiple times in <class 'grokcore.xmlrpc.tests.xmlrpc.multiple_require.MultipleXMLRPC'>. It may only be set once for a class.
martian.error.GrokError: grok.require was called multiple times in \
<class 'grokcore.xmlrpc.tests.xmlrpc.multiple_require.MultipleXMLRPC'>. \
It may only be set once for a class.
"""
import grokcore.component as grok
import grokcore.security
Expand Down
7 changes: 3 additions & 4 deletions src/grokcore/xmlrpc/tests/xmlrpc/nocontext.py
Expand Up @@ -6,13 +6,12 @@
>>> from grokcore.xmlrpc import testing
>>> testing.grok(__name__)
Traceback (most recent call last):
...
GrokError: No module-level context for
<class 'grokcore.xmlrpc.tests.xmlrpc.nocontext.HomeRPC'>, please use the
...
martian.error.GrokError: No module-level context for \
<class 'grokcore.xmlrpc.tests.xmlrpc.nocontext.HomeRPC'>, please use the \
'context' directive.
"""
import grokcore.component as grok
import grokcore.xmlrpc

class HomeRPC(grokcore.xmlrpc.XMLRPC):
Expand Down
5 changes: 3 additions & 2 deletions src/grokcore/xmlrpc/tests/xmlrpc/nomethods.py
Expand Up @@ -3,8 +3,9 @@
>>> testing.grok(__name__)
Traceback (most recent call last):
...
GrokError: <class 'grokcore.xmlrpc.tests.xmlrpc.nomethods.RemoteCaveman'> does not
define any public methods. Please add methods to this class to enable
martian.error.GrokError: \
<class 'grokcore.xmlrpc.tests.xmlrpc.nomethods.RemoteCaveman'> does not \
define any public methods. Please add methods to this class to enable \
its registration.
"""
Expand Down

0 comments on commit 3b436b0

Please sign in to comment.