feat: add NocoBase project record writes

This commit is contained in:
nac
2026-07-13 01:36:20 +00:00
parent 7ab9f57500
commit e213a91fea
2 changed files with 74 additions and 0 deletions
+46
View File
@@ -86,6 +86,52 @@ class NbClientTests(unittest.TestCase):
self.assertIn("--orders", commands[1])
self.assertIn("--timezone", commands[1])
def test_create_record_uses_values_and_whitelist(self) -> None:
commands: list[list[str]] = []
def runner(cmd, **kwargs):
commands.append(cmd)
return subprocess.CompletedProcess(cmd, 0, stdout='{"data":{"id":7}}', stderr="")
client = NbClient(env_name="nb-mcp", runner=runner)
client.create_record("t_projects", {"f_project_name": "EV inverter"}, ["f_project_name"])
self.assertEqual(commands[0][:4], ["nb", "api", "resource", "create"])
self.assertEqual(
json.loads(commands[0][commands[0].index("--values") + 1]),
{"f_project_name": "EV inverter"},
)
self.assertEqual(commands[0][commands[0].index("--whitelist") + 1], "f_project_name")
def test_update_record_uses_filter_by_tk(self) -> None:
commands: list[list[str]] = []
def runner(cmd, **kwargs):
commands.append(cmd)
return subprocess.CompletedProcess(cmd, 0, stdout='{"data":{"id":7}}', stderr="")
client = NbClient(env_name="nb-mcp", runner=runner)
client.update_record("t_projects", 7, {"client_ID": 3}, ["client_ID"])
self.assertEqual(commands[0][:4], ["nb", "api", "resource", "update"])
self.assertEqual(commands[0][commands[0].index("--filter-by-tk") + 1], "7")
def test_record_writes_reject_empty_values_without_running_command(self) -> None:
commands: list[list[str]] = []
def runner(cmd, **kwargs):
commands.append(cmd)
return subprocess.CompletedProcess(cmd, 0, stdout='{"data":{}}', stderr="")
client = NbClient(env_name="nb-mcp", runner=runner)
with self.assertRaises(ValueError):
client.create_record("t_projects", {}, ["f_project_name"])
with self.assertRaises(ValueError):
client.update_record("t_projects", 7, {}, ["f_project_name"])
self.assertEqual(commands, [])
def test_list_collection_fields_uses_data_modeling_command(self) -> None:
commands: list[list[str]] = []