예제 #1
0
    def test_Rcv_Sensor(self):
        """Does Recieve work when that sensortype is not in the DB"""

        now = datetime.datetime.utcnow()
        #Create our bitmask
        bs = Bitset(size = Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_D_TEMPERATURE] = True

        #Then A packet
        packet = StateMsg(addr = 4242)
        packet.set_ctp_parent_id(101) #Parent Node Id
        packet.set_special(0xc7) #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5])

        self.testbif.receive(packet)
        output = self.blogger.mainloop()
        self.assertTrue(output)

        #Check stuff gets added to the database correctly
        session = self.Session()

        #Does the sensortype exist now (Apparently its not a FK in Reading)
        #qry = session.query(models.SensorType).filter_by(id=1).first()
        #self.assertTrue(qry)
        #Is the name UNKNOWN
        #self.assertEqual(qry.Name, "UNKNOWN")


        #NodeState
        qry = session.query(models.NodeState).filter_by(nodeId = 4242)
        self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertTrue(qry)
        tdiff = qry.time - now
        self.assertLess(tdiff.seconds, 1.0)
        self.assertEqual(qry.parent, 101)

        #And Reading
        qry = session.query(models.Reading).filter_by(nodeId = 4242)
        #As we just did temperature there should only be one reading
        self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertTrue(qry)
        self.assertEqual(qry.typeId, 1)
        self.assertEqual(qry.value, 22.5)

        #Reset the sensor type to be as it should
        qry = session.query(models.SensorType).filter_by(id = 1).first()
        if qry is None:
            qry = models.SensorType(id = 1)
            session.add(qry)

        qry.name = "Delta Temperature"
        qry.code = "dT"
        qry.units = "deg.C/s"
예제 #2
0
    def test_Rcv_Sensor(self):
        """Does Recieve work when that sensortype is not in the DB"""

        now = datetime.datetime.utcnow()
        #Create our bitmask
        bs = Bitset(size=Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_D_TEMPERATURE] = True

        #Then A packet
        packet = StateMsg(addr=4242)
        packet.set_ctp_parent_id(101)  #Parent Node Id
        packet.set_special(0xc7)  #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5])

        self.testbif.receive(packet)
        output = self.blogger.mainloop()
        self.assertTrue(output)

        #Check stuff gets added to the database correctly
        session = self.Session()

        #Does the sensortype exist now (Apparently its not a FK in Reading)
        #qry = session.query(models.SensorType).filter_by(id=1).first()
        #self.assertTrue(qry)
        #Is the name UNKNOWN
        #self.assertEqual(qry.Name, "UNKNOWN")

        #NodeState
        qry = session.query(models.NodeState).filter_by(nodeId=4242)
        self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertTrue(qry)
        tdiff = qry.time - now
        self.assertLess(tdiff.seconds, 1.0)
        self.assertEqual(qry.parent, 101)

        #And Reading
        qry = session.query(models.Reading).filter_by(nodeId=4242)
        #As we just did temperature there should only be one reading
        self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertTrue(qry)
        self.assertEqual(qry.typeId, 1)
        self.assertEqual(qry.value, 22.5)

        #Reset the sensor type to be as it should
        qry = session.query(models.SensorType).filter_by(id=1).first()
        if qry is None:
            qry = models.SensorType(id=1)
            session.add(qry)

        qry.name = "Delta Temperature"
        qry.code = "dT"
        qry.units = "deg.C/s"
예제 #3
0
    def testrecvCombined(self):
        """Can we correctly recieve and packets with multiple readings"""
        now = datetime.datetime.utcnow()

        #Create our bitmask
        bs = Bitset(size=Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_TEMPERATURE] = True
        bs[Packets.SC_HUMIDITY] = True
        bs[Packets.SC_VOLTAGE] = True

        #Then A packet
        packet = StateMsg(addr=100)
        packet.set_ctp_parent_id(101) #Parent Node Id
        packet.set_special(0xc7) #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5, 50.0, 2.45])

        self.testbif.receive(packet)
        output = self.blogger.mainloop()
        self.assertTrue(output)


        #And check the data has arrived
        session = self.Session()
        qry = session.query(models.NodeState)
        #self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertEqual(qry.nodeId, 100)
        self.assertEqual(qry.parent, 101)

        #Do we get the temperature reading
        qry = session.query(models.Reading).filter_by(typeId = 0)
        #self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertEqual(qry.nodeId, 100)
        self.assertEqual(qry.value, 22.5)

        #Humidity
        qry = session.query(models.Reading).filter_by(typeId = 2)
        #self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertEqual(qry.nodeId, 100)
        self.assertEqual(qry.value, 50.0)

        #Voltage
        qry = session.query(models.Reading).filter_by(typeId = 6)
        #self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertEqual(qry.nodeId, 100)
        self.assertAlmostEqual(qry.value, 2.45)
