from src.gameplay.core.tasks.attackMonstersBox import AttackMonstersBoxTask


def _context(players=None):
    return {
        'ng_screenshot': object(),
        'ng_battleList': {'creatures': [('Unknown', False)]},
        'gameWindow': {'monsters': [], 'players': players or []},
    }


def test_retries_unmarked_unknown_blocker(mocker):
    mocker.patch(
        'src.gameplay.core.tasks.attackMonstersBox.getNearestCreaturesCount',
        return_value=1,
    )
    mocker.patch(
        'src.gameplay.core.tasks.attackMonstersBox.getContent',
        return_value=object(),
    )
    mocker.patch(
        'src.gameplay.core.tasks.attackMonstersBox.hasSkull',
        return_value=False,
    )

    assert AttackMonstersBoxTask().shouldRestartAfterAllChildrensComplete(
        _context(),
    ) is True


def test_does_not_retry_unknown_player(mocker):
    mocker.patch(
        'src.gameplay.core.tasks.attackMonstersBox.getNearestCreaturesCount',
        return_value=1,
    )
    mocker.patch(
        'src.gameplay.core.tasks.attackMonstersBox.getContent',
        return_value=object(),
    )
    has_skull = mocker.patch(
        'src.gameplay.core.tasks.attackMonstersBox.hasSkull',
        return_value=True,
    )

    assert AttackMonstersBoxTask().shouldRestartAfterAllChildrensComplete(
        _context(players=[object()]),
    ) is False
    has_skull.assert_not_called()
