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

Commit

Permalink
Cleaned up test setup. Use a simple http server instead of a local fi…
Browse files Browse the repository at this point in the history
…le url in the security test
  • Loading branch information
janjaapdriessen committed Oct 27, 2010
1 parent 9eec587 commit d9e7595
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 126 deletions.
2 changes: 0 additions & 2 deletions src/grokui/admin/tests/releaseinfo/readme.txt

This file was deleted.

14 changes: 7 additions & 7 deletions src/grokui/admin/tests/security.py
Expand Up @@ -77,11 +77,10 @@
a local directory with some warnings, which we will use as our
information source::
>>> import os.path
>>> fake_source = os.path.join(os.path.dirname(__file__), 'releaseinfo')
>>> fake_source_url = 'file://localhost/%s' % fake_source + os.path.sep
>>> fake_source_url = fake_source_url.replace(os.path.sep, '/')
>>> sn.setLookupURL(fake_source_url)
>>> import tempfile
>>> release_info_tmpdir = tempfile.mkdtemp()
>>> release_info_server = start_server(release_info_tmpdir)
>>> sn.setLookupURL(release_info_server)
Now we can safely enable the notifier and see, whether there are infos
for us. It is sufficient to call `getNotification()` as this will
Expand All @@ -104,8 +103,9 @@
>>> from grokui.admin.utilities import getVersion
>>> version = getVersion('grok')
>>> import os.path
>>> fake_warning_file = 'grok-%s.security.txt' % version
>>> fake_warning_file = os.path.join(fake_source, fake_warning_file)
>>> fake_warning_file = os.path.join(release_info_tmpdir, fake_warning_file)
>>> open(fake_warning_file, 'w').write('You better smash %s' % version)
When we now ask the security notifier again::
Expand Down Expand Up @@ -182,7 +182,7 @@
But we are not bound to the default URL to do lookups. We can set
another one ourselves::
>>> browser.getControl(name='secnotesource').value=fake_source_url
>>> browser.getControl(name='secnotesource').value=release_info_server
>>> browser.getControl('Set URL').click()
Now, as we set a lookup URL which we can control better, we can enable
Expand Down
66 changes: 0 additions & 66 deletions src/grokui/admin/tests/test_grokadmin.py

This file was deleted.

51 changes: 0 additions & 51 deletions src/grokui/admin/tests/test_grokadmin_functional.py

This file was deleted.

53 changes: 53 additions & 0 deletions src/grokui/admin/tests/tests.py
@@ -0,0 +1,53 @@
import doctest
import re
import unittest
import grokui.admin

import zc.buildout.testing
from zope.testing import renormalizing
from zope.app.wsgi.testlayer import BrowserLayer

checker = renormalizing.RENormalizing([
# Accommodate to exception wrapping in newer versions of mechanize
(re.compile(r'httperror_seek_wrapper:', re.M), 'HTTPError:'),
])

def test_suite():
suite = unittest.TestSuite()
functional_layer = BrowserLayer(grokui.admin.tests)
optionflags=(doctest.ELLIPSIS +
doctest.NORMALIZE_WHITESPACE +
doctest.REPORT_NDIFF)
globs=dict(getRootFolder=functional_layer.getRootFolder)

tests = [
'apps',
'brokenapps',
'brokenobjs',
'events',
'infoviews',
'packdatabase',
'server']

for filename in tests:
test = doctest.DocTestSuite(
'grokui.admin.tests.' + filename,
checker=checker,
globs=globs,
optionflags=optionflags,
)
test.layer = functional_layer
suite.addTest(test)

security_test = doctest.DocTestSuite(
'grokui.admin.tests.security',
checker=checker,
globs=globs,
optionflags=optionflags,
# In order to start a tiny http server in the test.
setUp=zc.buildout.testing.buildoutSetUp,
tearDown=zc.buildout.testing.buildoutTearDown,
)
security_test.layer = functional_layer
suite.addTest(security_test)
return suite

0 comments on commit d9e7595

Please sign in to comment.