예제 #4
0
    def testrecvCombined(self):
        """Can we correctly recieve and packets with multiple readings"""
        now = datetime.datetime.utcnow()

        #Create our bitmask
        bs = Bitset(size=Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_TEMPERATURE] = True
        bs[Packets.SC_HUMIDITY] = True
        bs[Packets.SC_VOLTAGE] = True

        #Then A packet
        packet = StateMsg(addr=100)
        packet.set_ctp_parent_id(101)  #Parent Node Id
        packet.set_special(0xc7)  #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5, 50.0, 2.45])

        self.testbif.receive(packet)
        output = self.blogger.mainloop()
        self.assertTrue(output)

        #And check the data has arrived
        session = self.Session()
        qry = session.query(models.NodeState)
        #self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertEqual(qry.nodeId, 100)
        self.assertEqual(qry.parent, 101)

        #Do we get the temperature reading
        qry = session.query(models.Reading).filter_by(typeId=0)
        #self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertEqual(qry.nodeId, 100)
        self.assertEqual(qry.value, 22.5)

        #Humidity
        qry = session.query(models.Reading).filter_by(typeId=2)
        #self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertEqual(qry.nodeId, 100)
        self.assertEqual(qry.value, 50.0)

        #Voltage
        qry = session.query(models.Reading).filter_by(typeId=6)
        #self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertEqual(qry.nodeId, 100)
        self.assertAlmostEqual(qry.value, 2.45)
예제 #5
0
    def testDuplicateFunction(self):
        """Test the duplicate packet function"""


        #Create our bitmask
        bs = Bitset(size=Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_TEMPERATURE] = True

        #Then A packet
        packet = StateMsg(addr = 4242)
        packet.set_ctp_parent_id(101) #Parent Node Id
        packet.set_special(0xc7) #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5])

        #Store the initial packet
        self.testbif.receive(packet)
        output = self.blogger.mainloop()
        self.assertTrue(output)

        now = datetime.datetime.utcnow()
        #Check the duplicate function

        #session = self.blogger.getSession()

        #Duplicate packet has been renamed
        session = self.Session()
        out = BaseLogger.duplicate_packet(session = session,
                                          receipt_time = now,
                                          node_id = 4242,
                                          localtime = 0)
        #out = self.blogger.duplicate_packet(session = session,
                                          # time = now,
                                          # nodeId = 4242,
                                          # localtime = 0)
        self.assertTrue(out)

        now = now+datetime.timedelta(minutes=1)
        #out = self.blogger.duplicate_packet(session = session,
        #                                    time = now,
        #                                    nodeId = 4242,
        #                                    localtime = 0)
        out = BaseLogger.duplicate_packet(session = session,
                                          receipt_time = now,
                                          node_id = 4242,
                                          localtime = 0)
        self.assertFalse(out)
