def testWebbrickStatusQuery(self):
        self._log.debug( "\n\ntestWebbrickStatusQuery" )

        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfigWebbrickStatusQuery) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        self.router.publish( EventAgent("TestWebbrickStatusMonitor"), Events.evtSecond5 )   # so webbrick is in list for recover
        self.router.publish( EventAgent("TestWebbrickStatusMonitor"), Events.evtMinute1 )    # do recover
        waitNSeconds(2)   # recover is async
        self.router.publish( EventAgent("TestWebbrickStatusMonitor"), Events.evtSecond5 )   # do scan
        waitNSeconds(2)   # scan is async

        # We should see lots of events here as initial pass.

        # my test rig only has 1 temp sensors.
        # so:
        # 1 temp sensors
        # 4 analogue in
        # 4 analogue out
        # 12 digital in
        # 8 digital out
        # 8 mimic out
        self.assert_( TestEventLogger.expectAtLeastNevents(36+NUM_TEMP_SENSORS), "expecting %u events" % (36+NUM_TEMP_SENSORS)  )
        oldLen = len(TestEventLogger._events)

        self.router.publish( EventAgent("TestWebbrickStatusMonitor"), Events.evtSecond5 )   # do scan
        waitNSeconds(2)   # scan is async

        TestEventLogger.logEvents()
        self.assert_( oldLen <= len(TestEventLogger._events) )
示例#2
0
    def testSend(self):
        self._log.debug( "\ntestListen" )
        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfigAsteriskSend) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()
        
        skt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        skt.connect(("localhost", 20998))

        skt.send( " agi_request: dialparties.agi\n" )
        skt.send( " agi_channel: SIP/100-b7a017f8\n" )
        skt.send( " agi_language: en\n" )
        skt.send( " agi_type: SIP\n" )
        skt.send( " agi_uniqueid: 1173178145.6\n" )
        skt.send( " agi_callerid: 100\n" )
        skt.send( " agi_calleridname: SNOM\n" )
        skt.send( " agi_callingpres: 0\n" )
        skt.send( " agi_callingani2: 0\n" )
        skt.send( " agi_callington: 0\n" )
        skt.send( " agi_callingtns: 0\n" )
        skt.send( " agi_dnid: 200\n" )
        skt.send( " agi_rdnis: unknown\n" )
        skt.send( " agi_context: macro-dial\n" )
        skt.send( " agi_extension: s\n" )
        skt.send( " agi_priority: 1\n" )
        skt.send( " agi_enhanced: 0.0\n" )
        skt.send( " agi_accountcode:\n" )
        skt.send( "\n" )

        skt.close()
    
        time.sleep(2)
        TestEventLogger.logEvents()
        self.assert_( len(TestEventLogger._events) >= 1)
    def testDeltaTime2(self):
        """
        Test the delta time event generator.
        """
        self._log.debug( "\n\ntestDeltaTime2" )
        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfigDeltaTime2) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        self.router.publish( EventAgent("TestDelayedEvent"), Events.evtTD0 )    # TD0 0 Off

        # time events are not in the log.
        TestEventLogger.logEvents()
        self.assertEqual( len(TestEventLogger._events), 2)
        self.assertEqual( TestEventLogger._events[0].getType(), "http://id.webbrick.co.uk/events/webbrick/TD" )
        self.assertEqual( TestEventLogger._events[1].getType(), "http://id.webbrick.co.uk/events/time/delta" )

        self.router.publish( EventAgent("TestDelayedEvent"), Events.evtMinute )    # minute
        self.router.publish( EventAgent("TestDelayedEvent"), Events.evtMinute )    # minute
        # delayed event should now be here.
        self.assertEqual( len(TestEventLogger._events), 4)
        self.assertEqual( TestEventLogger._events[2].getType(), "delta/delay" )
        self.assertEqual( TestEventLogger._events[2].getSource(), "delta/delay1" )
        self.assertEqual( TestEventLogger._events[3].getType(), "delta/delay" )
        self.assertEqual( TestEventLogger._events[3].getSource(), "delta/delay2" )
