Commit 2a6367ef authored by Fred Drake's avatar Fred Drake

- avoid duplication

- separate two tests that were performed in the same test method
- normalize whitespace
parent a7daace8
...@@ -43,7 +43,7 @@ for name in ('event', 'trace', 'access'): ...@@ -43,7 +43,7 @@ for name in ('event', 'trace', 'access'):
'propagate':logger.propagate, 'propagate':logger.propagate,
'handlers':logger.handlers, 'handlers':logger.handlers,
'filters':logger.filters} 'filters':logger.filters}
class ZopeStarterTestCase(unittest.TestCase): class ZopeStarterTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -66,6 +66,7 @@ class ZopeStarterTestCase(unittest.TestCase): ...@@ -66,6 +66,7 @@ class ZopeStarterTestCase(unittest.TestCase):
# of the directory is checked. This handles this in a # of the directory is checked. This handles this in a
# platform-independent way. # platform-independent way.
schema = self.schema schema = self.schema
text = "instancehome <<INSTANCE_HOME>>\n" + text
sio = cStringIO.StringIO( sio = cStringIO.StringIO(
text.replace("<<INSTANCE_HOME>>", TEMPNAME)) text.replace("<<INSTANCE_HOME>>", TEMPNAME))
try: try:
...@@ -83,10 +84,7 @@ class ZopeStarterTestCase(unittest.TestCase): ...@@ -83,10 +84,7 @@ class ZopeStarterTestCase(unittest.TestCase):
# XXX this almost certainly won't work on all systems # XXX this almost certainly won't work on all systems
import locale import locale
try: try:
conf = self.load_config_text(""" conf = self.load_config_text("locale fr_FR")
instancehome <<INSTANCE_HOME>>
locale fr_FR"""
)
starter = ZopeStarter(conf) starter = ZopeStarter(conf)
starter.setupLocale() starter.setupLocale()
self.assertEqual(locale.getlocale(), ['fr_FR', 'ISO8859-1']) self.assertEqual(locale.getlocale(), ['fr_FR', 'ISO8859-1'])
...@@ -98,7 +96,6 @@ class ZopeStarterTestCase(unittest.TestCase): ...@@ -98,7 +96,6 @@ class ZopeStarterTestCase(unittest.TestCase):
import zLOG import zLOG
import sys import sys
conf = self.load_config_text(""" conf = self.load_config_text("""
instancehome <<INSTANCE_HOME>>
debug-mode on debug-mode on
<eventlog> <eventlog>
level info level info
...@@ -127,7 +124,6 @@ class ZopeStarterTestCase(unittest.TestCase): ...@@ -127,7 +124,6 @@ class ZopeStarterTestCase(unittest.TestCase):
self.assertEqual(len(zLOG.EventLogger.EventLogger.logger.handlers), 1) self.assertEqual(len(zLOG.EventLogger.EventLogger.logger.handlers), 1)
self.failUnlessEqual(starter.startup_handler.stream, sys.stderr) self.failUnlessEqual(starter.startup_handler.stream, sys.stderr)
conf = self.load_config_text(""" conf = self.load_config_text("""
instancehome <<INSTANCE_HOME>>
debug-mode off debug-mode off
<eventlog> <eventlog>
level info level info
...@@ -141,9 +137,7 @@ class ZopeStarterTestCase(unittest.TestCase): ...@@ -141,9 +137,7 @@ class ZopeStarterTestCase(unittest.TestCase):
self.failIfEqual(starter.startup_handler.stream, sys.stderr) self.failIfEqual(starter.startup_handler.stream, sys.stderr)
def testSetupZServerThreads(self): def testSetupZServerThreads(self):
conf = self.load_config_text(""" conf = self.load_config_text("zserver-threads 10")
instancehome <<INSTANCE_HOME>>
zserver-threads 10""")
starter = ZopeStarter(conf) starter = ZopeStarter(conf)
starter.setupZServerThreads() starter.setupZServerThreads()
from ZServer.PubCore import _n from ZServer.PubCore import _n
...@@ -151,7 +145,6 @@ class ZopeStarterTestCase(unittest.TestCase): ...@@ -151,7 +145,6 @@ class ZopeStarterTestCase(unittest.TestCase):
def testSetupServers(self): def testSetupServers(self):
conf = self.load_config_text(""" conf = self.load_config_text("""
instancehome <<INSTANCE_HOME>>
<http-server> <http-server>
address 18092 address 18092
</http-server> </http-server>
...@@ -171,9 +164,9 @@ class ZopeStarterTestCase(unittest.TestCase): ...@@ -171,9 +164,9 @@ class ZopeStarterTestCase(unittest.TestCase):
ZServer.FTPServer) ZServer.FTPServer)
finally: finally:
del conf.servers # should release servers del conf.servers # should release servers
pass
def testSetupServersWithConflict(self):
conf = self.load_config_text(""" conf = self.load_config_text("""
instancehome <<INSTANCE_HOME>>
<http-server> <http-server>
address 18092 address 18092
</http-server> </http-server>
...@@ -200,30 +193,23 @@ class ZopeStarterTestCase(unittest.TestCase): ...@@ -200,30 +193,23 @@ class ZopeStarterTestCase(unittest.TestCase):
try: try:
os.getuid = _return0 os.getuid = _return0
# no effective user # no effective user
conf = self.load_config_text(""" conf = self.load_config_text("")
instancehome <<INSTANCE_HOME>>""")
starter = ZopeStarter(conf) starter = ZopeStarter(conf)
self.assertRaises(ZConfig.ConfigurationError, self.assertRaises(ZConfig.ConfigurationError,
starter.dropPrivileges) starter.dropPrivileges)
# cant find user in passwd database # cant find user in passwd database
conf = self.load_config_text(""" conf = self.load_config_text("effective-user n0sucHuS3r")
instancehome <<INSTANCE_HOME>>
effective-user n0sucHuS3r""")
starter = ZopeStarter(conf) starter = ZopeStarter(conf)
self.assertRaises(ZConfig.ConfigurationError, self.assertRaises(ZConfig.ConfigurationError,
starter.dropPrivileges) starter.dropPrivileges)
# can't specify '0' as effective user # can't specify '0' as effective user
conf = self.load_config_text(""" conf = self.load_config_text("effective-user 0")
instancehome <<INSTANCE_HOME>>
effective-user 0""")
starter = ZopeStarter(conf) starter = ZopeStarter(conf)
self.assertRaises(ZConfig.ConfigurationError, self.assertRaises(ZConfig.ConfigurationError,
starter.dropPrivileges) starter.dropPrivileges)
# setuid to test runner's uid XXX will this work cross-platform? # setuid to test runner's uid XXX will this work cross-platform?
runnerid = _old_getuid() runnerid = _old_getuid()
conf = self.load_config_text(""" conf = self.load_config_text("effective-user %s" % runnerid)
instancehome <<INSTANCE_HOME>>
effective-user %s""" % runnerid)
starter = ZopeStarter(conf) starter = ZopeStarter(conf)
finished = starter.dropPrivileges() finished = starter.dropPrivileges()
self.failUnless(finished) self.failUnless(finished)
...@@ -235,7 +221,6 @@ class ZopeStarterTestCase(unittest.TestCase): ...@@ -235,7 +221,6 @@ class ZopeStarterTestCase(unittest.TestCase):
import logging import logging
import sys import sys
conf = self.load_config_text(""" conf = self.load_config_text("""
instancehome <<INSTANCE_HOME>>
debug-mode off debug-mode off
<eventlog> <eventlog>
level info level info
...@@ -280,10 +265,7 @@ class ZopeStarterTestCase(unittest.TestCase): ...@@ -280,10 +265,7 @@ class ZopeStarterTestCase(unittest.TestCase):
def testMakeLockFile(self): def testMakeLockFile(self):
# put something in the way (it should be deleted) # put something in the way (it should be deleted)
name = os.path.join(TEMPNAME, 'lock') name = os.path.join(TEMPNAME, 'lock')
conf = self.load_config_text(""" conf = self.load_config_text("lock-filename %s" % name)
instancehome <<INSTANCE_HOME>>
lock-filename %s""" % name
)
f = open(name, 'a') f = open(name, 'a')
f.write('hello') f.write('hello')
f.close() f.close()
...@@ -298,10 +280,7 @@ class ZopeStarterTestCase(unittest.TestCase): ...@@ -298,10 +280,7 @@ class ZopeStarterTestCase(unittest.TestCase):
def testMakePidFile(self): def testMakePidFile(self):
# put something in the way (it should be deleted) # put something in the way (it should be deleted)
name = os.path.join(TEMPNAME, 'pid') name = os.path.join(TEMPNAME, 'pid')
conf = self.load_config_text(""" conf = self.load_config_text("pid-filename %s" % name)
instancehome <<INSTANCE_HOME>>
pid-filename %s""" % name
)
f = open(name, 'a') f = open(name, 'a')
f.write('hello') f.write('hello')
f.close() f.close()
...@@ -318,4 +297,3 @@ def test_suite(): ...@@ -318,4 +297,3 @@ def test_suite():
if __name__ == "__main__": if __name__ == "__main__":
unittest.main(defaultTest="test_suite") unittest.main(defaultTest="test_suite")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment