Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* [ENHANCEMENT] CLI docs list command implemented for v3 api #2612

Merged
merged 1 commit into from
Mar 26, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog

Develop
-----------------
* [ENHANCEMENT] CLI `docs list` command implemented for v3 api


0.13.15
Expand Down
24 changes: 11 additions & 13 deletions great_expectations/cli/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,22 @@ def docs_build(ctx, site_name, view=True):
@docs.command(name="list")
@click.pass_context
def docs_list(ctx):
"""List known Data Docs Sites."""
display_not_implemented_message_and_exit()
"""List known Data Docs sites."""
context = ctx.obj.data_context

docs_sites_url_dicts = context.get_docs_sites_urls()
docs_sites_strings = [
" - <cyan>{}</cyan>: {}".format(
docs_site_dict["site_name"],
docs_site_dict.get("site_url")
or f"site configured but does not exist. Run the following command to build site: great_expectations "
f'docs build --site-name {docs_site_dict["site_name"]}',
)
for docs_site_dict in docs_sites_url_dicts
]

if len(docs_sites_strings) == 0:
if len(docs_sites_url_dicts) == 0:
cli_message("No Data Docs sites found")
else:
docs_sites_strings = [
" - <cyan>{}</cyan>: {}".format(
docs_site_dict["site_name"],
docs_site_dict.get("site_url")
or f"site configured but does not exist. Run the following command to build site: great_expectations "
f'docs build --site-name {docs_site_dict["site_name"]}',
)
for docs_site_dict in docs_sites_url_dicts
]
list_intro_string = _build_intro_string(docs_sites_strings)
cli_message_list(docs_sites_strings, list_intro_string)

Expand Down
62 changes: 62 additions & 0 deletions tests/cli/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,65 @@ def test_docs_build_assume_yes(
click_result=result,
allowed_deprecation_message=VALIDATION_OPERATORS_DEPRECATION_MESSAGE,
)


def test_docs_list_with_no_sites(
caplog, monkeypatch, titanic_data_context_no_data_docs
):
context = titanic_data_context_no_data_docs

runner = CliRunner(mix_stderr=True)
monkeypatch.chdir(os.path.dirname(context.root_directory))
result = runner.invoke(
cli,
"--v3-api docs list",
catch_exceptions=False,
)
stdout = result.stdout
assert result.exit_code == 0
assert "No Data Docs sites found" in stdout

assert_no_logging_messages_or_tracebacks(
my_caplog=caplog,
click_result=result,
allowed_deprecation_message=VALIDATION_OPERATORS_DEPRECATION_MESSAGE,
)


@mock.patch(
"great_expectations.core.usage_statistics.usage_statistics.UsageStatisticsHandler.emit"
)
def test_docs_list(
mock_emit, caplog, monkeypatch, titanic_data_context_stats_enabled_config_version_3
):
context = titanic_data_context_stats_enabled_config_version_3
runner = CliRunner(mix_stderr=True)
monkeypatch.chdir(os.path.dirname(context.root_directory))
result = runner.invoke(
cli,
"--v3-api docs list",
catch_exceptions=False,
)
stdout = result.stdout
assert result.exit_code == 0
assert "1 Data Docs site configured:" in stdout
assert "local_site" in stdout

assert mock_emit.call_count == 2
assert mock_emit.call_args_list == [
mock.call(
{"event_payload": {}, "event": "data_context.__init__", "success": True}
),
mock.call(
{
"event": "cli.docs.list",
"event_payload": {"api_version": "v3"},
"success": True,
}
),
]

assert_no_logging_messages_or_tracebacks(
my_caplog=caplog,
click_result=result,
)