示例#4
0
    def testFloatCounterSet(self):
        """
        Set Counter to a fixed value 
        """
        _log.debug( "\ntestFloatCounterSet" )
        self.loader = EventRouterLoader()
        errCount = self.loader.loadHandlers( getDictFromXmlString(testConfigFloatCounterSet) )
        self.assertEqual( errCount, 0)

        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        self.router.publish( EventAgent("testCounters"), makeEvent( 'test/event', 'set/counter', { 'val':'300.45' } ) )

        TestEventLogger.logEvents()
        expectedEvents = { 
                    "test/event" : 
                            [
                                ("set/counter" , 'val', 300.45)
                            ],
                    "test/1" : 
                            [   ("test/entryCount",'val', 300.45)
                            ]
                     }
       
        Utils.expectNevents(self, 2)

        
        haveErr, excessEvents = Utils.verifyEvents2( expectedEvents, TestEventLogger._events )
        _log.debug( "Excess Events %s " % (excessEvents) )

        self.assertEqual( haveErr, False, "Incorrect event set" )
    def testTimeEvent4(self):
        """
        Run test with time interval in seconds.
        """
        self._log.debug( "\n\ntestTimeEvent4" )
        loader = EventRouterLoader()
        loader.loadHandlers( getDictFromXmlString(testConfigTime4) )

        loader.start()  # all tasks

        self._router = loader.getEventRouter()

        self.waitNEvents( 1 )
        TestEventLogger.logEvents()

        # first event should be isDark
        self.assert_( len(TestEventLogger._events) > 0)
        self.assertEqual( TestEventLogger._events[0].getType(), u'http://id.webbrick.co.uk/events/time/isDark' )
        self.assertEqual( TestEventLogger._events[0].getSource(), "time/isDark" )

        self.waitNEvents( 5 )
        TestEventLogger.logEvents()
        self.assert_( len(TestEventLogger._events) > 4)
        evt = TestEventLogger._events[1]
        od = evt.getPayload()
        self.assertEqual( len(od["timestr"]),8 )
        self.assertEqual( len(od["datestr"]),10 )
        self.assertEqual( len(od["datetimestr"]),19 )

        loader.stop()  # all tasks
        self.dumpEvents = False
    def testHttpAction2RequestsSpaced(self):
        self._log.debug( "\ntestHttpAction2RequestsSpaced" )

        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfigHttpAction) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()
        time.sleep(1)

        self.router.publish( EventAgent("TestHttpAction"), Events.evtTD0 )    # 0 Off

        maxTime = 10
        while (len(self.httpServer.requests()) < 1) and (maxTime > 0):
            maxTime -= 1
            time.sleep(1)

        self.router.publish( EventAgent("TestHttpAction"), Events.evtTD0 )    # 0 Off
        maxTime = 10
        while (len(self.httpServer.requests()) < 2) and (maxTime > 0):
            maxTime -= 1
            time.sleep(1)

        TestEventLogger.logEvents()

        # now look for correct url requests
        self._log.debug( "testHttpAction %s", self.httpServer.requests() )
        self.assertEqual( len(self.httpServer.requests()), 2)
        self.assertEqual( self.httpServer.requests()[0], "/test?medianame=ITunes&mediacmd=volup" )
        self.assertEqual( self.httpServer.requests()[1], "/test?medianame=ITunes&mediacmd=volup" )
    def testTimeEvent2(self):
        """
        Run test with time interval in seconds.
        """
        self._log.debug( "\ntestTimeEvent2" )
        loader = EventRouterLoader()
        loader.loadHandlers( getDictFromXmlString(testConfigTime2) )

        loader.start()  # all tasks

        self.waitNEvents( 5, 70 )

        # now look for correct url requests
        TestEventLogger.logEvents()
        self.assertEqual( len(TestEventLogger._events), 5)

        # the requests could be in either order.
        seenOne = 0
        seenTwo = 0
        for evnt in TestEventLogger._events:
            if ( evnt.getSource() == "local/BoilerOn" ):
                seenOne += 1
            elif ( evnt.getSource() == "local/HwOn" ):
                seenTwo += 1
            else:
                pass    # error
        self.assertEqual( seenOne, 1 )
        self.assertEqual( seenTwo, 4 )

        loader.stop()  # all tasks
        self.dumpEvents = False
