import pytest

from clarabot_nano.utility import parse_environment_flag
from clarabot_nano_tests.testing.control import run_nano_control_tester
from clarabot_nano_tests.testing.core.common import clear_nano_slots
from clarabot_nano_tests.testing.server.manager import DevServerManager


@pytest.mark.skipif(parse_environment_flag("CBNANO_TEST_WITHOUT_SERVER"), reason="server-dependant tests disabled")
@pytest.mark.asyncio
async def test_control_2fa_login_10(
    tmpdir,
    reset_user_app_dirs,
    dev_nano_root_dir,
    testing_server_manager: DevServerManager,
    testing_server_user_1,
):
    await clear_nano_slots(testing_server_manager, [testing_server_user_1["account_id"]])
    test_log = await run_nano_control_tester(
        tmpdir,
        testing_server_manager,
        reset_user_app_dirs,
        dev_nano_root_dir,
        "clarabot_nano_tests.control.cases._2fa_login_10:_2fa10LoginControlApplicationTester",
        {"email": testing_server_user_1["email"], "password": testing_server_user_1["password"]},
        timeout=30.0,
    )
    target_log = [
        "Starting _2fa10LoginControlApplicationTester",
        "Systray available: True",
        "Phase 0 passed.",
        "Phase 1 passed.",
        "Phase 2 passed.",
        "Phase 3 passed.",
        "Phase 4 passed.",
        "Phase 5 passed.",
        "Phase 6 passed.",
        "Phase 7 passed.",
        "Phase 8 passed.",
        "Test phases passed.",
        "Exiting",
        "",
    ]
    assert test_log == target_log, test_log


@pytest.mark.skipif(parse_environment_flag("CBNANO_TEST_WITHOUT_SERVER"), reason="server-dependant tests disabled")
@pytest.mark.asyncio
async def test_control_2fa_password_change_10(
    tmpdir,
    reset_user_app_dirs,
    dev_nano_root_dir,
    testing_server_manager: DevServerManager,
    testing_server_user0,
):
    await clear_nano_slots(testing_server_manager, [testing_server_user0["account_id"]])
    test_log = await run_nano_control_tester(
        tmpdir,
        testing_server_manager,
        reset_user_app_dirs,
        dev_nano_root_dir,
        "clarabot_nano_tests.control.cases._2fa_password_change_10:_2fa10PasswordChangeControlApplicationTester",
        {"email": testing_server_user0["email"], "password": testing_server_user0["password"]},
        timeout=30.0,
    )
    target_log = [
        "Starting _2fa10PasswordChangeControlApplicationTester",
        "Systray available: True",
        "Phase 0 passed.",
        "Phase 1 passed.",
        "Phase 2 passed.",
        "Phase 3 passed.",
        "Phase 4 passed.",
        "Phase 5 passed.",
        "Phase 6 passed.",
        "Phase 7 passed.",
        "Phase 8 passed.",
        "Phase 9 passed.",
        "Phase 10 passed.",
        "Phase 11 passed.",
        "Test phases passed.",
        "Exiting",
        "",
    ]
    assert test_log == target_log, test_log
