Skip to content

Commit

Permalink
Merge a9960de into 1999da0
Browse files Browse the repository at this point in the history
  • Loading branch information
roblim committed Aug 8, 2019
2 parents 1999da0 + a9960de commit f35888b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
9 changes: 8 additions & 1 deletion great_expectations/data_context/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ def build_slack_notification_request(validation_json=None):
query["blocks"][0]["text"]["text"] = "*Validated batch from data asset:* `{}`\n*Status: {}*\n{}".format(
data_asset_name, status, check_details_text)
if "batch_kwargs" in validation_json["meta"]:
query["blocks"][1]["text"]["text"] = "Batch kwargs: {}".format(
batch_kwargs = {
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Batch kwargs: {}".format(
json.dumps(validation_json["meta"]["batch_kwargs"], indent=2))
}
}
query["blocks"].append(batch_kwargs)

if "result_reference" in validation_json["meta"]:
report_element = {
Expand Down
55 changes: 55 additions & 0 deletions tests/test_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,61 @@ def test_build_slack_notification_request_with_successful_validation(validation_
]
}

def test_build_slack_notification_request_with_successful_validation_and_batch_kwargs(validation_json):
validation_json["meta"]["batch_kwargs"] = {
"path": "/Users/user/some_path/some_file.csv",
"timestamp": "1565286704.3622668",
"sep": None,
"engine": "python"
}

with mock.patch("datetime.datetime") as mock_datetime:
mock_datetime.strftime.return_value = "05/05/19 12:12:12"
obs = build_slack_notification_request(validation_json)

assert isinstance(obs, dict)
print(obs)
assert obs == {
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Validated batch from data asset:* `diabetes_raw_csv`\n*Status: Success :tada:*\n33 of 44 expectations were met\n\n",
},
},
{
'type': 'section',
'text': {
'type': 'mrkdwn',
'text': 'Batch kwargs: {\n "path": "/Users/user/some_path/some_file.csv",\n "timestamp": "1565286704.3622668",\n "sep": null,\n "engine": "python"\n}'
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "- *Validation Report*: s3://my_bucket/blah.json",
},
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "- *Validation data asset*: s3://my_bucket/blah.csv",
},
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "Great Expectations run id 7 ran at 05/05/19 12:12:12",
}
],
},
]
}

def test_build_slack_notification_request_with_failed_validation(validation_json):
validation_json["success"] = False
Expand Down

0 comments on commit f35888b

Please sign in to comment.