示例#8
0
    def testIntCounterDec2Reset(self):
        _log.debug( "\ntestIntCounterDec2Reset" )
        self.loader = EventRouterLoader()
        errCount = self.loader.loadHandlers( getDictFromXmlString(testConfigDecrement2Reset) )
        self.assertEqual( errCount, 0)

        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        self.router.publish( EventAgent("testCounters"), Events.evtTD0 )
        self.router.publish( EventAgent("testCounters"), Events.evtTD0 )
        self.router.publish( EventAgent("testCounters"), Events.evtHour03 )

        TestEventLogger.logEvents()

        expectedEvents = { 
                    "http://id.webbrick.co.uk/events/webbrick/TD" : 
                            [
                                ("webbrick/100/TD/0" , None, None),
                                ("webbrick/100/TD/0" , None, None)
                            ],
                    "http://id.webbrick.co.uk/events/time/hour" : 
                            [   ("time/hour",None, None)
                            ],
                    "test/entryCount" : 
                            [   ("test/entryCount",'val', 98)
                            ,   ("test/entryCountTotal",'val', 100)
                            ],
                     }
        Utils.expectNevents(self, 5)

        haveErr, excessEvents = Utils.verifyEvents2( expectedEvents, TestEventLogger._events )
        _log.debug( "Excess Events %s " % (excessEvents) )

        self.assertEqual( haveErr, False, "Incorrect event set" )
    def testOnkyo(self):
        self._log.debug( "\ntestOnkyo" )
        
        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfigOnkyo) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        self.router.publish( EventAgent("testVolume"), evtOnkyoVolume0 )

        # time events are not in the log.
        self.assert_(TestEventLogger.expectNevents(2))
        self.assertEqual( TestEventLogger._events[0].getSource(), "webbrick/1/100" )
        evt = TestEventLogger._events[1]
        self.assertEqual( evt.getType(), "avamplifier/volume/current" )
        self.assertEqual( evt.getSource(), "avamplifier/1/volume/main/current" )
        evtod = evt.getPayload()
        self.assert_( evtod.has_key("val") )
        self.assertEqual( evtod["val"], 0 )
        
        self.router.publish( EventAgent("testVolume"), evtOnkyoVolume50 )
        self.assert_(TestEventLogger.expectNevents(4))
        
        self.router.publish( EventAgent("testVolume"), evtOnkyoVolume100 )
        self.assert_(TestEventLogger.expectNevents(6))
        
        TestEventLogger.logEvents()
