async def patch_config(self, config_id: str, json: Json) -> AccessJson: async with self.session.patch(self.base_path + f"/config/{config_id}", json=json) as r: if r.status == 200: return AccessJson.wrap_object(await r.json()) else: raise AttributeError(await r.text())
async def search_graph_raw(self, graph: str, search: str) -> AccessJson: async with self.session.post(self.base_path + f"/graph/{graph}/search/raw", data=search) as r: if r.status == 200: return AccessJson.wrap_object(await r.json()) else: raise AttributeError(await r.text())
async def put_config(self, config_id: str, json: Json, validate: bool = True) -> AccessJson: params = {"validate": "true" if validate else "false"} async with self.session.put(self.base_path + f"/config/{config_id}", json=json, params=params) as r: if r.status == 200: return AccessJson.wrap_object(await r.json()) else: raise AttributeError(await r.text())
async def test_update_nodes(graph_db: ArangoGraphDB, foo_model: Model) -> None: def expect(jsons: List[Json], path: List[str], value: JsonElement) -> None: for js in jsons: v = value_in_path(js, path) assert v is not None assert v == value await graph_db.wipe() await graph_db.create_node(foo_model, "id1", to_json(Foo("id1", "foo")), "root") await graph_db.create_node(foo_model, "id2", to_json(Foo("id2", "foo")), "root") # only change the desired section change1 = {"desired": {"test": True}} result1 = [ a async for a in graph_db.update_nodes(foo_model, { "id1": change1, "id2": change1 }) ] assert len(result1) == 2 expect(result1, ["desired", "test"], True) # only change the metadata section change2 = {"metadata": {"test": True}} result2 = [ a async for a in graph_db.update_nodes(foo_model, { "id1": change2, "id2": change2 }) ] assert len(result2) == 2 expect(result2, ["metadata", "test"], True) # change all sections including the reported section change3 = { "desired": { "test": False }, "metadata": { "test": False }, "reported": { "name": "test" } } node_raw_id1 = AccessJson.wrap_object( graph_db.db.db.collection(graph_db.name).get("id1")) result3 = [ a async for a in graph_db.update_nodes(foo_model, { "id1": change3, "id2": change3 }) ] assert len(result3) == 2 expect(result3, ["desired", "test"], False) expect(result3, ["metadata", "test"], False) expect(result3, ["reported", "name"], "test") # make sure the db is updated node_raw_id1_updated = AccessJson.wrap_object( graph_db.db.db.collection(graph_db.name).get("id1")) assert node_raw_id1.reported.name != node_raw_id1_updated.reported.name assert node_raw_id1.desired.test != node_raw_id1_updated.desired.test assert node_raw_id1.metadata.test != node_raw_id1_updated.metadata.test assert node_raw_id1.flat != node_raw_id1_updated.flat assert node_raw_id1.hash != node_raw_id1_updated.hash assert "test" in node_raw_id1_updated.flat change4 = {"desired": None, "metadata": None} result4 = [ a async for a in graph_db.update_nodes(foo_model, { "id1": change4, "id2": change4 }) ] assert len(result4) == 2 assert "desired" not in result4 assert "metadata" not in result4
async def test_system_info_command(cli: CLI) -> None: info = AccessJson.wrap_object( (await cli.execute_cli_command("system info", stream.list))[0][0]) assert info.version == version() assert info.name == "resotocore" assert info.cpus > 0
async def cli_info(self) -> AccessJson: async with self.session.get(self.base_path + f"/cli/info") as r: if r.status == 200: return AccessJson.wrap_object(await r.json()) else: raise AttributeError(await r.text())