예제 #6
0
    def testDuplicateFunction(self):
        """Test the duplicate packet function"""

        #Create our bitmask
        bs = Bitset(size=Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_TEMPERATURE] = True

        #Then A packet
        packet = StateMsg(addr=4242)
        packet.set_ctp_parent_id(101)  #Parent Node Id
        packet.set_special(0xc7)  #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5])

        #Store the initial packet
        self.testbif.receive(packet)
        output = self.blogger.mainloop()
        self.assertTrue(output)

        now = datetime.datetime.utcnow()
        #Check the duplicate function

        #session = self.blogger.getSession()

        #Duplicate packet has been renamed
        session = self.Session()
        out = BaseLogger.duplicate_packet(session=session,
                                          receipt_time=now,
                                          node_id=4242,
                                          localtime=0)
        #out = self.blogger.duplicate_packet(session = session,
        # time = now,
        # nodeId = 4242,
        # localtime = 0)
        self.assertTrue(out)

        now = now + datetime.timedelta(minutes=1)
        #out = self.blogger.duplicate_packet(session = session,
        #                                    time = now,
        #                                    nodeId = 4242,
        #                                    localtime = 0)
        out = BaseLogger.duplicate_packet(session=session,
                                          receipt_time=now,
                                          node_id=4242,
                                          localtime=0)
        self.assertFalse(out)
예제 #7
0
    def test_Rcv_Node(self):
        """Does Recieve work when that node is not in the DB"""

        now = datetime.datetime.utcnow()

        #Create our bitmask
        bs = Bitset(size=Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_TEMPERATURE] = True

        #Then A packet
        packet = StateMsg(addr=100)
        packet.set_ctp_parent_id(101)  #Parent Node Id
        packet.set_special(0xc7)  #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5])

        self.testbif.receive(packet)
        output = self.blogger.mainloop()
        self.assertTrue(output)

        #Check stuff gets added to the database correctly
        session = self.Session()
        #Has a node been added to the DB
        qry = session.query(models.Node).filter_by(id=100).first()
        self.assertTrue(qry)

        #NodeState
        qry = session.query(models.NodeState).filter_by(nodeId=100)
        self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertTrue(qry)
        tdiff = qry.time - now
        self.assertLess(tdiff.seconds, 1.0)
        self.assertEqual(qry.parent, 101)

        #And Reading
        qry = session.query(models.Reading).filter_by(nodeId=100)
        #As we just did temperature there should only be one reading
        self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertTrue(qry)
        self.assertEqual(qry.typeId, 0)
        self.assertEqual(qry.value, 22.5)
예제 #8
0
    def test_Rcv_Node(self):
        """Does Recieve work when that node is not in the DB"""

        now = datetime.datetime.utcnow()

        #Create our bitmask
        bs = Bitset(size = Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_TEMPERATURE] = True

        #Then A packet
        packet = StateMsg(addr=100)
        packet.set_ctp_parent_id(101) #Parent Node Id
        packet.set_special(0xc7) #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5])

        self.testbif.receive(packet)
        output = self.blogger.mainloop()
        self.assertTrue(output)

        #Check stuff gets added to the database correctly
        session = self.Session()
        #Has a node been added to the DB
        qry = session.query(models.Node).filter_by(id = 100).first()
        self.assertTrue(qry)

        #NodeState
        qry = session.query(models.NodeState).filter_by(nodeId = 100)
        self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertTrue(qry)
        tdiff = qry.time - now
        self.assertLess(tdiff.seconds, 1.0)
        self.assertEqual(qry.parent, 101)

        #And Reading
        qry = session.query(models.Reading).filter_by(nodeId = 100)
        #As we just did temperature there should only be one reading
        self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertTrue(qry)
        self.assertEqual(qry.typeId, 0)
        self.assertEqual(qry.value, 22.5)
예제 #9
0
    def testRcv(self):
        """Test a single receive"""
        now = datetime.datetime.utcnow()

        #Create our bitmask
        bs = Bitset(size=Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_TEMPERATURE] = True

        #Then A packet
        packet = StateMsg(addr=4242)
        packet.set_ctp_parent_id(101)  #Parent Node Id
        packet.set_special(0xc7)  #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5])

        self.testbif.receive(packet)
        output = self.blogger.mainloop()
        self.assertTrue(output)

        #Check the reading turns up
        session = self.Session()
        qry = session.query(models.Node).filter_by(id=4242).first()
        self.assertTrue(qry)

        #NodeState
        qry = session.query(models.NodeState).filter_by(nodeId=4242)
        self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertTrue(qry)
        tdiff = qry.time - now
        self.assertLess(tdiff.seconds, 1.0)
        self.assertEqual(qry.parent, 101)

        #And Reading
        qry = session.query(models.Reading).filter_by(nodeId=4242)
        #As we just did temperature there should only be one reading
        self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertTrue(qry)
        self.assertEqual(qry.typeId, 0)
        self.assertEqual(qry.value, 22.5)