示例#10
0
    def testCompoundNewState(self):
        self._log.debug( "\ntestCompoundNewState" )

        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfigCompoundEventNewState) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        # initial state is all things off.
        self.router.publish( EventAgent("TestCompound"), Events.evtMinute1 )

        TestEventLogger.logEvents()
        self.expectNevents( 1 )

        self.router.publish( EventAgent("TestCompound"), Events.evtMinute2 )
        self.expectNevents( 3 )
        self.assertEqual( TestEventLogger._events[2].getType(), u'internal' )
        self.assertEqual( TestEventLogger._events[2].getSource(), "testState" )
        od = TestEventLogger._events[2].getPayload()
        self.assertEqual( od["idx"], '1' )

        self.router.publish( EventAgent("TestCompound"), Events.evtMinute3 )
        self.expectNevents( 4 )

        self.router.publish( EventAgent("TestCompound"), Events.evtMinute4 )
        self.expectNevents( 6 )
        self.assertEqual( TestEventLogger._events[5].getType(), u'internal' )
        self.assertEqual( TestEventLogger._events[5].getSource(), "testState" )
        od = TestEventLogger._events[5].getPayload()
        self.assertEqual( od["idx"], 3 )  # previous minute
    def testTestEventLogger(self):
        """
        Test loading the test event logger
        """
        _log.debug( "\ntestTestEventLogger" )
        self._loader = EventRouterLoader()
        self._loader.loadHandlers( getDictFromXmlString(testConfigTestEventLogger) )

        self._loader.start()  # all tasks

        self._router = self._loader.getEventRouter()

        self._router.publish( EventAgent("TestEventRouterLoad"), Events.evtTD0 )
        self._router.publish( EventAgent("TestEventRouterLoad"), Events.evtTD1 )
        
        if len(TestEventLogger._events) < 2 :
            time.sleep(1)   # allow threading to catch up.

        # now look for correct events requests
        TestEventLogger.logEvents()

        self.assertEqual( len(TestEventLogger._events), 2)
        self.assertEqual( TestEventLogger._events[0].getType(), "http://id.webbrick.co.uk/events/webbrick/TD" )
        self.assertEqual( TestEventLogger._events[0].getSource(), "webbrick/100/TD/0" )
        self.assertEqual( TestEventLogger._events[1].getType(), "http://id.webbrick.co.uk/events/webbrick/TD" )
        self.assertEqual( TestEventLogger._events[1].getSource(), "webbrick/100/TD/1" )
 def testSetDOOff(self):
     self._log.debug( "\n\ntestSetDOOff" )
     self.timeout = time.time() + 5
     do = DigitalOutput('do/type','do/source',self.router,'10.100.100.100','2')
     do.turnOff()
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType() == 'do/type'
     assert TestEventLogger._events[0].getSource() == 'do/source/off'
 def testSetDODwellFinish(self):
     self._log.debug( "\n\ntestSetDOOn" )
     self.timeout = time.time() + 15
     do = DigitalOutput('do/type','do/source',self.router,'10.100.100.100','2')
     do.turnOn()
     #let eventrouter catch up
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType() == 'do/type'
     assert TestEventLogger._events[0].getSource() == 'do/source/on'
示例#14
0
    def expectNevents(self, cnt):
        idx = 2000
        while (len(TestEventLogger._events) < cnt) and (idx > 0):
            time.sleep(0.05)
            idx = idx - 1

        if len(TestEventLogger._events) != cnt:
            TestEventLogger.logEvents()

        self.assertEqual(len(TestEventLogger._events), cnt)
 def testSetDOOnDwell(self):
     self._log.debug( "\n\ntestSetDOOn" )
     self.timeout = time.time() + 15
     do = DigitalOutput('do/type','do/source',self.router,'10.100.100.100','2')
     do.turnOn(100)
     #let eventrouter catch up
     time.sleep(0.2)
     assert TestEventLogger._events[0].getType() == 'do/type'
     assert TestEventLogger._events[0].getSource() == 'do/source/dwell'
     assert TestEventLogger._events[0].getPayload()['val'] == '100'
     TestEventLogger.logEvents()
    def testLoad(self):
        self._log.debug( "\ntestLoad" )
        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfig1) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()
        time.sleep(1.0)

        # We should see lots of events here as initial pass.
        TestEventLogger.logEvents()
        oldLen = len(TestEventLogger._events)
        self.assertEqual( oldLen, 11 )  # twice sent.
    def testOutOfRange(self):
        self._log.debug( "\ntestOutOfRange" )
        
        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfigOutofRange) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        self.router.publish( EventAgent("testVolume"), outofrangeoffset )
        time.sleep(1)        
        self.assertEqual( len(TestEventLogger._events), 1 )
        TestEventLogger.logEvents()
示例#18
0
 def testDigitalTimedConfig(self):
     """
         Test to make sure the valve is configuring itself properly with two digital outputs
     """
     TestEventLogger.logEvents()
     self._log.debug( "\n\nTestConfig")
     valveCfg = getDictFromXmlString(digitalTimedCfg)
     valve = Valve(valveCfg['valve'],self.router)
     assert valve.move['TS'][1] == 1
     assert valve.move['CS'][1] == 2
     
     assert valve.move['TS'][0].onCmd == 'DO;1;N:'
     assert valve.move['CS'][0].onCmd == 'DO;2;N:'
