示例#1
0
    def test_model_not_exists(self):
        # set up
        class ThermometerDevice(AbstractDevice):
            @Sensor
            def room(self):
                return 25

        # test
        with self.mysql.dao.SessionContext():
            result = sensors.get('thermometer.room')
        self.assertEqual('thermometer.room', result['name'])
        self.assertEqual(0, result['error_rate'])
        self.assertEqual(60, result['interval'])
        self.assertEqual(datetime(1970, 1, 1), result['time'])
        self.assertIsNone(result['value'])
示例#2
0
 def test_model_not_exists(self):
     # set up
     class ThermometerDevice(AbstractDevice):
         @Sensor
         def room(self):
             return 25
         
     # test
     with self.mysql.dao.SessionContext():
         result = sensors.get('thermometer.room')
     self.assertEqual('thermometer.room', result['name'])
     self.assertEqual(0, result['error_rate'])
     self.assertEqual(60, result['interval'])
     self.assertEqual(datetime(1970, 1, 1), result['time'])
     self.assertIsNone(result['value'])
示例#3
0
 def test_success(self):
     # set up
     class ThermometerDevice(AbstractDevice):
         @Sensor
         def room(self):
             return 25
     with self.mysql.dao.create_session() as session:
         sensor = SensorModel(name='thermometer.room',
                 error_rate=0.01,
                 value=json.dumps(25),
                 time=datetime(2000, 1, 1))
         session.add(sensor)
         
     # test
     with self.mysql.dao.SessionContext():
         result = sensors.get('thermometer.room')
     self.assertEqual('thermometer.room', result['name'])
     self.assertEqual(0.01, result['error_rate'])
     self.assertEqual(60, result['interval'])
     self.assertEqual(datetime(2000, 1, 1), result['time'])
     self.assertEqual(25, result['value'])
示例#4
0
    def test_success(self):
        # set up
        class ThermometerDevice(AbstractDevice):
            @Sensor
            def room(self):
                return 25

        with self.mysql.dao.create_session() as session:
            sensor = SensorModel(name='thermometer.room',
                                 error_rate=0.01,
                                 value=json.dumps(25),
                                 time=datetime(2000, 1, 1))
            session.add(sensor)

        # test
        with self.mysql.dao.SessionContext():
            result = sensors.get('thermometer.room')
        self.assertEqual('thermometer.room', result['name'])
        self.assertEqual(0.01, result['error_rate'])
        self.assertEqual(60, result['interval'])
        self.assertEqual(datetime(2000, 1, 1), result['time'])
        self.assertEqual(25, result['value'])