def test_check_laptimer_raises_exception_when_not_dictionary(self): # Arrange laptimer = json.loads('{"bogus": "data"}') # Act with self.assertRaises(Exception) as context: check.check_laptimer(laptimer) # Assert self.assertEqual(context.exception.message, "Unknown attribute 'bogus' in laptimer configuration")
def test_check_laptimer_raises_exception_when_not_dictionary(self): # Arrange laptimer = json.loads('{"bogus": "data"}') # Act with self.assertRaises(Exception) as context: check.check_laptimer(laptimer) # Assert self.assertEqual( context.exception.message, "Unknown attribute 'bogus' in laptimer configuration")
def test_check_laptimer_raises_exception_when_attribute_is_invalid(self): # Arrange laptimer_item = json.loads('{"laptimer": [{"bogus": "data"}]}') laptimer = laptimer_item['laptimer'] # Act with self.assertRaises(Exception) as context: check.check_laptimer(laptimer) # Assert self.assertEqual(context.exception.message, "Unknown attribute '{u'bogus': u'data'}' in laptimer " "configuration")
def test_check_laptimer_raises_exception_when_attribute_is_invalid(self): # Arrange laptimer_item = json.loads('{"laptimer": [{"bogus": "data"}]}') laptimer = laptimer_item['laptimer'] # Act with self.assertRaises(Exception) as context: check.check_laptimer(laptimer) # Assert self.assertEqual( context.exception.message, "Unknown attribute '{u'bogus': u'data'}' in laptimer " "configuration")
def update_laptimer(config_file, config, laptimer): """ Updates the laptimer section of specified config_file after checking to ensure configuration is valid. :param config_file: Name of configuration file to update. :type config_file: str :param config: Complete current configuration. :type config: dict :param laptimer: Laptimer configuration to be updated. :type config_file: dict :returns: Complete configuration contents after being updated. :rtype: dict """ # Merges existing content, preferring new laptimer config for duplicates # TODO: Handle case when items are removed rather than updated or added. config['laptimer'].update(laptimer) check.check_laptimer(config['laptimer']) _update_config(config_file, config) log.msg('Updated laptimer configuration') return config
def test_check_laptimer_passes_when_attributes_are_valid(self): # Arrange laptimer = json.loads('{"url": "ws://127.0.0.1:8080/ws"}') # Act & Assert check.check_laptimer(laptimer)