示例#19
0
 def testAnalogConfig(self):
     """
         Test to make sure the valve is configuring itself properly when using an analog output
     """
     TestEventLogger.logEvents()
     self._log.debug( "\n\nTestConfig")
     valveCfg = getDictFromXmlString(aCfg)
     self.valve = Valve(valveCfg['valve'],self.router)
     
     assert self.valve.aOutput == '3'
     assert self.valve.name == "Test Valve"
     assert self.valve.key == "tv1"
     assert self.valve.ao.aoCmd == 'AA;3;%(val)s:'
    def testTimeEvent1(self):
        """
        Run test with time interval in minutes.
        """
        self._log.debug( "\n\ntestTimeEvent1" )
        loader = EventRouterLoader()
        loader.loadHandlers( getDictFromXmlString(testConfigTime1) )

        loader.start()  # all tasks

        self._router = loader.getEventRouter()

        self.waitNEvents( 1 )

        # should have isDark or isLight event
        TestEventLogger.logEvents()

        self.assertEqual( len(TestEventLogger._events), 1)
        self.assertEqual( TestEventLogger._events[0].getType(), u'http://id.webbrick.co.uk/events/time/isDark' )
        self.assertEqual( TestEventLogger._events[0].getSource(), "time/isDark" )
        # assume testing during daylight hours
        od = TestEventLogger._events[0].getPayload()
        #self.assertEqual( od["state"], 0 )

        maxTime = 70
        while (TestEventLogger._events[-1].getType() != u'http://id.webbrick.co.uk/events/time/minute') and (maxTime > 0):
            maxTime -= 1
            time.sleep(1)

        TestEventLogger.logEvents()

        # now look for correct url requests
        self.failUnless( len(TestEventLogger._events) >= 2)
        self.assertEqual( TestEventLogger._events[-1].getType(), u'http://id.webbrick.co.uk/events/time/minute' )
        self.assertEqual( TestEventLogger._events[-1].getSource(), "time/minute" )
        od = TestEventLogger._events[-1].getPayload()
        self.failUnless( od.has_key("second") ) 
        self.failUnless( od.has_key("minute") ) 
        self.failUnless( od.has_key("hour") ) 
        self.failUnless( od.has_key("day") ) 
        self.failUnless( od.has_key("date") ) 
        self.failUnless( od.has_key("month") ) 
        self.failUnless( od.has_key("year") ) 
        self.failUnless( od.has_key("week") ) 
        self.failUnless( od.has_key("dayofyear") ) 
        self.failUnless( od.has_key("timestr") ) 
        self.failUnless( od.has_key("datestr") ) 
        self.failUnless( od.has_key("datetimestr") ) 

        loader.stop()  # all tasks
        self.dumpEvents = False
示例#21
0
    def testListen(self):
        self._log.debug( "\ntestListen" )
        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfigAsteriskListen) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        cDown = 120
        while cDown > 0 and len(TestEventLogger._events) <= 0:
            cDown = cDown - 1
            time.sleep(1)

        TestEventLogger.logEvents()
        self.assert_( len(TestEventLogger._events) >= 1)
 def testSetDOOffCorrect(self):
     self._log.debug( "\n\ntestSetDOOn" )
     self.timeout = time.time() + 15
     do = DigitalOutput('do/type','do/source',self.router,'10.100.100.100','2')
     doEvent = makeEvent('http://id.webbrick.co.uk/events/webbrick/DO','webbrick/100/DO/2',{'state':'1'})
     do.turnOff()
     self.router.publish(doEvent.getSource(),doEvent)
     #let eventrouter catch up
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType() == 'do/type'
     assert TestEventLogger._events[0].getSource() == 'do/source/off'        
     assert TestEventLogger._events[2].getType() == 'do/type'
     assert TestEventLogger._events[2].getSource() == 'do/source/off'
    def testBadCommand(self):
        self._log.debug( "\ntestBadCommand" )
        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfigBadcommand) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        self.router.publish( EventAgent("TestRgbLedLighting"), Events.evtSecond5 )
        time.sleep(1)

        oldLen = len(TestEventLogger._events)
        TestEventLogger.logEvents()

        self.assertEqual( oldLen, 1 )
