Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deactivted all BBB to ensure that we use only the latest code in zope…
….app Made almost all tests pass again, except the few that heavily depended on the old way of doing things: apidoc, module, presentation
- Loading branch information
0 parents
commit 18e4da4
Showing
3 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2001, 2002, 2003 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""Runtime View tests | ||
$Id$ | ||
""" | ||
import unittest | ||
from types import DictType | ||
from zope.app.testing import ztapi | ||
|
||
from zope.app.applicationcontrol.applicationcontrol import applicationController | ||
from zope.app.applicationcontrol.runtimeinfo import RuntimeInfo | ||
from zope.app.applicationcontrol.browser.runtimeinfo import RuntimeInfoView | ||
from zope.app.applicationcontrol.interfaces import \ | ||
IApplicationControl, IRuntimeInfo | ||
from zope.app.component.testing import PlacefulSetup | ||
|
||
class Test(PlacefulSetup, unittest.TestCase): | ||
|
||
def _TestView__newView(self, container): | ||
view = RuntimeInfoView() | ||
view.context = container | ||
view.request = None | ||
return view | ||
|
||
def test_RuntimeInfoView(self): | ||
ztapi.provideAdapter(IApplicationControl, IRuntimeInfo, RuntimeInfo) | ||
test_runtimeinfoview = self._TestView__newView(applicationController) | ||
|
||
test_format = test_runtimeinfoview.runtimeInfo() | ||
self.failUnless(isinstance(test_format, DictType)) | ||
|
||
assert_keys = ['ZopeVersion', 'PythonVersion', 'PythonPath', | ||
'SystemPlatform', 'PreferredEncoding', 'FileSystemEncoding', | ||
'CommandLine', 'ProcessId', 'Uptime' ] | ||
test_keys = test_format.keys() | ||
|
||
assert_keys.sort() | ||
test_keys.sort() | ||
self.failUnless(assert_keys == test_keys) | ||
|
||
self.failUnless(test_format["ZopeVersion"] != "n/a") | ||
|
||
def test_RuntimeInfoFailureView(self): | ||
test_runtimeinfoview = self._TestView__newView(applicationController) | ||
|
||
test_format = test_runtimeinfoview.runtimeInfo() | ||
self.failUnless(isinstance(test_format, DictType)) | ||
|
||
assert_keys = ['ZopeVersion', 'PythonVersion', 'PythonPath', | ||
'SystemPlatform', 'PreferredEncoding', 'FileSystemEncoding', | ||
'CommandLine', 'ProcessId', 'Uptime', 'Hint'] | ||
test_keys = test_format.keys() | ||
|
||
assert_keys.sort() | ||
test_keys.sort() | ||
self.failUnless(assert_keys == test_keys) | ||
|
||
self.failUnless(test_format["ZopeVersion"] == "n/a") | ||
|
||
|
||
def test_suite(): | ||
return unittest.TestSuite(( | ||
unittest.makeSuite(Test), | ||
)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2001, 2002, 2003 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""Server Control View Tests | ||
$Id$ | ||
""" | ||
import unittest | ||
|
||
from zope.interface import implements | ||
from zope.app import zapi | ||
from zope.app.applicationcontrol.applicationcontrol import applicationController | ||
from zope.app.applicationcontrol.browser.servercontrol import ServerControlView | ||
from zope.app.applicationcontrol.interfaces import IServerControl | ||
from zope.app.servicenames import Utilities | ||
from zope.app.component.testing import PlacefulSetup | ||
|
||
class ServerControlStub(object): | ||
implements(IServerControl) | ||
|
||
did_restart = None | ||
did_shutdown = None | ||
|
||
def restart(self, time): | ||
self.did_restart = time | ||
|
||
def shutdown(self, time): | ||
self.did_shutdown = time | ||
|
||
class Test(PlacefulSetup, unittest.TestCase): | ||
|
||
def _TestView__newView(self, container, request): | ||
view = ServerControlView() | ||
view.context = container | ||
view.request = request | ||
return view | ||
|
||
def test_ServerControlView(self): | ||
control = ServerControlStub() | ||
zapi.getGlobalSiteManager().provideUtility(IServerControl, control) | ||
|
||
test_serverctrl = self._TestView__newView( | ||
applicationController, | ||
{'shutdown': 1}, | ||
) | ||
test_serverctrl.action(100) | ||
self.assertEqual(control.did_shutdown, 100) | ||
|
||
test_serverctrl = self._TestView__newView( | ||
applicationController, | ||
{'restart': 1}, | ||
) | ||
test_serverctrl.action(100) | ||
self.assertEqual(control.did_restart, 100) | ||
|
||
|
||
def test_suite(): | ||
return unittest.TestSuite(( | ||
unittest.makeSuite(Test), | ||
)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
############################################################################## | ||
"""Runtime Info Tests | ||
$Id$ | ||
""" | ||
import unittest | ||
import os, sys, time | ||
|
||
try: | ||
import locale | ||
except ImportError: | ||
locale = None | ||
|
||
from zope.app import zapi | ||
from zope.interface import implements | ||
from zope.interface.verify import verifyObject | ||
from zope.app.applicationcontrol.applicationcontrol import applicationController | ||
from zope.app.applicationcontrol.interfaces import IRuntimeInfo, IZopeVersion | ||
from zope.app.component.testing import PlacefulSetup | ||
|
||
# seconds, time values may differ in order to be assumed equal | ||
time_tolerance = 2 | ||
stupid_version_string = "3085t0klvn93850voids" | ||
|
||
class TestZopeVersion(object): | ||
"""A fallback implementation for the ZopeVersion utility.""" | ||
|
||
implements(IZopeVersion) | ||
|
||
def getZopeVersion(self): | ||
return stupid_version_string | ||
|
||
class Test(PlacefulSetup, unittest.TestCase): | ||
|
||
def _Test__new(self): | ||
from zope.app.applicationcontrol.runtimeinfo import RuntimeInfo | ||
return RuntimeInfo(applicationController) | ||
|
||
def _getPreferredEncoding(self): | ||
if locale is not None: | ||
try: | ||
return locale.getpreferredencoding() | ||
except locale.Error: | ||
pass | ||
return sys.getdefaultencoding() | ||
|
||
def _getFileSystemEncoding(self): | ||
enc = sys.getfilesystemencoding() | ||
if enc is None: | ||
enc = self._getPreferredEncoding() | ||
return enc | ||
|
||
def testIRuntimeInfoVerify(self): | ||
verifyObject(IRuntimeInfo, self._Test__new()) | ||
|
||
def test_PreferredEncoding(self): | ||
runtime_info = self._Test__new() | ||
enc = self._getPreferredEncoding() | ||
self.assertEqual(runtime_info.getPreferredEncoding(), enc) | ||
|
||
def test_FileSystemEncoding(self): | ||
runtime_info = self._Test__new() | ||
enc = self._getFileSystemEncoding() | ||
self.assertEqual(runtime_info.getFileSystemEncoding(), enc) | ||
|
||
def test_ZopeVersion(self): | ||
runtime_info = self._Test__new() | ||
|
||
# we expect that there is no utility | ||
self.assertEqual(runtime_info.getZopeVersion(), "") | ||
|
||
zapi.getSiteManager().provideUtility(IZopeVersion, TestZopeVersion()) | ||
self.assertEqual(runtime_info.getZopeVersion(), | ||
stupid_version_string) | ||
def test_PythonVersion(self): | ||
runtime_info = self._Test__new() | ||
enc = self._getPreferredEncoding() | ||
self.assertEqual(runtime_info.getPythonVersion(), | ||
unicode(sys.version, enc)) | ||
|
||
def test_SystemPlatform(self): | ||
runtime_info = self._Test__new() | ||
test_platform = (sys.platform,) | ||
if hasattr(os, "uname"): | ||
test_platform = os.uname() | ||
enc = self._getPreferredEncoding() | ||
self.assertEqual(runtime_info.getSystemPlatform(), | ||
unicode(" ".join(test_platform), enc)) | ||
|
||
def test_CommandLine(self): | ||
runtime_info = self._Test__new() | ||
self.assertEqual(runtime_info.getCommandLine(), " ".join(sys.argv)) | ||
|
||
def test_ProcessId(self): | ||
runtime_info = self._Test__new() | ||
self.assertEqual(runtime_info.getProcessId(), os.getpid()) | ||
|
||
def test_Uptime(self): | ||
runtime_info = self._Test__new() | ||
# whats the uptime we expect? | ||
|
||
start_time = applicationController.getStartTime() | ||
asserted_uptime = time.time() - start_time | ||
|
||
# get the uptime the current implementation calculates | ||
test_uptime = runtime_info.getUptime() | ||
|
||
self.failUnless(abs(asserted_uptime - test_uptime) < time_tolerance) | ||
|
||
|
||
def test_suite(): | ||
return unittest.TestSuite(( | ||
unittest.makeSuite(Test), | ||
)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |