[Checkins] SVN: grokui.admin/trunk/src/grokui/admin/tests/ Cleaned up test setup. Use a simple http server instead of a local file url in the security test
Jan-Jaap Driessen
jdriessen at thehealthagency.com
Wed Oct 27 06:15:55 EDT 2010
Log message for revision 117953:
Cleaned up test setup. Use a simple http server instead of a local file url in the security test
Changed:
D grokui.admin/trunk/src/grokui/admin/tests/releaseinfo/
U grokui.admin/trunk/src/grokui/admin/tests/security.py
D grokui.admin/trunk/src/grokui/admin/tests/test_grokadmin.py
D grokui.admin/trunk/src/grokui/admin/tests/test_grokadmin_functional.py
A grokui.admin/trunk/src/grokui/admin/tests/tests.py
-=-
Modified: grokui.admin/trunk/src/grokui/admin/tests/security.py
===================================================================
--- grokui.admin/trunk/src/grokui/admin/tests/security.py 2010-10-27 10:14:17 UTC (rev 117952)
+++ grokui.admin/trunk/src/grokui/admin/tests/security.py 2010-10-27 10:15:55 UTC (rev 117953)
@@ -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
@@ -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::
@@ -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
Deleted: grokui.admin/trunk/src/grokui/admin/tests/test_grokadmin.py
===================================================================
--- grokui.admin/trunk/src/grokui/admin/tests/test_grokadmin.py 2010-10-27 10:14:17 UTC (rev 117952)
+++ grokui.admin/trunk/src/grokui/admin/tests/test_grokadmin.py 2010-10-27 10:15:55 UTC (rev 117953)
@@ -1,66 +0,0 @@
-# -*- coding: utf-8 -*-
-
-import doctest
-import os
-import unittest
-import zope.component.eventtesting
-from pkg_resources import resource_listdir
-from zope.testing import cleanup
-
-
-def setUpZope(test):
- zope.component.eventtesting.setUp(test)
-
-
-def cleanUpZope(test):
- cleanup.cleanUp()
-
-
-def suiteFromPackage(name):
- files = resource_listdir(__name__, name)
- suite = unittest.TestSuite()
- for filename in files:
- if not filename.endswith('.py'):
- continue
- if filename.endswith('_fixture.py'):
- continue
- if filename == '__init__.py':
- continue
-
- dottedname = 'grokui.admin.tests.%s.%s' % (name, filename[:-3])
- test = doctest.DocTestSuite(
- dottedname,
- setUp=setUpZope,
- tearDown=cleanUpZope,
- optionflags=(doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
- )
- suite.addTest(test)
- return suite
-
-
-def pnorm(path):
- """Normalization of paths to use forward slashes. This is needed
- to make sure the tests work on windows.
- """
- return path.replace(os.sep, '/')
-
-
-def test_suite():
- suite = unittest.TestSuite()
- globs = {'pnorm': pnorm}
-
- for name in []:
- suite.addTest(suiteFromPackage(name))
- for name in ['utilities.py']:
- suite.addTest(doctest.DocFileSuite(
- name,
- package='grokui.admin',
- globs=globs,
- setUp=setUpZope,
- tearDown=cleanUpZope,
- optionflags=(doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
- ))
- return suite
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
Deleted: grokui.admin/trunk/src/grokui/admin/tests/test_grokadmin_functional.py
===================================================================
--- grokui.admin/trunk/src/grokui/admin/tests/test_grokadmin_functional.py 2010-10-27 10:14:17 UTC (rev 117952)
+++ grokui.admin/trunk/src/grokui/admin/tests/test_grokadmin_functional.py 2010-10-27 10:15:55 UTC (rev 117953)
@@ -1,51 +0,0 @@
-# -*- coding: utf-8 -*-
-
-import doctest
-import re
-import unittest
-import os.path
-import grokui.admin
-
-from pkg_resources import resource_listdir
-from zope.testing import renormalizing
-from zope.app.wsgi.testlayer import BrowserLayer
-
-ftesting_zcml = os.path.join(
- os.path.dirname(__file__), 'ftesting.zcml')
-
-FunctionalLayer = BrowserLayer(grokui.admin.tests, zcml_file=ftesting_zcml)
-
-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()
- files = resource_listdir(__name__, '')
- for filename in files:
- if not filename.endswith('.py'):
- continue
- if filename == '__init__.py':
- continue
- if filename.startswith('test_'):
- continue
-
- dottedname = 'grokui.admin.tests.%s' % (filename[:-3])
- test = doctest.DocTestSuite(
- dottedname,
- checker=checker,
- extraglobs=dict(getRootFolder=FunctionalLayer.getRootFolder),
- optionflags=(doctest.ELLIPSIS +
- doctest.NORMALIZE_WHITESPACE +
- doctest.REPORT_NDIFF),
- )
- test.layer = FunctionalLayer
-
- suite.addTest(test)
- return suite
-
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
Added: grokui.admin/trunk/src/grokui/admin/tests/tests.py
===================================================================
--- grokui.admin/trunk/src/grokui/admin/tests/tests.py (rev 0)
+++ grokui.admin/trunk/src/grokui/admin/tests/tests.py 2010-10-27 10:15:55 UTC (rev 117953)
@@ -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
More information about the checkins
mailing list