[Zope-Checkins] CVS: Zope/lib/python/ZServer/tests - testClockServer.py:1.1.2.1

Chris McDonough chrism at plope.com
Thu Dec 25 04:07:47 EST 2003


Update of /cvs-repository/Zope/lib/python/ZServer/tests
In directory cvs.zope.org:/tmp/cvs-serv22553/lib/python/ZServer/tests

Added Files:
      Tag: chrism-scheduling-branch
	testClockServer.py 
Log Message:
Initial clock server implementation.  The clock server generates a faux http request to a traversable method at a regular interval using arbitrary authentication credentials without the aid of an external process (it uses ZServer internals to schedule the request like any other Zope request).  The method, the interval, and the credentials are configurable via the Zope config file.  More than one clock server can be caused to run per instance.


=== Added File Zope/lib/python/ZServer/tests/testClockServer.py ===
##############################################################################
#
# 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.0 (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.
#
##############################################################################

import os, sys, unittest, time, math
import Lifetime, ZServer
from Lifetime.timeslice import timeslice
from ZServer import ClockServer

class TestClockServer( unittest.TestCase ):
    """ Test the ClockServer module """
    def setUp(self):
        self.c = ClockServer.ClockServer(
            '/amethod?abc=123', 30, 'user', 'pass','host')

    def tearDown(self):
        self.c.del_channel()
        
    def test_init(self):
        c = self.c
        cid = id(c)
        self.failUnless(ClockServer._last_slices.has_key(cid))
        self.assertEqual(c.period, 30)
        self.assertEqual(c.method, '/amethod?abc=123')
        self.assert_(c.headers)
        self.assert_(c.headers.index('Authorization: Basic dXNlcjpwYXNz'))

    def test_getenv(self):
        c = self.c
        req, zreq, resp = c.get_requests_and_response()
        env = c.get_env(req)
        self.assertEqual(env['PATH_INFO'], '/amethod')
        self.assertEqual(env['QUERY_STRING'], 'abc=123')
        self.assertEqual(env['HTTP_AUTHORIZATION'], 'Basic dXNlcjpwYXNz')
        

def test_suite():
    suite = unittest.TestSuite()
    suite.addTest( unittest.makeSuite( TestClockServer ) )
    return suite

def main():
    unittest.main(defaultTest='test_suite')

if __name__ == '__main__':
    main()




More information about the Zope-Checkins mailing list