ServiceTest.py :  » Database » Python-Remote-Objects » Pyro-3.10 » Pyro » ext » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » Python Remote Objects 
Python Remote Objects » Pyro 3.10 » Pyro » ext » ServiceTest.py
#############################################################################
#
#  $Id: ServiceTest.py,v 1.1 2003/03/13 22:00:31 irmen Exp $
#  A test for the PyroNS_NTService program
#   Author: Syver Enstad  syver-en@online.no
#
#  This is part of "Pyro" - Python Remote Objects
#  Which is (c) Irmen de Jong - irmen@users.sourceforge.net
#
#############################################################################

import unittest
import win32serviceutil
import win32service
import time
import Pyro.nsc

ServiceName = 'PyroNS'

class Test(unittest.TestCase):
  def setUp(self):
    win32serviceutil.StartService(ServiceName)
    
  def testStartPending(self):
    svcType, svcState, svcControls, err, svcErr, svcCP, svcWH = \
         win32serviceutil.QueryServiceStatus(ServiceName)
    assert svcState & win32service.SERVICE_START_PENDING
    
  def testFullyStarted(self):
    self._waitForStarted()
    svcType, svcState, svcControls, err, svcErr, svcCP, svcWH = \
         win32serviceutil.QueryServiceStatus(ServiceName)
    assert svcType & win32service.SERVICE_WIN32_OWN_PROCESS
    assert svcState & win32service.SERVICE_RUNNING
    assert svcControls & win32service.SERVICE_ACCEPT_STOP

  def testStop(self):
    self._waitForStarted()
    svcType, svcState, svcControls, err, svcErr, svcCP, svcWH = \
         win32serviceutil.StopService(ServiceName)
    assert svcState & win32service.SERVICE_STOPPED
    assert svcType & win32service.SERVICE_WIN32_OWN_PROCESS

  def testNameserverAvailable(self):
    self._waitForStarted()
    ctrl = Pyro.nsc.PyroNSControl()
    ctrl.args(None)
    ctrl.ping()

  def testNameserverShutdownFromNsc(self):
    self._waitForStarted()
    ctrl = Pyro.nsc.PyroNSControl()
    ctrl.args(None)
    ctrl.shutdown()
    for each in range(100):
      svcType, svcState, svcControls, err, svcErr, svcCP, svcWH = \
           win32serviceutil.QueryServiceStatus(ServiceName)
      if svcState & win32service.SERVICE_STOPPED:
        return
      time.sleep(0.20)
    self.fail()

  def tearDown(self):
    for each in range(1000):
      svcType, svcState, svcControls, err, svcErr, svcCP, svcWH = \
           win32serviceutil.QueryServiceStatus(ServiceName)
      if svcState & win32service.SERVICE_RUNNING:
        svcType, svcState, svcControls, err, svcErr, svcCP, svcWH = \
             win32serviceutil.StopService(ServiceName)
        time.sleep(0.1)
      elif svcState & win32service.SERVICE_STOPPED:
        time.sleep(0.10)
        break
      else:
        time.sleep(0.10)
    assert svcState & win32service.SERVICE_STOPPED
    time.sleep(3)

  def _waitForStarted(self):
    for each in range(100):
      svcType, svcState, svcControls, err, svcErr, svcCP, svcWH = \
           win32serviceutil.QueryServiceStatus(ServiceName)
      if svcState & win32service.SERVICE_RUNNING:
        break
      else:
        time.sleep(0.10)

    
if __name__ == '__main__':
  unittest.main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.