Exemplo n.º 1
0
 def test_rename_sensor_passes(self):
     # Arrange
     sensor_name = 'Start & finish'
     new_sensor_name = 'Bogus'
     # Act
     config = update.rename_sensor(self.config_file, self.config,
                                   sensor_name, new_sensor_name)
     # Assert
     self.assertEqual(self.config, config)
     # Cleanup
     update.rename_sensor(self.config_file, self.config, new_sensor_name,
                          sensor_name)
Exemplo n.º 2
0
 def test_rename_sensor_passes(self):
     # Arrange
     sensor_name = 'Start & finish'
     new_sensor_name = 'Bogus'
     # Act
     config = update.rename_sensor(self.config_file, self.config,
                                   sensor_name, new_sensor_name)
     # Assert
     self.assertEqual(self.config, config)
     # Cleanup
     update.rename_sensor(self.config_file, self.config,
                          new_sensor_name, sensor_name)
Exemplo n.º 3
0
 def test_rename_sensor_passes_when_new_sensor_name_matches_sensor_name(self):
     # Arrange
     sensor_name = 'Start & finish'
     new_sensor_name = 'Start & finish'
     # Act
     config = update.rename_sensor(self.config_file, self.config,
                                   sensor_name, new_sensor_name)
     # Assert
     self.assertEqual(self.config, config)
Exemplo n.º 4
0
 def test_rename_sensor_passes_when_new_sensor_name_matches_sensor_name(
         self):
     # Arrange
     sensor_name = 'Start & finish'
     new_sensor_name = 'Start & finish'
     # Act
     config = update.rename_sensor(self.config_file, self.config,
                                   sensor_name, new_sensor_name)
     # Assert
     self.assertEqual(self.config, config)
Exemplo n.º 5
0
 def test_rename_sensor_fails_when_sensor_name_doesnt_exist(self):
     # Arrange
     sensor_name = 'Bogus'
     new_sensor_name = 'Bogus 2'
     # Act
     with self.assertRaises(Exception) as context:
         config = update.rename_sensor(self.config_file, self.config,
                                       sensor_name, new_sensor_name)
     # Assert
     self.assertEqual(context.exception.message,
                      "Can't rename as existing sensor 'Bogus' not found in configuration")
Exemplo n.º 6
0
 def test_rename_sensor_fails_when_sensor_name_doesnt_exist(self):
     # Arrange
     sensor_name = 'Bogus'
     new_sensor_name = 'Bogus 2'
     # Act
     with self.assertRaises(Exception) as context:
         config = update.rename_sensor(self.config_file, self.config,
                                       sensor_name, new_sensor_name)
     # Assert
     self.assertEqual(
         context.exception.message,
         "Can't rename as existing sensor 'Bogus' not found in configuration"
     )
Exemplo n.º 7
0
 def test_rename_sensor_fails_when_new_sensor_name_already_exists(self):
     # Arrange
     sensor_name = 'Bogus'
     new_sensor_name = 'Bogus2'
     config_json = \
         '{' \
         '   "laptimer": {' \
         '       "url": "ws://127.0.0.1:8080/ws",' \
         '       "hardware": "RPI_REV1"' \
         '   },' \
         '   "sensors": [{' \
         '       "name": "Bogus",' \
         '       "url": "ws://127.0.0.1:8888/ws",' \
         '       "hardware": "RPI_REV2",' \
         '       "location": "START",' \
         '       "pinLedApp": 13' \
         '    },{' \
         '       "name": "Bogus2",' \
         '       "url": "ws://127.0.0.1:8889/ws",' \
         '       "hardware": "RPI_REV2",' \
         '       "location": "FINISH",' \
         '       "pinLedApp": 13' \
         '    }]' \
         '}'
     config_file = os.path.join(os.getcwd(),
                                'test_update_rename_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)
     # Act
     with self.assertRaises(Exception) as context:
         config = update.rename_sensor(config_file, config, sensor_name,
                                       new_sensor_name)
     # Assert
     self.assertEqual(
         context.exception.message,
         "Can't rename sensor '%s' as '%s' already found in "
         "configuration" % (sensor_name, new_sensor_name))
     # Cleanup
     if os.path.isfile(config_file):
         os.remove(config_file)
Exemplo n.º 8
0
 def test_rename_sensor_fails_when_new_sensor_name_already_exists(self):
     # Arrange
     sensor_name = 'Bogus'
     new_sensor_name = 'Bogus2'
     config_json = \
         '{' \
         '   "laptimer": {' \
         '       "url": "ws://127.0.0.1:8080/ws",' \
         '       "hardware": "RPI_REV1"' \
         '   },' \
         '   "sensors": [{' \
         '       "name": "Bogus",' \
         '       "url": "ws://127.0.0.1:8888/ws",' \
         '       "hardware": "RPI_REV2",' \
         '       "location": "START",' \
         '       "pinLedApp": 13' \
         '    },{' \
         '       "name": "Bogus2",' \
         '       "url": "ws://127.0.0.1:8889/ws",' \
         '       "hardware": "RPI_REV2",' \
         '       "location": "FINISH",' \
         '       "pinLedApp": 13' \
         '    }]' \
         '}'
     config_file = os.path.join(os.getcwd(), 'test_update_rename_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)
     # Act
     with self.assertRaises(Exception) as context:
         config = update.rename_sensor(config_file, config, sensor_name,
                                       new_sensor_name)
     # Assert
     self.assertEqual(context.exception.message,
                      "Can't rename sensor '%s' as '%s' already found in "
                      "configuration" % (sensor_name, new_sensor_name))
     # Cleanup
     if os.path.isfile(config_file):
         os.remove(config_file)
Exemplo n.º 9
0
 def rename_sensor(self, sensor_name, new_sensor_name):
     config = update.rename_sensor(self.config_file, self.config,
                                   sensor_name, new_sensor_name)
     if "sensors" in config:
         self.config = config
         self._publish("sensor_changed", config["sensors"])