mirror of
https://github.com/simonw/dclient.git
synced 2026-07-24 18:04:33 +02:00
Test -t auth token option
This commit is contained in:
parent
ef351373a1
commit
a424a0e27b
1 changed files with 16 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ from click.testing import CliRunner
|
|||
from dclient.cli import cli
|
||||
import json
|
||||
import pathlib
|
||||
import pytest
|
||||
|
||||
|
||||
def test_query_error(httpx_mock):
|
||||
|
|
@ -23,7 +24,8 @@ def test_query_error(httpx_mock):
|
|||
)
|
||||
|
||||
|
||||
def test_query(httpx_mock):
|
||||
@pytest.mark.parametrize("with_token", (False, True))
|
||||
def test_query(httpx_mock, with_token):
|
||||
httpx_mock.add_response(
|
||||
json={
|
||||
"ok": True,
|
||||
|
|
@ -40,10 +42,22 @@ def test_query(httpx_mock):
|
|||
status_code=200,
|
||||
)
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["query", "https://example.com", "hello"])
|
||||
args = ["query", "https://example.com", "hello"]
|
||||
if with_token:
|
||||
args.append("--token")
|
||||
args.append("xyz")
|
||||
result = runner.invoke(cli, args)
|
||||
assert result.exit_code == 0
|
||||
assert json.loads(result.output) == [{"5 * 2": 10}]
|
||||
|
||||
# Check the request
|
||||
request = httpx_mock.get_request()
|
||||
assert str(request.url) == "https://example.com.json?sql=hello&_shape=objects"
|
||||
if with_token:
|
||||
assert request.headers["authorization"] == "Bearer xyz"
|
||||
else:
|
||||
assert "authorization" not in request.headers
|
||||
|
||||
|
||||
def test_aliases(mocker, tmpdir, httpx_mock):
|
||||
mocker.patch("dclient.cli.get_config_dir", return_value=pathlib.Path(tmpdir))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue