def test_greeting ( self ): config = Config () config.addString ( "", "test" ) config.setValue ( "test", "value" ) config.addBoolean ( "", "test_bool") config.setValue ( "test_bool", True ) config.addInteger ( "", "test_int") config.setValue ( "test_int", 9 ) config.addInteger ( "", "test_unsigned_int") config.setValue ( "test_unsigned_int", -9 ) config.addFloat ( "", "test_float") config.setValue ( "test_float", 82.1002 ) self.assert_ ( config.value ( "test" )[0] == "value" ) self.assert_ ( config.value ( "test" )[1] == True ) self.assert_ ( config.value ( "test_bool" )[0] == True ) self.assert_ ( config.value ( "loose" )[1] == False ) self.assert_ ( config.value ( "test_int" )[0] == 9 ) self.assert_ ( config.value ( "test_unsigned_int" )[0] == -9 ) self.assert_ ( fabs( config.value ( "test_float" )[0] - 82.1002) < 0.00001 ) config.setValue( "test_bool", False ) config.writeFile ( "test.conf" ) self.assert_ ( os.path.exists ( "./test.conf" ) == True ) config.readFile ( "test.conf" ) self.assert_ ( config.value ( "test" )[0] == "value" ) self.assert_ ( config.value ( "test" )[1] == True ) os.remove ( "./test.conf" )
def test_greeting(self): config = Config() config.addString("", "test") config.setValue("test", "value") config.addBoolean("", "test_bool") config.setValue("test_bool", True) config.addInteger("", "test_int") config.setValue("test_int", 9) config.addInteger("", "test_unsigned_int") config.setValue("test_unsigned_int", -9) config.addFloat("", "test_float") config.setValue("test_float", 82.1002) self.assert_(config.value("test")[0] == "value") self.assert_(config.value("test")[1] == True) self.assert_(config.value("test_bool")[0] == True) self.assert_(config.value("loose")[1] == False) self.assert_(config.value("test_int")[0] == 9) self.assert_(config.value("test_unsigned_int")[0] == -9) self.assert_(fabs(config.value("test_float")[0] - 82.1002) < 0.00001) config.setValue("test_bool", False) config.writeFile("test.conf") self.assert_(os.path.exists("./test.conf") == True) config.readFile("test.conf") self.assert_(config.value("test")[0] == "value") self.assert_(config.value("test")[1] == True) os.remove("./test.conf")
def PUT(self): # Enable/disable geolocation scanning # 0: disable geolocation scanning # others: enable geolocation scanning result = { 'SDCERR': weblcm_def.WEBLCM_ERRORS.get('SDCERR_FAIL'), 'InfoMsg': "AWM's geolocation scanning configuration only supported in LITE mode", 'geolocation_scanning_enable': 1, } # determine if in LITE mode litemode = False try: file = open("/etc/default/adaptive_ww", "r") for line in file: if re.search('LITE', line): litemode = True break except Exception as e: pass if not litemode: return result #prep for next error condition result['InfoMsg'] = 'No writable configuration file found' # check if there is a configuration file which contains a "scan_attempts:0" entry # if writable configuration file does not exist, scan_attempts can not be modified fp = cherrypy.request.app.config['weblcm'].get('awm_cfg', None) if not fp: return result d = Path(os.path.dirname(fp)) d.mkdir(exist_ok=True) geolocation_scanning_enable = cherrypy.request.json.get( 'geolocation_scanning_enable', 0) config = Config() with AWMCfgManage._lock: if os.path.isfile(fp): config.readFile(fp) if geolocation_scanning_enable: if config.exists("scan_attempts"): config.remove("", "scan_attempts") config.writeFile(fp) else: if not config.exists("scan_attempts"): config.addInteger("", "scan_attempts") config.setValue("scan_attempts", geolocation_scanning_enable) config.writeFile(fp) result['geolocation_scanning_enable'] = geolocation_scanning_enable result['SDCERR'] = weblcm_def.WEBLCM_ERRORS.get('SDCERR_SUCCESS') result['InfoMsg'] = '' return result