示例#24
0
    def testFirstRead(self):
        _log.debug( "\ntestFirstRead" )
        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfigHeatmiser) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        time.sleep(1)

        oldLen = len(TestEventLogger._events)
        # for each schedule entry 4 weekday, 4 weekend
        # send time and day event and set point event
        # 16 events
        # send two current values setpoint and current value
        
        expectedEvents = { 
                    "http://id.webbrick.co.uk/events/config/set" : 
                            [
                                ("schedule/room2/0" , 'time', '07:00:00', 'day', '-MTWtF-'),
                                ("schedule/room2/1" , 'time', '08:30:00', 'day', '-MTWtF-'),
                                ("schedule/room2/2" , 'time', '16:00:00', 'day', '-MTWtF-'),
                                ("schedule/room2/3" , 'time', '22:30:00', 'day', '-MTWtF-'),
                                ("schedule/room2/4" , 'time', '07:00:00', 'day', 'S-----s'),
                                ("schedule/room2/5" , 'time', '08:30:00', 'day', 'S-----s'),
                                ("schedule/room2/6" , 'time', '16:00:00', 'day', 'S-----s'),
                                ("schedule/room2/7" , 'time', '22:30:00', 'day', 'S-----s'),
                                ("schedule/room2/0/room2" , 'val', None),
                                ("schedule/room2/1/room2" , 'val', None),
                                ("schedule/room2/2/room2" , 'val', None),
                                ("schedule/room2/3/room2" , 'val', None),
                                ("schedule/room2/4/room2" , 'val', None),
                                ("schedule/room2/5/room2" , 'val', None),
                                ("schedule/room2/6/room2" , 'val', None),
                                ("schedule/room2/7/room2" , 'val', None),
                            ],
                    "http://id.webbrick.co.uk/events/heatmiser/current":
                            [
                                ("heatmiser/room2/setpoint" , 'val', None ),
                                ("heatmiser/room2/temperature" , 'val', None ),
                            ]
                }

        TestEventLogger.logEvents()
        _log.info( "Expected Events %s " % (expectedEvents) )
        haveErr, excessEvents = Utils.verifyEvents( expectedEvents, TestEventLogger._events )

        _log.info( "Excess Events %s " % (excessEvents) )

        self.assertEqual( haveErr, False, "Incorrect event set" )
示例#25
0
    def testLoad(self):
        _log.debug( "\ntestLoad" )
        self.loader = EventRouterLoader()
        errCount = self.loader.loadHandlers( getDictFromXmlString(testConfigIncrement) )
        self.assertEqual( errCount, 0)

        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        self.router.publish( EventAgent("testCounters"), Events.evtMinute1 )

        Utils.expectNevents(self, 1)

        TestEventLogger.logEvents()
        self.assertEqual( len(TestEventLogger._events), 1)
        self.assertEqual( TestEventLogger._events[0].getSource(), "time/minute" )
示例#26
0
 def testDigitalConfig(self):
     """
         Test to make sure the valve is configuring itself properly when using a single digital output
         Commonly a spring loaded valve
     """
     TestEventLogger.logEvents()
     self._log.debug( "\n\nTestConfig")
     valveCfg = getDictFromXmlString(digitalCfg)
     valve = Valve(valveCfg['valve'],self.router)
  
     assert valve.wbTarget == "10.100.100.102"
     assert valve.name == "Test Valve"
     assert valve.key == "tv1"
     assert valve.type == 'digital'
     assert valve.move == {'CS':'0','TS':'1'}
     assert valve.dOutput == '1'
     assert valve.do.onCmd == 'DO;1;N:'
    def doSimpleTest(self):

        self._router.publish( EventAgent("TestEventRouterLoad"), Events.evtDO_0_off )
        self._router.publish( EventAgent("TestEventRouterLoad"), Events.evtDO_1_off )
        self._router.publish( EventAgent("TestEventRouterLoad"), Events.evtDO_1_on )

        if len(TestEventLogger._events) < 8 :
            time.sleep(1)   # allow threading to catch up.

        # now look for correct events requests
        TestEventLogger.logEvents()

        self.assertEqual( len(TestEventLogger._events), 5)
        base = 0
