#!/usr/bin/python3
#
# Copyright (C) 2025 Red Hat, Inc.
# SPDX-License-Identifier: LGPL-2.1-or-later

from anacondalib import INSTALLER_VM_MEMORY_MB, VirtInstallMachineCase, disk_images
from installer import Installer
from progress import Progress
from testlib import test_main, timeout  # pylint: disable=import-error
from utils import get_pretty_name


class TestPayloadDNF_E2E(VirtInstallMachineCase):
    provision = {"machine1": {"payload_type": "dnf", "memory_mb": INSTALLER_VM_MEMORY_MB}}

    @disk_images([("", 15)])
    @timeout(1200)
    def testDefaultClosestMirror(self):
        """
        Description:
            Perform a simple installation using the default DNF payload
            with the closest mirror source.

        Expected results:
            - The system installs successfully and boots to Fedora.
        """
        b = self.browser
        m = self.machine
        i = Installer(b, m)
        p = Progress(b)

        i.open()
        i.reach(i.steps.REVIEW)

        # Begin installation, wait for completion
        i.begin_installation(needs_confirmation=False)
        p.wait_done(timeout=2400)

        # Reboot into installed system
        self.handleReboot()

        # Sanity check: verify we booted into Fedora
        pretty_name = get_pretty_name(m)
        self.assertIn("Fedora Linux", pretty_name)


if __name__ == '__main__':
    test_main()
