# Path: os_win/exceptions.py
#     class WindowsError(Exception):
#     class x_wmi(Exception):
#     class x_wmi_timed_out(x_wmi):
# class OSWinException(Exception):
# class NotFound(OSWinException):
# class PciDeviceNotFound(NotFound):
# class HyperVException(OSWinException):
# class VHDResizeException(HyperVException):
# class HyperVAuthorizationException(HyperVException):
# class HyperVVMNotFoundException(NotFound, HyperVException):
# class HyperVPortNotFoundException(NotFound, HyperVException):
# class HyperVvNicNotFound(NotFound, HyperVException):
# class HyperVvSwitchNotFound(NotFound, HyperVException):
# class Invalid(OSWinException):
# class UnsupportedOperation(Invalid):
# class InvalidParameterValue(Invalid):
# class InvalidVMVersion(Invalid):
# class SMBException(OSWinException):
# class Win32Exception(OSWinException):
# class VHDException(OSWinException):
# class VHDWin32APIException(VHDException, Win32Exception):
# class FCException(OSWinException):
# class FCWin32Exception(FCException, Win32Exception):
# class WMIException(OSWinException):
# class WqlException(OSWinException):
# class ISCSITargetException(OSWinException):
# class ISCSITargetWMIException(ISCSITargetException, WMIException):
# class ISCSIInitiatorAPIException(Win32Exception):
# class ISCSILunNotAvailable(ISCSITargetException):
# class Win32IOException(Win32Exception):
# class DiskNotFound(NotFound):
# class HyperVRemoteFXException(HyperVException):
# class HyperVClusterException(HyperVException):
# class DNSException(OSWinException):
# class Timeout(OSWinException):
# class DNSZoneNotFound(NotFound, DNSException):
# class DNSZoneAlreadyExists(DNSException):
# class WMIJobFailed(HyperVException):
# class JobTerminateFailed(HyperVException):
# class ClusterException(OSWinException):
# class ClusterObjectNotFound(NotFound, ClusterException):
# class ClusterWin32Exception(ClusterException, Win32Exception):
# class ClusterGroupMigrationFailed(ClusterException):
# class ClusterGroupMigrationTimeOut(ClusterGroupMigrationFailed):
# class ClusterPropertyRetrieveFailed(ClusterException):
# class ClusterPropertyListEntryNotFound(ClusterPropertyRetrieveFailed):
# class ClusterPropertyListParsingError(ClusterPropertyRetrieveFailed):
# class SCSIPageParsingError(Invalid):
# class SCSIIdDescriptorParsingError(Invalid):
# class ResourceUpdateError(OSWinException):
# class DiskUpdateError(OSWinException):
#         def __init__(self, winerror=None):
#         def __init__(self, info='', com_error=None):
#     def __init__(self, message=None, **kwargs):
#     def __init__(self, message=None, wmi_exc=None):
#     def __init__(self, message=None, **kwargs):
# 
# Path: os_win/tests/unit/test_base.py
# class TestingException(Exception):
# class FakeWMIExc(exceptions.x_wmi):
# class BaseTestCase(base.BaseTestCase):
# class OsWinBaseTestCase(BaseTestCase):
#     def __init__(self, hresult=None):
#     def setUp(self):
#     def _patch_autospec_classes(self):
#     def setUp(self):
# 
# Path: os_win/utils/_wqlutils.py
# def get_element_associated_class(conn, class_name, element_instance_id=None,
#                                  element_uuid=None, fields=None):


from unittest import mock
from os_win import exceptions
from os_win.tests.unit import test_base
from os_win.utils import _wqlutils



