Esempio n. 1
0
 def test_add_sensor_adds_new_sensor_section(self):
     # Arrange
     config_json = \
         '{' \
         '   "laptimer": {' \
         '       "url": "ws://127.0.0.1:8080/ws",' \
         '       "hardware": "RPI_REV2"' \
         '   },' \
         '   "sensors": []' \
         '}'
     config_file = os.path.join(os.getcwd(), 'test_update_add_sensor.json')
     if os.path.isfile(config_file):
         os.remove(config_file)
     with open(config_file, 'w') as cfg:
         cfg.write(config_json)
     config = json.loads(config_json)
     sensor = json.loads('{'
                         '    "name": "Bogus",'
                         '    "url": "ws://127.0.0.1:88/ws",'
                         '    "hardware": "RPI_REV1",'
                         '    "location": "START_FINISH",'
                         '    "pinLedApp": 13'
                         '}')
     # Act
     config = update.add_sensor(config_file, config, sensor)
     # Assert
     self.assertEqual(config['sensors'][0], sensor)
     # Cleanup
     if os.path.isfile(config_file):
         os.remove(config_file)
Esempio n. 2
0
 def test_add_sensor_adds_new_sensor_section(self):
     # Arrange
     config_json = \
         '{' \
         '   "laptimer": {' \
         '       "url": "ws://127.0.0.1:8080/ws",' \
         '       "hardware": "RPI_REV2"' \
         '   },' \
         '   "sensors": []' \
         '}'
     config_file = os.path.join(os.getcwd(), 'test_update_add_sensor.json')
     if os.path.isfile(config_file):
         os.remove(config_file)
     with open(config_file, 'w') as cfg:
         cfg.write(config_json)
     config = json.loads(config_json)
     sensor = json.loads(
         '{'
         '    "name": "Bogus",'
         '    "url": "ws://127.0.0.1:88/ws",'
         '    "hardware": "RPI_REV1",'
         '    "location": "START_FINISH",'
         '    "pinLedApp": 13'
         '}')
     # Act
     config = update.add_sensor(config_file, config, sensor)
     # Assert
     self.assertEqual(config['sensors'][0], sensor)
     # Cleanup
     if os.path.isfile(config_file):
         os.remove(config_file)
Esempio n. 3
0
 def test_add_sensor_fails_when_sensor_name_already_exists(self):
     # Arrange
     sensor = json.loads('{"name": "Start & finish"}')
     # Act
     with self.assertRaises(Exception) as context:
         config = update.add_sensor(self.config_file, self.config, sensor)
     # Assert
     self.assertEqual(context.exception.message,
                      "Sensor 'Start & finish' already found in configuration")
Esempio n. 4
0
 def test_add_sensor_fails_when_sensor_name_already_exists(self):
     # Arrange
     sensor = json.loads('{"name": "Start & finish"}')
     # Act
     with self.assertRaises(Exception) as context:
         config = update.add_sensor(self.config_file, self.config, sensor)
     # Assert
     self.assertEqual(
         context.exception.message,
         "Sensor 'Start & finish' already found in configuration")
Esempio n. 5
0
 def add_sensor(self, sensor):
     config = update.add_sensor(self.config_file, self.config,
                                sensor)
     if "sensors" in config:
         self.config = config
         self._publish("sensor_changed", config["sensors"])