From c439c375eb0a54b892ad7990a4b7effa2f3ebabf Mon Sep 17 00:00:00 2001 From: Uli Fouquet Date: Wed, 15 Sep 2010 09:48:24 +0000 Subject: [PATCH] Add tests for https://bugs.launchpad.net/grok/+bug/638763. --- src/grokui/admin/tests/brokenapps.py | 67 ++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/grokui/admin/tests/brokenapps.py diff --git a/src/grokui/admin/tests/brokenapps.py b/src/grokui/admin/tests/brokenapps.py new file mode 100644 index 0000000..792cd8a --- /dev/null +++ b/src/grokui/admin/tests/brokenapps.py @@ -0,0 +1,67 @@ +""" +Broken applications +=================== + +When some broken application raises DuplicationErrors during creation, +these problem will not be hidden away. + +We first setup the environment: + + >>> from zope.app.wsgi.testlayer import Browser + >>> browser = Browser() + >>> #print dir(browser) + >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw') + +We have an application type available, which raises DuplicationError +during creation intentionally: + + >>> browser.open('http://localhost/++grokui++/applications') + >>> 'IntentionallyBrokenApp' in browser.contents + True + +If we try to add an application of that type, the traceback will be +visible: + + >>> browser.handleErrors = False + >>> subform = browser.getForm( + ... name='grokui.admin.tests.brokenapps.IntentionallyBrokenApp') + >>> subform.getControl(name='name').value = 'mybrokenapp' + >>> subform.getControl('Create').click() + Traceback (most recent call last): + ... + DuplicationError: Intentional DuplicationError + +If, however, we try to add two working apps under same name, the UI +will inform us of the problem (without a traceback): + + >>> browser.open('http://localhost/++grokui++/applications') + >>> subform = browser.getForm( + ... name='grokui.admin.tests.brokenapps.WorkingApp') + >>> subform.getControl(name='name').value = 'somename' + >>> subform.getControl('Create').click() + + >>> subform = browser.getForm( + ... name='grokui.admin.tests.brokenapps.WorkingApp') + >>> subform.getControl(name='name').value = 'somename' + >>> subform.getControl('Create').click() + + >>> print browser.contents + + ... + ...Name `somename` already in use. Please choose another name... + ... + +""" +import grok +from zope.exceptions import DuplicationError + +class IntentionallyBrokenApp(grok.Application, grok.Container): + """An application that intentionally raises DuplicationError. + """ + + def __init__(self, *args, **kw): + raise DuplicationError('Intentional DuplicationError') + +class WorkingApp(grok.Application, grok.Container): + """A working app. + """