mirror of
https://github.com/simonw/dclient.git
synced 2026-09-10 18:44:20 +02:00
Initial dclient query command, refs #1
This commit is contained in:
parent
56c4672f37
commit
1ecb6a02e8
5 changed files with 94 additions and 27 deletions
|
|
@ -1,10 +0,0 @@
|
|||
from click.testing import CliRunner
|
||||
from dclient.cli import cli
|
||||
|
||||
|
||||
def test_version():
|
||||
runner = CliRunner()
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(cli, ["--version"])
|
||||
assert result.exit_code == 0
|
||||
assert result.output.startswith("cli, version ")
|
||||
41
tests/test_query.py
Normal file
41
tests/test_query.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
from click.testing import CliRunner
|
||||
from dclient.cli import cli
|
||||
import json
|
||||
|
||||
|
||||
def test_query_error(httpx_mock):
|
||||
httpx_mock.add_response(
|
||||
json={
|
||||
"ok": False,
|
||||
"error": "Statement must be a SELECT",
|
||||
"status": 400,
|
||||
"title": "Invalid SQL",
|
||||
},
|
||||
status_code=400,
|
||||
)
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["query", "https://example.com", "hello"])
|
||||
assert result.exit_code == 1
|
||||
assert result.output == "Error: Invalid SQL: Statement must be a SELECT\n"
|
||||
|
||||
|
||||
def test_query(httpx_mock):
|
||||
httpx_mock.add_response(
|
||||
json={
|
||||
"ok": True,
|
||||
"database": "fixtures",
|
||||
"query_name": None,
|
||||
"rows": [{"5 * 2": 10}],
|
||||
"truncated": False,
|
||||
"columns": ["5 * 2"],
|
||||
"query": {"sql": "select 5 * 2", "params": {}},
|
||||
"error": None,
|
||||
"private": False,
|
||||
"allow_execute_sql": True,
|
||||
},
|
||||
status_code=200,
|
||||
)
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["query", "https://example.com", "hello"])
|
||||
assert result.exit_code == 0
|
||||
assert json.loads(result.output) == [{"5 * 2": 10}]
|
||||
Loading…
Add table
Add a link
Reference in a new issue