|
2 | 2 | import uuid
|
3 | 3 |
|
4 | 4 | import freezegun
|
| 5 | +import mock.mock |
5 | 6 | import pytest
|
6 | 7 |
|
7 | 8 | from notebooker.constants import JobStatus, NotebookResultComplete, NotebookResultError, NotebookResultPending
|
@@ -173,3 +174,56 @@ def test_report_hunter_pending_to_done(bson_library, webapp_config):
|
173 | 174 | serializer.save_check_result(expected)
|
174 | 175 | _report_hunter(webapp_config=webapp_config, run_once=True)
|
175 | 176 | assert get_report_cache(report_name, job_id, cache_dir=webapp_config.CACHE_DIR) == expected
|
| 177 | + |
| 178 | + |
| 179 | +@mock.patch("notebooker.web.routes.prometheus.record_failed_report") |
| 180 | +def test_prometheus_logging_in_report_hunter_no_prometheus_fail(record_failed_report, bson_library, webapp_config): |
| 181 | + job_id = str(uuid.uuid4()) |
| 182 | + report_name = str(uuid.uuid4()) |
| 183 | + serializer = initialize_serializer_from_config(webapp_config) |
| 184 | + record_failed_report.side_effect = ImportError("wah") |
| 185 | + |
| 186 | + with freezegun.freeze_time(datetime.datetime(2018, 1, 12, 2, 37)): |
| 187 | + expected = NotebookResultError( |
| 188 | + job_id=job_id, |
| 189 | + report_name=report_name, |
| 190 | + report_title=report_name, |
| 191 | + status=JobStatus.ERROR, |
| 192 | + update_time=datetime.datetime(2018, 1, 12, 2, 37), |
| 193 | + job_start_time=datetime.datetime(2018, 1, 12, 2, 30), |
| 194 | + error_info="This was cancelled!", |
| 195 | + ) |
| 196 | + serializer.save_check_result(expected) |
| 197 | + _report_hunter(webapp_config=webapp_config, run_once=True) |
| 198 | + assert get_report_cache(report_name, job_id, cache_dir=webapp_config.CACHE_DIR) == expected |
| 199 | + record_failed_report.assert_called_once_with(report_name, report_name) |
| 200 | + |
| 201 | + |
| 202 | +@mock.patch("notebooker.web.routes.prometheus.record_successful_report") |
| 203 | +def test_prometheus_logging_in_report_hunter_no_prometheus_success( |
| 204 | + record_successful_report, bson_library, webapp_config |
| 205 | +): |
| 206 | + job_id = str(uuid.uuid4()) |
| 207 | + report_name = str(uuid.uuid4()) |
| 208 | + serializer = initialize_serializer_from_config(webapp_config) |
| 209 | + record_successful_report.side_effect = ImportError("wah") |
| 210 | + |
| 211 | + with freezegun.freeze_time(datetime.datetime(2018, 1, 12, 2, 37)): |
| 212 | + expected = NotebookResultComplete( |
| 213 | + job_id=job_id, |
| 214 | + report_name=report_name, |
| 215 | + report_title=report_name, |
| 216 | + status=JobStatus.DONE, |
| 217 | + update_time=datetime.datetime(2018, 1, 12, 2, 37), |
| 218 | + job_start_time=datetime.datetime(2018, 1, 12, 2, 30), |
| 219 | + job_finish_time=datetime.datetime(2018, 1, 12, 2, 37), |
| 220 | + pdf=b"abc", |
| 221 | + raw_html="rawstuff", |
| 222 | + email_html="emailstuff", |
| 223 | + raw_html_resources={"outputs": {}, "inlining": []}, |
| 224 | + raw_ipynb_json="[]", |
| 225 | + ) |
| 226 | + serializer.save_check_result(expected) |
| 227 | + _report_hunter(webapp_config=webapp_config, run_once=True) |
| 228 | + assert get_report_cache(report_name, job_id, cache_dir=webapp_config.CACHE_DIR) == expected |
| 229 | + record_successful_report.assert_called_once_with(report_name, report_name) |
0 commit comments