def test_get_next_task_run_start_time_query_is_correct(cloud_mocks): # Just return nothing to simplify the test / cover malformed response cloud_mocks.Client().graphql.return_value = {} with pytest.raises(ValueError, match="Unexpected result"): _get_next_task_run_start_time("flow-run-id") cloud_mocks.Client().graphql.assert_called_once_with({ "query": { 'task_run(where: { state_start_time: { _is_null: false }, flow_run_id: { _eq: "flow-run-id" }, flow_run: { state: { _eq: "Running" } } })': {"state_start_time"} } })
def test_get_next_task_run_start_time_returns_null_when_no_task_runs( cloud_mocks): # WHen no task runs match the 'where' clause, `None` is returned cloud_mocks.Client().graphql.return_value = GraphQLResult( {"data": { "task_run": [] }}) result = _get_next_task_run_start_time("flow-run-id") assert result is None
def test_get_next_task_run_start_time(cloud_mocks): start_time = pendulum.now("utc") cloud_mocks.Client().graphql.return_value = GraphQLResult({ "data": { "task_run": [ { "state_start_time": start_time.add(seconds=10).isoformat() }, { "state_start_time": start_time.isoformat() }, { "state_start_time": start_time.add(seconds=20).isoformat() }, ] } }) result = _get_next_task_run_start_time("flow-run-id") assert result == start_time