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'])
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'])