def test_load_chart_data_into_cache(self, mock_update_job): async_query_manager.init_app(app) query_context = get_query_context("birth_names") job_metadata = { "channel_id": str(uuid4()), "job_id": str(uuid4()), "user_id": 1, "status": "pending", "errors": [], } load_chart_data_into_cache(job_metadata, query_context) mock_update_job.assert_called_with(job_metadata, "done", result_url=mock.ANY)
def test_load_chart_data_into_cache_error(self, mock_update_job, mock_run_command): async_query_manager.init_app(app) query_context = get_query_context("birth_names") job_metadata = { "channel_id": str(uuid4()), "job_id": str(uuid4()), "user_id": 1, "status": "pending", "errors": [], } with pytest.raises(ChartDataQueryFailedError): load_chart_data_into_cache(job_metadata, query_context) mock_run_command.assert_called_with(cache=True) errors = [{"message": "Error: foo"}] mock_update_job.assert_called_with(job_metadata, "error", errors=errors)
def test_load_chart_data_into_cache(self, mock_update_job): async_query_manager.init_app(app) query_context = get_query_context("birth_names") user = security_manager.find_user("gamma") job_metadata = { "channel_id": str(uuid4()), "job_id": str(uuid4()), "user_id": user.id, "status": "pending", "errors": [], } with mock.patch.object(async_queries, "ensure_user_is_set") as ensure_user_is_set: load_chart_data_into_cache(job_metadata, query_context) ensure_user_is_set.assert_called_once_with(user.id) mock_update_job.assert_called_once_with(job_metadata, "done", result_url=mock.ANY)
def test_load_chart_data_into_cache_error(self, mock_update_job, mock_run_command): async_query_manager.init_app(app) query_context = get_query_context("birth_names") user = security_manager.find_user("gamma") job_metadata = { "channel_id": str(uuid4()), "job_id": str(uuid4()), "user_id": user.id, "status": "pending", "errors": [], } with pytest.raises(ChartDataQueryFailedError): with mock.patch.object( async_queries, "ensure_user_is_set" ) as ensure_user_is_set: load_chart_data_into_cache(job_metadata, query_context) ensure_user_is_set.assert_called_once_with(user.id) mock_run_command.assert_called_once_with(cache=True) errors = [{"message": "Error: foo"}] mock_update_job.assert_called_once_with(job_metadata, "error", errors=errors)
def test_soft_timeout_load_chart_data_into_cache( self, mock_update_job, mock_run_command ): async_query_manager.init_app(app) user = security_manager.find_user("gamma") form_data = {} job_metadata = { "channel_id": str(uuid4()), "job_id": str(uuid4()), "user_id": user.id, "status": "pending", "errors": [], } errors = ["A timeout occurred while loading chart data"] with pytest.raises(SoftTimeLimitExceeded): with mock.patch.object( async_queries, "ensure_user_is_set", ) as ensure_user_is_set: ensure_user_is_set.side_effect = SoftTimeLimitExceeded() load_chart_data_into_cache(job_metadata, form_data) ensure_user_is_set.assert_called_once_with(user.id, "error", errors=errors)