def test_update_sensor_raises_exception_when_sensor_is_invalid(self): # Arrange sensor = json.loads('{"bogus": "bogus"}') # Act with self.assertRaises(Exception) as context: update.update_sensor(self.config_file, self.config, sensor) # Assert expected = 'Missing sensor name' self.assertEqual(context.exception.message, expected)
def test_update_sensor_merges_existing_section(self): # Arrange sensor = json.loads('{"name": "Start & finish", "hardware": ' '"RPI_REV1"}') # Act config = update.update_sensor(self.config_file, self.config, sensor) # Assert self.assertEqual(config['sensors'][0]['hardware'], 'RPI_REV1')
def update_sensor(self, sensor): config = update.update_sensor(self.config_file, self.config, sensor) if "sensors" in config: self.config = config self._publish("sensor_changed", config["sensors"])