コード例 #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)
コード例 #2
0
ファイル: test_update.py プロジェクト: si618/pi-time
 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)
コード例 #3
0
ファイル: test_update.py プロジェクト: si618/pi-time
 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)
コード例 #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)
コード例 #5
0
ファイル: test_update.py プロジェクト: si618/pi-time
 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")
コード例 #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"
     )
コード例 #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)
コード例 #8
0
ファイル: test_update.py プロジェクト: si618/pi-time
 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)
コード例 #9
0
ファイル: api.py プロジェクト: movermeyer/pi-time
 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"])