Пример #1
0
def test_get_task_run_info_with_error(monkeypatch):
    response = {
        "data": {
            "getOrCreateTaskRun": None
        },
        "errors": [{
            "message": "something went wrong"
        }],
    }
    post = MagicMock(return_value=MagicMock(json=MagicMock(
        return_value=response)))
    session = MagicMock()
    session.return_value.post = post
    monkeypatch.setattr("requests.Session", session)
    with set_temporary_config({
            "cloud.graphql": "http://my-cloud.foo",
            "cloud.auth_token": "secret_token"
    }):
        client = Client()

    with pytest.raises(ClientError) as exc:
        client.get_task_run_info(flow_run_id="74-salt",
                                 task_id="72-salt",
                                 map_index=None)

    assert "something went wrong" in str(exc.value)
Пример #2
0
def test_get_task_run_info(monkeypatch):
    response = """
    {
        "getOrCreateTaskRun": {
            "task_run": {
                "id": "772bd9ee-40d7-479c-9839-4ab3a793cabd",
                "version": 0,
                "serialized_state": {
                    "type": "Pending",
                    "_result": {"type": "SafeResult", "value": "42", "result_handler": {"type": "JSONResultHandler"}},
                    "message": null,
                    "__version__": "0.3.3+310.gd19b9b7.dirty",
                    "cached_inputs": null
                }
            }
        }
    }
    """
    post = MagicMock(return_value=MagicMock(json=MagicMock(return_value=dict(
        data=json.loads(response)))))
    monkeypatch.setattr("requests.post", post)
    with set_temporary_config({
            "cloud.graphql": "http://my-cloud.foo",
            "cloud.auth_token": "secret_token"
    }):
        client = Client()
    result = client.get_task_run_info(flow_run_id="74-salt",
                                      task_id="72-salt",
                                      map_index=None)
    assert isinstance(result, TaskRunInfoResult)
    assert isinstance(result.state, Pending)
    assert result.state.result == "42"
    assert result.state.message is None
    assert result.id == "772bd9ee-40d7-479c-9839-4ab3a793cabd"
    assert result.version == 0
Пример #3
0
def test_get_task_run_info_with_error(patch_post):
    response = {
        "data": {"getOrCreateTaskRun": None},
        "errors": [{"message": "something went wrong"}],
    }
    post = patch_post(response)

    with set_temporary_config(
        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
    ):
        client = Client()

    with pytest.raises(ClientError, match="something went wrong"):
        client.get_task_run_info(
            flow_run_id="74-salt", task_id="72-salt", map_index=None
        )
Пример #4
0
def test_get_task_run_info(patch_posts):
    mutation_resp = {
        "get_or_create_task_run": {
            "id": "772bd9ee-40d7-479c-9839-4ab3a793cabd",
        }
    }
    query_resp = {
        "task_run_by_pk": {
            "version": 0,
            "serialized_state": {
                "type": "Pending",
                "_result": {
                    "type": "SafeResult",
                    "value": "42",
                    "result_handler": {
                        "type": "JSONResultHandler"
                    },
                },
                "message": None,
                "__version__": "0.3.3+310.gd19b9b7.dirty",
                "cached_inputs": None,
            },
            "task": {
                "slug": "slug"
            },
        }
    }

    post = patch_posts([dict(data=mutation_resp), dict(data=query_resp)])
    with set_temporary_config({
            "cloud.api": "http://my-cloud.foo",
            "cloud.auth_token": "secret_token",
            "backend": "cloud",
    }):
        client = Client()
    result = client.get_task_run_info(flow_run_id="74-salt",
                                      task_id="72-salt",
                                      map_index=None)
    assert isinstance(result, TaskRunInfoResult)
    assert isinstance(result.state, Pending)
    assert result.state.result == "42"
    assert result.state.message is None
    assert result.id == "772bd9ee-40d7-479c-9839-4ab3a793cabd"
    assert result.version == 0