datasette/tests/test_inspect.py
Simon Willison c0d1b4c322 "datasette inspect foo.db" now just calculates table counts
Refs #462

* inspect command now just outputs table counts
* test_inspect.py is now only tests for that CLI command
* Updated some relevant documentation
* Removed docs for /-/inspect since that is about to change
2019-05-11 14:36:57 -07:00

28 lines
964 B
Python

from .fixtures import app_client
from datasette.cli import cli
from click.testing import CliRunner
import json
def test_inspect_cli(app_client):
runner = CliRunner()
result = runner.invoke(cli, ["inspect", "fixtures.db"])
data = json.loads(result.output)
assert ["fixtures"] == list(data.keys())
database = data["fixtures"]
assert "fixtures.db" == database["file"]
assert isinstance(database["hash"], str)
assert 64 == len(database["hash"])
for table_name, expected_count in {
"Table With Space In Name": 0,
"facetable": 15
}.items():
assert expected_count == database["tables"][table_name]["count"]
def test_inspect_cli_writes_to_file(app_client):
runner = CliRunner()
result = runner.invoke(cli, ["inspect", "fixtures.db", "--inspect-file", "foo.json"])
assert 0 == result.exit_code, result.output
data = json.load(open("foo.json"))
assert ["fixtures"] == list(data.keys())