import uuid

from keble_helpers import ProgressTask
from ..config import redis


def test_get_prebuilt_subtasks_model():
    key = str(uuid.uuid4())
    model_key = str(uuid.uuid4())
    root = ProgressTask(redis=redis, key=key, model_key=model_key)
    t1 = root.new_subtask()
    t2 = root.new_subtask()
    t3 = root.new_subtask()
    t1.success()
    t2.failure()
    t3.success()
    root.success()

    # expect prebuilt to be length of 3

    new_root = ProgressTask(redis=redis, key=str(uuid.uuid4()), model_key=model_key)
    new_root.subtasks = new_root.get_prebuilt_subtasks_model(root=root,
                                                             redis=redis,
                                                             model_key=model_key)
    assert len(new_root.subtasks) == 3

    # now same model key, but we change its length
    t1 = new_root.new_subtask()
    t2 = new_root.new_subtask()
    t1.success()
    t2.failure()
    new_root.success()

    # expect prebuilt to be length of 2

    new_root = ProgressTask(redis=redis, key=str(uuid.uuid4()), model_key=model_key)
    new_root.subtasks = new_root.get_prebuilt_subtasks_model(root=root,
                                                             redis=redis,
                                                             model_key=model_key)
    assert len(new_root.subtasks) == 2
