예제 #1
0
    def test_oneInN_with_two_device_and_port( self, config ):
        N = OneInN()

        listeners = []
        data = {}
        device1 = '0x13a200409029bf'
        device2 = '0x13a200408cccc3'
        port = 'adc-1'

        data[Constants.DataPacket.device] = device1
        data[Constants.DataPacket.port] = port
        N.step( 1, data, listeners )
        self.assertEqual( N.count[device1][port], 1 )

        data[Constants.DataPacket.device] = device2
        data[Constants.DataPacket.port] = port
        N.step( 1, data, listeners )
        self.assertEqual( N.count[device2][port], 1 )

        data[Constants.DataPacket.device] = device1
        data[Constants.DataPacket.port] = port
        N.step( 1, data, listeners )
        self.assertEqual( N.count[device1][port], 2 )

        data[Constants.DataPacket.device] = device1
        data[Constants.DataPacket.port] = port
        N.step( 1, data, listeners )
        self.assertEqual( N.count[device1][port], 3 )

        N = None
예제 #2
0
    def test_oneInN_with_no_device( self, config ):
        N = OneInN()
        Common.send = Mock()
        N.config = {'0x13a200409029bf': {'adc-1': '2'}, '0x13a200408cccc3': {'adc-0': '2', 'adc-1': '5'}}
        listeners = ['a', 'b', 'c']
        data = {}
        port = 'adc-1'

        data[Constants.DataPacket.port] = port
        N.substep( 1, data, listeners )
        self.assertEqual( N.errors, 1 )
예제 #3
0
    def test_oneInN_using_abc_step( self, config ):
        N = OneInN()

        N.config = {'0x13a200409029bf': {'adc-1': '2'}, '0x13a200408cccc3': {'adc-0': '2', 'adc-1': '5'}}
        listeners = ['a', 'b', 'c']
        data = {}
        device1 = '0x13a200409029bf'
        device2 = '0x13a200408cccc3'
        port = 'adc-1'

        data[Constants.DataPacket.device] = device1
        data[Constants.DataPacket.port] = port
        N.substep( 1, data, listeners )
        self.assertEqual( N.count[device1][port], 1 )

        N.substep( 2, data, listeners )
        self.assertEqual( N.count[device1][port], 2 )

        N.substep( 3, data, listeners )
        self.assertEqual( N.count[device1][port], 3 )
예제 #4
0
    def test_oneInN_with_one_device_and_port( self, config ):
        N = OneInN()

        N.config = {'0x13a200409029bf': {'adc-1': '2'}, '0x13a200408cccc3': {'adc-0': '2', 'adc-1': '5'}}
        listeners = []
        data = {}
        device = '0x13a200409029bf'
        port = 'adc-1'
        data[Constants.DataPacket.device] = device
        data[Constants.DataPacket.port] = port
        N.step( 1, data, listeners )
        self.assertEqual( N.count[device][port], 1 )

        N.step( 1, data, listeners )
        self.assertEqual( N.count[device][port], 2 )

        N.step( 1, data, listeners )
        self.assertEqual( N.count[device][port], 3 )

        N = None
예제 #5
0
    def test_oneInN_with_no_device_in_count_dict( self, configuration ):
        N = OneInN()
        N.config = {'0x13a200409029bf': {'adc-1': '2'}, '0x13a200408cccc3': {'adc-0': '2', 'adc-1': '5'}}
        N.count = {}
        listeners = ['a', 'b', 'c']
        data = {}
        device = '0x13a200409029bf'
        port = 'adc-1'

        data[Constants.DataPacket.port] = port
        data[Constants.DataPacket.device] = device
        N.step( 1, data, listeners )
        self.assertEqual( N.count[device][port], 1 )
예제 #6
0
    def test_oneInN_with_one_device_in_count_dict_that_is_not_the_same( self, configuration ):
        device0 = 'device0'
        device1 = 'device1'
        port0 = 'port0'
        port1 = 'port1'

        N = OneInN()
        N.config = {device0: {port1: '2', port0: 10}, device1: {port0: '2', port1: '5'}}
        N.count = {device1: {port1: 10}}
        listeners = ['a', 'b', 'c']
        data = {}

        data[Constants.DataPacket.port] = port0
        data[Constants.DataPacket.device] = device0
        N.step( 1, data, listeners )
        self.assertEqual( N.count[device0][port0], 1 )
        self.assertEqual( N.count[device1][port1], 10 )
예제 #7
0
    def test_oneInN_with_no_device_in_count_dict( self, config ):
        N = OneInN()
        Common.send = Mock()
        GetDateTime.isoformat = Mock()
        GetDateTime.isoformat.return_value = '123'
        N.config = {'0x13a200409029bf': {'adc-1': '2'}, '0x13a200408cccc3': {'adc-0': '2', 'adc-1': '5'}}
        N.count = {}
        listeners = ['a', 'b', 'c']
        data = {}
        device = '0x13a200409029bf'
        port = 'adc-1'

        data[Constants.DataPacket.port] = port
        data[Constants.DataPacket.device] = device
        N.substep( 1, data, listeners )
        self.assertEqual( N.count[device][port], 1 )
        self.assertEqual( N.errors, 0 )
        self.assertEqual( N.counter, 1 )
예제 #8
0
    def test_oneInN_with_one_device_and_other_port_in_count_dict( self, send, configuration ):
        N = OneInN()
        GetDateTime.isoformat = Mock()
        GetDateTime.isoformat.return_value = '123'
        N.config = {'0x13a200409029bf': {'adc-1': '2', 'adc-0': 10}, '0x13a200408cccc3': {'adc-0': '2', 'adc-1': '5'}}
        N.count = {'0x13a200409029bf': {'adc-0': 10}}
        listeners = ['a', 'b', 'c']
        data = {}
        device0 = '0x13a200409029bf'
        device1 = '0x13a200408cccc3'
        port0 = 'adc-0'
        port1 = 'adc-1'

        data[Constants.DataPacket.port] = port1
        data[Constants.DataPacket.device] = device0
        N.substep( 1, data, listeners )
        self.assertEqual( N.count[device0][port0], 10 )
        self.assertEqual( N.count[device0][port1], 1 )
        self.assertEqual( N.errors, 0 )
        self.assertEqual( N.last_error_time, None )
        self.assertEqual( N.counter, 1 )
예제 #9
0
    def test_oneInN_with_one_device_in_count_dict_that_is_not_the_same( self, config ):
        device0 = 'device0'
        device1 = 'device1'
        port0 = 'port0'
        port1 = 'port1'

        N = OneInN()
        Common.send = Mock()
        GetDateTime.isoformat = Mock()
        GetDateTime.isoformat.return_value = '123'
        N.config = {device0: {port1: '2', port0: 10}, device1: {port0: '2', port1: '5'}}
        N.count = {device1: {port1: 10}}
        listeners = ['a', 'b', 'c']
        data = {}

        data[Constants.DataPacket.port] = port0
        data[Constants.DataPacket.device] = device0
        N.substep( 1, data, listeners )
        self.assertEqual( N.count[device0][port0], 1 )
        self.assertEqual( N.count[device1][port1], 10 )
        self.assertEqual( N.errors, 0 )
        self.assertEqual( N.counter, 1 )
예제 #10
0
 def test_configuration_file_name( self, config ):
     oin = OneInN()
     self.assertEqual( oin.configuration_file_name(), 'housemonitor.steps.oneInN' )