예제 #10
0
    def testRcv(self):
        """Test a single receive"""
        now = datetime.datetime.utcnow()

        #Create our bitmask
        bs = Bitset(size = Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_TEMPERATURE] = True

        #Then A packet
        packet = StateMsg(addr = 4242)
        packet.set_ctp_parent_id(101) #Parent Node Id
        packet.set_special(0xc7) #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5])

        self.testbif.receive(packet)
        output = self.blogger.mainloop()
        self.assertTrue(output)

        #Check the reading turns up
        session = self.Session()
        qry = session.query(models.Node).filter_by(id = 4242).first()
        self.assertTrue(qry)

        #NodeState
        qry = session.query(models.NodeState).filter_by(nodeId = 4242)
        self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertTrue(qry)
        tdiff = qry.time - now
        self.assertLess(tdiff.seconds, 1.0)
        self.assertEqual(qry.parent, 101)

        #And Reading
        qry = session.query(models.Reading).filter_by(nodeId = 4242)
        #As we just did temperature there should only be one reading
        self.assertEqual(qry.count(), 1)
        qry = qry.first()
        self.assertTrue(qry)
        self.assertEqual(qry.typeId, 0)
        self.assertEqual(qry.value, 22.5)
예제 #11
0
    def testFailOnSpecial(self):
        """Do We fail gracefully if Special is wrong"""
        bs = Bitset(size=Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_TEMPERATURE] = True

        #Then A packet
        packet = StateMsg(addr=4242)
        packet.set_ctp_parent_id(101)  #Parent Node Id
        #packet.set_special(0xc7) #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5])

        #The First thing is to see if the code passes nicely (ie no fail)
        #When run in the normal way
        self.testbif.receive(packet)
        output = self.blogger.mainloop()
        self.assertIsNone(output)  #Only when we store return True

        with self.assertRaises(Exception):
            self.blogger.store_state(packet)
예제 #12
0
    def testFailOnSpecial(self):
        """Do We fail gracefully if Special is wrong"""
        bs = Bitset(size=Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_TEMPERATURE] = True

        #Then A packet
        packet = StateMsg(addr = 4242)
        packet.set_ctp_parent_id(101) #Parent Node Id
        #packet.set_special(0xc7) #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5])

        #The First thing is to see if the code passes nicely (ie no fail)
        #When run in the normal way
        self.testbif.receive(packet)
        output = self.blogger.mainloop()
        self.assertIsNone(output) #Only when we store return True

        with self.assertRaises(Exception):
            self.blogger.store_state(packet)
예제 #13
0
    def testDuplicate(self):
        """What about duplicate packets"""
        now = datetime.datetime.utcnow()

        #Create our bitmask
        bs = Bitset(size=Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_TEMPERATURE] = True

        #Then A packet
        packet = StateMsg(addr=4242)
        packet.set_ctp_parent_id(101)  #Parent Node Id
        packet.set_special(0xc7)  #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5])

        self.testbif.receive(packet)
        self.testbif.receive(packet)  #Add it twice
        output = self.blogger.mainloop()
        self.assertTrue(output)
        output = self.blogger.mainloop()  #And a duplicate
        self.assertFalse(output)
예제 #14
0
    def testDuplicate(self):
        """What about duplicate packets"""
        now = datetime.datetime.utcnow()

        #Create our bitmask
        bs = Bitset(size=Packets.SC_SIZE)
        #Try to setup a temperature sample
        bs[Packets.SC_TEMPERATURE] = True

        #Then A packet
        packet = StateMsg(addr = 4242)
        packet.set_ctp_parent_id(101) #Parent Node Id
        packet.set_special(0xc7) #Special Id

        packet.set_packed_state_mask(bs.a)
        packet.set_packed_state([22.5])

        self.testbif.receive(packet)
        self.testbif.receive(packet) #Add it twice
        output = self.blogger.mainloop()
        self.assertTrue(output)
        output = self.blogger.mainloop() #And a duplicate
        self.assertFalse(output)