Пример #1
0
def test_nomad_agent_deploy_flow(monkeypatch, runner_token):
    post = MagicMock()
    import requests  # this is imported within the agent's constructor

    monkeypatch.setattr(requests, "post", post)

    agent = NomadAgent()
    agent.deploy_flow(
        flow_run=GraphQLResult(
            {
                "flow": GraphQLResult(
                    {
                        "storage": Docker(
                            registry_url="test", image_name="name", image_tag="tag"
                        ).serialize(),
                        "id": "id",
                    }
                ),
                "id": "id",
            }
        )
    )

    assert post.called
    assert post.call_args[1]["json"]
Пример #2
0
def test_nomad_agent_deploy_flow_raises(monkeypatch, runner_token):
    requests = MagicMock()
    monkeypatch.setattr("prefect.agent.nomad.agent.requests", requests)

    agent = NomadAgent()

    with pytest.raises(ValueError):
        agent.deploy_flow(
            flow_run=GraphQLResult(
                {
                    "flow": GraphQLResult({"storage": Local().serialize(), "id": "id"}),
                    "id": "id",
                }
            )
        )

    assert not requests.post.called
Пример #3
0
def test_nomad_agent_deploy_flow_raises(monkeypatch, runner_token):
    post = MagicMock()
    import requests  # this is imported within the agent's constructor

    monkeypatch.setattr(requests, "post", post)

    agent = NomadAgent()

    with pytest.raises(ValueError):
        agent.deploy_flow(
            flow_run=GraphQLResult(
                {
                    "flow": GraphQLResult({"storage": Local().serialize(), "id": "id"}),
                    "id": "id",
                }
            )
        )

    assert not post.called
Пример #4
0
def test_nomad_agent_deploy_flow(monkeypatch, runner_token):
    requests = MagicMock()
    monkeypatch.setattr("prefect.agent.nomad.agent.requests", requests)

    agent = NomadAgent()
    agent.deploy_flow(
        flow_run=GraphQLResult(
            {
                "flow": GraphQLResult(
                    {
                        "storage": Docker(
                            registry_url="test", image_name="name", image_tag="tag"
                        ).serialize(),
                        "id": "id",
                    }
                ),
                "id": "id",
            }
        )
    )

    assert requests.post.called
    assert requests.post.call_args[1]["json"]