test withconfig parameter removal

This commit is contained in:
avollkopf 2023-04-06 12:40:49 +02:00
parent 5e2dc35b30
commit dc36cc1ed3
4 changed files with 46 additions and 3 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.1.8.a5"
__version__ = "4.1.8.a6"
__codename__ = "Groundhog Day"

View file

@ -17,6 +17,9 @@ class CBPiBase(metaclass=ABCMeta):
async def set_config_value(self,name,value):
return await self.cbpi.config.set(name,value)
async def remove_config_parameter(self,name):
return await self.cbpi.config.remove(name)
async def add_config_value(self, name, value, type: ConfigType, description, source, options=None):
await self.cbpi.config.add(name, value, type, description, source,options=None)

View file

@ -50,10 +50,27 @@ class ConfigController:
with open(self.path, "w") as file:
json.dump(data, file, indent=4, sort_keys=True)
async def add(self, name, value, type: ConfigType, description, source="", options=None):
async def add(self, name, value, type: ConfigType, description, source="craftbeerpi", options=None):
self.cache[name] = Config(name,value,description,type,source,options)
data = {}
for key, value in self.cache.items():
data[key] = value.to_dict()
with open(self.path, "w") as file:
json.dump(data, file, indent=4, sort_keys=True)
async def remove(self, name):
data = {}
self.testcache={}
for key, value in self.cache.items():
try:
if key != name:
data[key] = value.to_dict()
self.testcache[key] = Config(name=data[key].get("name"), value=data[key].get("value"), description=data[key].get("description"),
type=ConfigType(data[key].get("type", "string")), options=data[key].get("options", None),
source=data[key].get("source", "craftbeerpi") )
except Exception as e:
print(e)
with open(self.path, "w") as file:
json.dump(data, file, indent=4, sort_keys=True)
self.cache=self.testcache

View file

@ -78,5 +78,28 @@ class ConfigHttpEndpoints:
name = request.match_info['name']
# if name not in self.cache:
# raise CBPiException("Parameter %s not found" % name)
data = self.controller.get(name)
# data = self.controller.get(name)
return web.json_response(self.controller.get(name), dumps=json_dumps)
@request_mapping(path="/remove/{name}/", method="PUT", auth_required=False)
async def http_remove(self, request) -> web.Response:
"""
---
description: Remove config parameter
tags:
- Config
parameters:
- name: "name"
in: "path"
description: "Parameter name"
required: true
type: "string"
responses:
"200":
description: successful operation
"""
name = request.match_info['name']
await self.controller.remove(name=name)
return web.Response(status=200)