#        self.assertEqual( len(TestEventLogger._events), 8)
#        self.assertEqual( TestEventLogger._events[0].getType(), "http://id.webbrick.co.uk/events/subscribe" )
#        self.assertEqual( TestEventLogger._events[1].getType(), "http://id.webbrick.co.uk/events/subscribe" )
#        self.assertEqual( TestEventLogger._events[2].getType(), "http://id.webbrick.co.uk/events/subscribe" )
#        base = 3

        #
        # artifact of simple router is that the event logger may see new events before triggering events.
        #
        # type, source and space for a parameter

        expectedEvents = { 
                    "local/url" : 
                            [
                                ("local/BoilerOn",),
                                ("local/HwOn",),
                            ],
                    "http://id.webbrick.co.uk/events/webbrick/DO" : 
                            [   
                                ("webbrick/100/DO/0",),
                                ("webbrick/100/DO/1",),
                                ("webbrick/100/DO/1",),
                            ],
                     }
        _log.debug( "Received Events %s " % (TestEventLogger._events) )

        haveErr, excessEvents = Utils.verifyEvents( expectedEvents, TestEventLogger._events )

        _log.debug( "Excess Events %s " % (excessEvents) )

        self.assertEqual( haveErr, False, "Incorrect event set" )
示例#28
0
    def testSecondRead(self):
        _log.debug( "\ntestSecondRead" )
        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfigHeatmiser) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        time.sleep(1)   # allow start
        oldLen = len(TestEventLogger._events)
        self.assertEqual( oldLen, 18 )

        self.router.publish( EventAgent("TestHeatmiser"), Events.evtSecond15 )  # re-read
        time.sleep(1)

        TestEventLogger.logEvents()

        # additional time event
        self.assertEqual( oldLen+1, len(TestEventLogger._events) )
    def testReadLogFile2(self):

        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfig) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()

        ReadLogFileSendEvents( "resources/EventLog.log", self.router )

        TestEventLogger.expectNevents(9)
        self.assertEqual( TestEventLogger._events[0].getSource(), "temperature/outside" )
        self.assertEqual( TestEventLogger._events[1].getSource(), "webbrick/3/1" )
        self.assertEqual( TestEventLogger._events[2].getSource(), "webbrick/3/1" )
        self.assertEqual( TestEventLogger._events[3].getSource(), "webbrick/6" )
        self.assertEqual( TestEventLogger._events[4].getSource(), "webbrick/2" )
        self.assertEqual( TestEventLogger._events[5].getSource(), "webbrick/7" )
        self.assertEqual( TestEventLogger._events[6].getSource(), "webbrick/4" )
        self.assertEqual( TestEventLogger._events[7].getSource(), "webbrick/9/CT/3" )
        self.assertEqual( TestEventLogger._events[8].getSource(), "webbrick/9/AI/0" )
    def testTimeEvent3(self):
        """
        Run test with time interval in seconds.
        """
        self._log.debug( "\n\ntestTimeEvent3" )
        loader = EventRouterLoader()
        loader.loadHandlers( getDictFromXmlString(testConfigTime3) )

        loader.start()  # all tasks

        self._router = loader.getEventRouter()

        self.waitNEvents( 16, 20 )

        TestEventLogger.logEvents()
        self.assert_( len(TestEventLogger._events) > 16)

        loader.stop()  # all tasks
        self.dumpEvents = False