Пример #1
0
def test_get_flow_run_scheduled_start_time_raises_on_multiple_flow_runs(
        cloud_mocks):
    cloud_mocks.Client().graphql.return_value = {
        "data": {
            "flow_run": [True, True]
        }
    }

    with pytest.raises(ValueError, match="Found more than one flow"):
        _get_flow_run_scheduled_start_time("flow-run-id")
Пример #2
0
def test_get_flow_run_scheduled_start_time_from_state_time(cloud_mocks):
    start_time = pendulum.now("utc")
    states = [
        Scheduled(start_time=start_time.add(seconds=10)).serialize(),
        Scheduled(start_time=start_time).serialize(),
        Scheduled().serialize(),
    ]

    # Attach db "created" times to the states, the second one is the newest
    states[0]["created"] = pendulum.now().subtract(seconds=10).isoformat()
    states[1]["created"] = pendulum.now().isoformat()

    # The last state will have an empty start time and no created time to test handling
    # of malformed data
    states[2]["start_time"] = None

    cloud_mocks.Client().graphql.return_value = GraphQLResult({
        "data": {
            "flow_run": [{
                "scheduled_start_time":
                (start_time.subtract(seconds=10).isoformat()),
                "states":
                states,
            }]
        }
    })

    result = _get_flow_run_scheduled_start_time("flow-run-id")
    assert result == start_time
Пример #3
0
def test_get_flow_run_scheduled_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_flow_run_scheduled_start_time("flow-run-id")

    cloud_mocks.Client().graphql.assert_called_once_with({
        "query": {
            'flow_run(where: { id: { _eq: "flow-run-id" } })': {
                'states(where: { state: { _eq: "Scheduled" } })': {
                    "created",
                    "start_time",
                },
                "scheduled_start_time": True,
            }
        }
    })
Пример #4
0
def test_get_flow_run_scheduled_start_time_from_flow_run_scheduled_time(
        cloud_mocks, with_states):
    # This occurs when there are no states available or when the states have no start
    # time on them
    states = []
    if with_states:
        states = [Failed().serialize()]
        states[0]["created"] = pendulum.now()

    start_time = pendulum.now("utc")

    cloud_mocks.Client().graphql.return_value = GraphQLResult({
        "data": {
            "flow_run": [{
                "scheduled_start_time": start_time.isoformat(),
                "states": states,
            }]
        }
    })

    result = _get_flow_run_scheduled_start_time("flow-run-id")
    assert result == start_time
Пример #5
0
def test_get_flow_run_scheduled_start_time_raises_on_no_flow_runs(cloud_mocks):
    cloud_mocks.Client().graphql.return_value = {"data": {"flow_run": []}}

    with pytest.raises(ValueError, match="No flow run exists"):
        _get_flow_run_scheduled_start_time("flow-run-id")