Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/entropy_data_cli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ def post_action(self, path: str, resource_id: str, action: str) -> str | None:
_raise_for_status(response)
return response.headers.get(RESPONSE_HEADER_LOCATION_HTML)

def post_action_json(self, path: str, resource_id: str, action: str, params: dict | None = None,
timeout: int = REQUEST_TIMEOUT) -> dict:
"""POST /api/{path}/{id}/{action} with query params. Returns response JSON."""
_validate_resource_id(resource_id)
response = self.session.post(
f"{self.base_url}/api/{path}/{resource_id}/{action}", params=params, timeout=timeout,
)
_raise_for_status(response)
return response.json()

def post_resource(self, path: str, body: dict, params: dict | None = None) -> str | None:
"""POST /api/{path}. Returns location-html URL if present."""
response = self.session.post(f"{self.base_url}/api/{path}", json=body, params=params, timeout=REQUEST_TIMEOUT)
Expand Down
22 changes: 22 additions & 0 deletions src/entropy_data_cli/commands/datacontracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ def put_datacontract(
handle_error(e)


@datacontracts_app.command("test")
def test_datacontract(
id: Annotated[str, typer.Argument(help="Data contract ID.")],
server: Annotated[Optional[str], typer.Option("--server", "-s", help="Server name to test against.")] = None,
) -> None:
"""Run a data contract test."""
import json

from entropy_data_cli.cli import get_client, handle_error

try:
client = get_client()
params = {}
if server:
params["server"] = server
# Data contract tests can take a long time (up to 30 minutes)
data = client.post_action_json(RESOURCE_PATH, id, "test", params=params, timeout=1800)
print(json.dumps(data, indent=2))
except Exception as e:
handle_error(e)


@datacontracts_app.command("delete")
def delete_datacontract(
id: Annotated[str, typer.Argument(help="Data contract ID.")],
Expand Down
Loading