class WqlUtilsTestCase(test_base.OsWinBaseTestCase):
    def _test_get_element_associated_class(self, fields=None):
        mock_conn = mock.MagicMock()
        _wqlutils.get_element_associated_class(
            mock_conn, mock.sentinel.class_name,
            element_instance_id=mock.sentinel.instance_id,
            fields=fields)

        expected_fields = ", ".join(fields) if fields else '*'
        expected_query = (
            "SELECT %(expected_fields)s FROM %(class_name)s "
            "WHERE InstanceID LIKE '%(instance_id)s%%'" %
            {'expected_fields': expected_fields,
             'class_name': mock.sentinel.class_name,
             'instance_id': mock.sentinel.instance_id})
        mock_conn.query.assert_called_once_with(expected_query)

    def test_get_element_associated_class(self):
        self._test_get_element_associated_class()

    def test_get_element_associated_class_specific_fields(self):
        self._test_get_element_associated_class(
            fields=['field', 'another_field'])

    def test_get_element_associated_class_invalid_element(self):
        self.assertRaises(
            exceptions.WqlException,

# Path: os_win/exceptions.py
#     class WindowsError(Exception):
#     class x_wmi(Exception):
#     class x_wmi_timed_out(x_wmi):
# class OSWinException(Exception):
# class NotFound(OSWinException):
# class PciDeviceNotFound(NotFound):
# class HyperVException(OSWinException):
# class VHDResizeException(HyperVException):
# class HyperVAuthorizationException(HyperVException):
# class HyperVVMNotFoundException(NotFound, HyperVException):
# class HyperVPortNotFoundException(NotFound, HyperVException):
# class HyperVvNicNotFound(NotFound, HyperVException):
# class HyperVvSwitchNotFound(NotFound, HyperVException):
# class Invalid(OSWinException):
# class UnsupportedOperation(Invalid):
# class InvalidParameterValue(Invalid):
# class InvalidVMVersion(Invalid):
# class SMBException(OSWinException):
# class Win32Exception(OSWinException):
# class VHDException(OSWinException):
# class VHDWin32APIException(VHDException, Win32Exception):
# class FCException(OSWinException):
# class FCWin32Exception(FCException, Win32Exception):
# class WMIException(OSWinException):
# class WqlException(OSWinException):
# class ISCSITargetException(OSWinException):
# class ISCSITargetWMIException(ISCSITargetException, WMIException):
# class ISCSIInitiatorAPIException(Win32Exception):
# class ISCSILunNotAvailable(ISCSITargetException):
# class Win32IOException(Win32Exception):
# class DiskNotFound(NotFound):
# class HyperVRemoteFXException(HyperVException):
# class HyperVClusterException(HyperVException):
# class DNSException(OSWinException):
# class Timeout(OSWinException):
# class DNSZoneNotFound(NotFound, DNSException):
# class DNSZoneAlreadyExists(DNSException):
# class WMIJobFailed(HyperVException):
# class JobTerminateFailed(HyperVException):
# class ClusterException(OSWinException):
# class ClusterObjectNotFound(NotFound, ClusterException):
# class ClusterWin32Exception(ClusterException, Win32Exception):
# class ClusterGroupMigrationFailed(ClusterException):
# class ClusterGroupMigrationTimeOut(ClusterGroupMigrationFailed):
# class ClusterPropertyRetrieveFailed(ClusterException):
# class ClusterPropertyListEntryNotFound(ClusterPropertyRetrieveFailed):
# class ClusterPropertyListParsingError(ClusterPropertyRetrieveFailed):
# class SCSIPageParsingError(Invalid):
# class SCSIIdDescriptorParsingError(Invalid):
# class ResourceUpdateError(OSWinException):
# class DiskUpdateError(OSWinException):
#         def __init__(self, winerror=None):
#         def __init__(self, info='', com_error=None):
#     def __init__(self, message=None, **kwargs):
#     def __init__(self, message=None, wmi_exc=None):
#     def __init__(self, message=None, **kwargs):
# 
# Path: os_win/tests/unit/test_base.py
# class TestingException(Exception):
# class FakeWMIExc(exceptions.x_wmi):
# class BaseTestCase(base.BaseTestCase):
# class OsWinBaseTestCase(BaseTestCase):
#     def __init__(self, hresult=None):
#     def setUp(self):
#     def _patch_autospec_classes(self):
#     def setUp(self):
# 
# Path: os_win/utils/_wqlutils.py
# def get_element_associated_class(conn, class_name, element_instance_id=None,
#                                  element_uuid=None, fields=None):


# Path: os_win/tests/unit/utils/test_wqlutils.py
from unittest import mock
from os_win import exceptions
from os_win.tests.unit import test_base
from os_win.utils import _wqlutils




class WqlUtilsTestCase(test_base.OsWinBaseTestCase):
    def _test_get_element_associated_class(self, fields=None):
        mock_conn = mock.MagicMock()
        _wqlutils.get_element_associated_class(
            mock_conn, mock.sentinel.class_name,
            element_instance_id=mock.sentinel.instance_id,
            fields=fields)

        expected_fields = ", ".join(fields) if fields else '*'
        expected_query = (
            "SELECT %(expected_fields)s FROM %(class_name)s "
            "WHERE InstanceID LIKE '%(instance_id)s%%'" %
            {'expected_fields': expected_fields,
             'class_name': mock.sentinel.class_name,
             'instance_id': mock.sentinel.instance_id})
        mock_conn.query.assert_called_once_with(expected_query)

    def test_get_element_associated_class(self):
        self._test_get_element_associated_class()

    def test_get_element_associated_class_specific_fields(self):
        self._test_get_element_associated_class(
            fields=['field', 'another_field'])

    def test_get_element_associated_class_invalid_element(self):
        self.assertRaises(
            exceptions.WqlException,

            _wqlutils.get_element_associated_class,