from tests.mgnt_general_acsw_power_test import GeneralACSWPowerTest
from .mgnt_auto_checkout_test import AutoCheckoutTest


class ACSWPowerTest(AutoCheckoutTest):
    test_id = 'acsw_power'
    description = 'ACSW power control'
    read_only = False
    deferred = False

    def __init__(self):
        super(ACSWPowerTest, self).__init__(
            pre_checkout_routines=[]
        )

    def execute(self, magnet):
        """Gets the result of the general ACSW power test for a magnet's ACSW plug. If there is no result, ask the user
        to test the plug.

        Args:
            magnet (dict): Information about a magnet from Oracle (Elements, Polynomial, Additional Data)

        Returns:
            None

        """
        if not magnet['acsw_node']:
            self.status = None
            return

        results = GeneralACSWPowerTest().get_subtest_results(magnet['acsw_host'], magnet['acsw_plug'])
        if not results:
            raise Exception(
                "No test results found for {0}, plug {1}. Please append '-A {0}' to your previous command to test the ACSW".format(
                    magnet['acsw_host'], magnet['acsw_plug']))

        self.data = results['data']
        self.status = results['status']
