Esempio n. 1
0
def test_flyte_task_fetch(mock_url, mock_client_manager):
    mock_url.get.return_value = "localhost"
    admin_task_v1 = _task_models.Task(
        _identifier.Identifier(_identifier.ResourceType.TASK, "p1", "d1", "n1",
                               "v1"),
        _MagicMock(),
    )
    admin_task_v2 = _task_models.Task(
        _identifier.Identifier(_identifier.ResourceType.TASK, "p1", "d1", "n1",
                               "v2"),
        _MagicMock(),
    )
    mock_client = _MagicMock()
    mock_client.list_tasks_paginated = _MagicMock(
        return_value=([admin_task_v2, admin_task_v1], ""))
    mock_client_manager.return_value.client = mock_client

    latest_task = _task.FlyteTask.fetch_latest("p1", "d1", "n1")
    task_v1 = _task.FlyteTask.fetch("p1", "d1", "n1", "v1")
    task_v2 = _task.FlyteTask.fetch("p1", "d1", "n1", "v2")
    assert task_v1.id == admin_task_v1.id
    assert task_v1.id != latest_task.id
    assert task_v2.id == latest_task.id == admin_task_v2.id

    for task in [task_v1, task_v2]:
        assert task.entity_type_text == "Task"
        assert task.resource_type == _identifier.ResourceType.TASK
Esempio n. 2
0
def test_task(task_closure):
    obj = task.Task(
        identifier.Identifier(identifier.ResourceType.TASK, "project",
                              "domain", "name", "version"), task_closure)
    assert obj.id.project == "project"
    assert obj.id.domain == "domain"
    assert obj.id.name == "name"
    assert obj.id.version == "version"
    assert obj.closure == task_closure
    assert obj == task.Task.from_flyte_idl(obj.to_flyte_idl())
Esempio n. 3
0
def test_fetch_latest(mock_get_engine):
    admin_task = _task_models.Task(
        _identifier.Identifier(_identifier.ResourceType.TASK, "p1", "d1", "n1",
                               "v1"),
        _MagicMock(),
    )
    mock_engine = _MagicMock()
    mock_engine.fetch_latest_task = _MagicMock(return_value=admin_task)
    mock_get_engine.return_value = mock_engine
    task = _task.SdkTask.fetch_latest("p1", "d1", "n1")
    assert task.id == admin_task.id
Esempio n. 4
0
def test_fetch_latest(mock_url, mock_client_manager):
    mock_url.get.return_value = "localhost"
    admin_task = _task_models.Task(
        _identifier.Identifier(_identifier.ResourceType.TASK, "p1", "d1", "n1",
                               "v1"),
        _MagicMock(),
    )
    mock_client = _MagicMock()
    mock_client.list_tasks_paginated = _MagicMock(return_value=([admin_task],
                                                                ""))
    mock_client_manager.return_value.client = mock_client
    task = _task.SdkTask.fetch_latest("p1", "d1", "n1")
    assert task.id == admin_task.id
Esempio n. 5
0
                    "project",
                    "domain",
                    "name",
                ),
            ),
            0,
        )
    )


@pytest.mark.parametrize(
    "tasks",
    [
        [
            _task_models.Task(
                identifier.Identifier(identifier.ResourceType.TASK, "p1", "d1", "n1", "v1"),
                MagicMock(),
            )
        ],
        [],
    ],
)
@patch.object(engine._FlyteClientManager, "_CLIENT", new_callable=PropertyMock)
def test_fetch_latest_task(mock_client_factory, tasks):
    mock_client = MagicMock()
    mock_client.list_tasks_paginated = MagicMock(return_value=(tasks, 0))
    mock_client_factory.return_value = mock_client

    task = engine.FlyteEngineFactory().fetch_latest_task(_common_models.NamedEntityIdentifier("p", "d", "n"))

    if tasks:
        assert task.id == tasks[0].id