def test_simple_checkpoint_defaults_run_and_basic_run_params_with_persisted_checkpoint_loaded_from_store( context_with_data_source_and_empty_suite, simple_checkpoint_defaults, webhook, one_validation, ): context: DataContext = context_with_data_source_and_empty_suite checkpoint_config = SimpleCheckpointConfigurator( "foo", context_with_data_source_and_empty_suite, slack_webhook=webhook).build() context.add_checkpoint(**checkpoint_config.to_json_dict()) checkpoint_name = checkpoint_config.name assert context.list_checkpoints() == [checkpoint_name] del checkpoint_config checkpoint = context.get_checkpoint(checkpoint_name) assert isinstance(checkpoint, Checkpoint) result = checkpoint.run( run_name="bar", validations=[one_validation], ) assert isinstance(result, CheckpointResult) assert result.run_id.run_name == "bar" assert result.list_expectation_suite_names() == ["one"] assert len(result.list_validation_results()) == 1 assert result.success
def test_simple_checkpoint_persisted_to_store( context_with_data_source_and_empty_suite, webhook, one_validation): assert context_with_data_source_and_empty_suite.list_checkpoints() == [] initial_checkpoint_config = SimpleCheckpointConfigurator( "foo", context_with_data_source_and_empty_suite, site_names=None, ).build() # TODO this add_checkpoint will be user facing and it could be more # ergonomic by accepting a Checkpoint maybe .add_checkpoint() should take a # Checkpoint and there should be a .create_checkpoint() that accepts all # the current parameters context_with_data_source_and_empty_suite.add_checkpoint( **initial_checkpoint_config.to_json_dict()) assert context_with_data_source_and_empty_suite.list_checkpoints() == [ "foo" ] checkpoint = context_with_data_source_and_empty_suite.get_checkpoint("foo") assert isinstance(checkpoint, Checkpoint) assert isinstance(checkpoint.config, CheckpointConfig) assert checkpoint.config.to_json_dict() == { "action_list": [ { "action": { "class_name": "StoreValidationResultAction" }, "name": "store_validation_result", }, { "action": { "class_name": "StoreEvaluationParametersAction" }, "name": "store_evaluation_params", }, ], "batch_request": None, "class_name": "Checkpoint", "config_version": 1.0, "evaluation_parameters": {}, "expectation_suite_name": None, "ge_cloud_id": None, "module_name": "great_expectations.checkpoint", "name": "foo", "profilers": [], "run_name_template": None, "runtime_configuration": {}, "template_name": None, "validations": [], } results = checkpoint.run(validations=[one_validation]) assert results.success
def test_simple_checkpoint_raises_errors_on_invalid_site_name_types( empty_data_context, ): for junk_input in [[1, "local"], 1, ["local", None]]: with pytest.raises(TypeError): SimpleCheckpointConfigurator("foo", empty_data_context, site_names=junk_input).build()
def test_simple_checkpoint_has_slack_action_with_notify_adjustments_slack_webhook_is_present( empty_data_context, store_validation_result_action, store_eval_parameter_action, update_data_docs_action, slack_notification_action, webhook, ): checkpoint_config = SimpleCheckpointConfigurator( "foo", empty_data_context, slack_webhook=webhook, notify_on="failure", notify_with=["local_site", "s3_prod"], ).build() slack_notification_action["action"]["notify_on"] = "failure" slack_notification_action["action"]["notify_with"] = [ "local_site", "s3_prod" ] expected = [ store_validation_result_action, store_eval_parameter_action, update_data_docs_action, slack_notification_action, ] assert checkpoint_config.action_list == expected
def test_simple_checkpoint_raises_error_on_invalid_notify_with( empty_data_context, ): for bad in [1, "bar", ["local_site", 3]]: with pytest.raises(ValueError): SimpleCheckpointConfigurator("foo", empty_data_context, notify_with=bad).build()
def test_simple_checkpoint_raises_error_on_missing_slack_webhook_when_notify_on_is_not_default( empty_data_context, slack_notification_action, webhook): for condition in ["faliure", "success"]: with pytest.raises(ValueError): SimpleCheckpointConfigurator("foo", empty_data_context, notify_on=condition).build()
def test_simple_checkpoint_raises_errors_on_site_name_that_does_not_exist_on_data_context( empty_data_context, ): # assert the fixture is adequate assert "prod" not in empty_data_context.get_site_names() with pytest.raises(TypeError): SimpleCheckpointConfigurator("foo", empty_data_context, site_names=["prod"]).build()
def test_simple_checkpoint_has_no_slack_action_when_no_slack_webhook_is_present( empty_data_context, store_validation_result_action, store_eval_parameter_action, update_data_docs_action, ): checkpoint_config = SimpleCheckpointConfigurator( "foo", empty_data_context).build() assert checkpoint_config.action_list == [ store_validation_result_action, store_eval_parameter_action, update_data_docs_action, ]
def test_simple_checkpoint_has_no_update_data_docs_action_when_site_names_is_none( empty_data_context, store_validation_result_action, store_eval_parameter_action, update_data_docs_action, ): # assert the fixture is adequate assert "local_site" in empty_data_context.get_site_names() checkpoint_config = SimpleCheckpointConfigurator("foo", empty_data_context, site_names=None).build() assert checkpoint_config.action_list == [ store_validation_result_action, store_eval_parameter_action, ]
def test_simple_checkpoint_has_update_data_docs_action_that_should_update_all_sites_when_site_names_is_all( empty_data_context, store_validation_result_action, store_eval_parameter_action, update_data_docs_action, ): checkpoint_config = SimpleCheckpointConfigurator("foo", empty_data_context, site_names="all").build() # This is confusing: the UpdateDataDocsAction default behavior is to update # all sites if site_names=None update_data_docs_action["action"]["site_names"] = [] assert checkpoint_config.action_list == [ store_validation_result_action, store_eval_parameter_action, update_data_docs_action, ]
def test_simple_checkpoint_default_properties_with_no_optional_arguments( empty_data_context, store_validation_result_action, store_eval_parameter_action, update_data_docs_action, titanic_pandas_data_context_with_v013_datasource_stats_enabled_with_checkpoints_v1_with_templates, ): """This demonstrates the simplest possible usage.""" checkpoint_config = SimpleCheckpointConfigurator( "my_minimal_simple_checkpoint", empty_data_context).build() assert isinstance(checkpoint_config, CheckpointConfig) assert checkpoint_config.name == "my_minimal_simple_checkpoint" assert checkpoint_config.action_list == [ store_validation_result_action, store_eval_parameter_action, update_data_docs_action, ] assert checkpoint_config.config_version == 1.0 assert checkpoint_config.class_name == "Checkpoint" assert checkpoint_config.evaluation_parameters == {} assert checkpoint_config.runtime_configuration == {} assert checkpoint_config.validations == [] checkpoint_from_store = titanic_pandas_data_context_with_v013_datasource_stats_enabled_with_checkpoints_v1_with_templates.get_checkpoint( "my_minimal_simple_checkpoint") checkpoint_config = checkpoint_from_store.config assert checkpoint_config.name == "my_minimal_simple_checkpoint" assert checkpoint_config.action_list == [ store_validation_result_action, store_eval_parameter_action, update_data_docs_action, ] assert checkpoint_config.config_version == 1.0 assert checkpoint_config.class_name == "Checkpoint" assert checkpoint_config.evaluation_parameters == {} assert checkpoint_config.runtime_configuration == {} assert checkpoint_config.validations == []
def test_simple_checkpoint_has_update_data_docs_action_that_should_update_selected_sites_when_sites_are_selected( empty_data_context, store_validation_result_action, store_eval_parameter_action, update_data_docs_action, titanic_pandas_data_context_with_v013_datasource_stats_enabled_with_checkpoints_v1_with_templates, ): # assert the fixture is adequate assert "local_site" in empty_data_context.get_site_names() checkpoint_config = SimpleCheckpointConfigurator("foo", empty_data_context, site_names=["local_site" ]).build() # This is confusing: the UpdateDataDocsAction default behavior is to update # all sites if site_names=None update_data_docs_action["action"]["site_names"] = ["local_site"] assert checkpoint_config.action_list == [ store_validation_result_action, store_eval_parameter_action, update_data_docs_action, ] # assert the fixture is adequate assert ( "local_site" in titanic_pandas_data_context_with_v013_datasource_stats_enabled_with_checkpoints_v1_with_templates .get_site_names()) checkpoint_from_store = titanic_pandas_data_context_with_v013_datasource_stats_enabled_with_checkpoints_v1_with_templates.get_checkpoint( "my_simple_checkpoint_with_site_names") checkpoint_config = checkpoint_from_store.config assert checkpoint_config.action_list == [ store_validation_result_action, store_eval_parameter_action, update_data_docs_action, ]
def test_simple_checkpoint_has_slack_action_with_defaults_when_slack_webhook_is_present( empty_data_context, store_validation_result_action, store_eval_parameter_action, update_data_docs_action, slack_notification_action, webhook, titanic_pandas_data_context_with_v013_datasource_stats_enabled_with_checkpoints_v1_with_templates, ): checkpoint_config = SimpleCheckpointConfigurator( "foo", empty_data_context, slack_webhook=webhook).build() expected = [ store_validation_result_action, store_eval_parameter_action, update_data_docs_action, slack_notification_action, ] assert checkpoint_config.action_list == expected checkpoint_from_store = titanic_pandas_data_context_with_v013_datasource_stats_enabled_with_checkpoints_v1_with_templates.get_checkpoint( "my_simple_checkpoint_with_slack") checkpoint_config = checkpoint_from_store.config assert checkpoint_config.name == "my_simple_checkpoint_with_slack" assert checkpoint_config.action_list == expected
def test_simple_checkpoint_notify_with_all_has_data_docs_action_with_none_specified( empty_data_context, slack_notification_action, webhook, titanic_pandas_data_context_with_v013_datasource_stats_enabled_with_checkpoints_v1_with_templates, ): """ The underlying SlackNotificationAction and SlackRenderer default to including links to all sites if the key notify_with is not present. We are intentionally hiding this from users of SimpleCheckpoint by having a default of "all" that sets the configuration appropriately. """ checkpoint_config = SimpleCheckpointConfigurator( "foo", empty_data_context, slack_webhook=webhook, notify_with="all").build() # set the config to include all sites slack_notification_action["action"]["notify_with"] = None assert slack_notification_action in checkpoint_config.action_list checkpoint_from_store = titanic_pandas_data_context_with_v013_datasource_stats_enabled_with_checkpoints_v1_with_templates.get_checkpoint( "my_simple_checkpoint_with_slack_and_notify_with_all") checkpoint_config = checkpoint_from_store.config assert slack_notification_action in checkpoint_config.action_list
def test_simple_checkpoint_raises_error_on_invalid_slack_webhook( empty_data_context, ): with pytest.raises(ValueError): SimpleCheckpointConfigurator("foo", empty_data_context, slack_webhook="bad").build()
def simple_checkpoint_defaults(context_with_data_source_and_empty_suite): return Checkpoint( data_context=context_with_data_source_and_empty_suite, **SimpleCheckpointConfigurator( "foo", context_with_data_source_and_empty_suite).build().to_json_dict())
def test_simple_checkpoint_raises_error_on_missing_slack_webhook_when_notify_on_is_list( empty_data_context, slack_notification_action, webhook): with pytest.raises(ValueError): SimpleCheckpointConfigurator("foo", empty_data_context, notify_with=["prod", "dev"]).build()