class zzzTestFrameworkSHlaunchdTwoHelperMethods(unittest.TestCase):
        '''
        Test the launchd version 2 service helper.

        @author: Roy Nielsen
        '''
        @classmethod
        def setUpClass(self):
            '''
            Test initializer
            '''
            self.environ = Environment()
            self.environ.setdebugmode(True)

            # Start timer in miliseconds
            self.test_start_time = datetime.now()

            self.logger = LogDispatcher(self.environ)
            self.logger.initializeLogs()

            self.sh = SHlaunchdTwo(self.environ, self.logger)

            self.logger.log(lp.DEBUG, "test " + __file__ + " initialized...")

        def test_isValidServicePath(self):
            '''
            '''
            for test_key, test_values in service_path_test_data.iteritems():
                if re.match("^valid_service_paths", test_key):
                    for test_item in test_values:
                        self.assertTrue(self.sh.isValidServicePath(test_item),
                                        "Invalid service path: " +
                                        str(test_item))
                if re.match("^invalid_service_paths", test_key):
                    for test_item in test_values:
                        self.assertFalse(self.sh.isValidServicePath(test_item),
                                         "Valid service path: " +
                                         str(test_item))

        def test_getServiceNameFromService(self):
            '''
            '''
            for test_key, test_values in name_from_service_test_data.iteritems():
                if re.match("^valid_service_plists", test_key):
                    for test_item in test_values:
                        self.assertTrue(self.sh.isValidServicePath(test_item),
                                        "Invalid service plist: " +
                                        str(test_item))
                if re.match("^invalid_service_plists", test_key):
                    for test_item in test_values:
                        self.assertFalse(self.sh.isValidServicePath(test_item),
                                         "Valid service plist: " +
                                         str(test_item))

        def test_targetValid(self):
            '''
            '''
            for test_key, test_values in target_valid_test_data.iteritems():
                if re.match("^valid_target_data", test_key):
                    for test_item in test_values:
                        params = {test_item[1]['serviceName'][0]:
                                  test_item[1]['serviceName'][1]}
                        self.assertEqual(self.sh.targetValid(test_item[0],
                                                             **params),
                                         test_item[2],
                                         "Target data: " +
                                         str(test_item) +
                                         " is not valid.")
                if re.match("^invalid_target_data", test_key):
                    for test_item in test_values:
                        params = {test_item[1]['serviceName'][0]:
                                  test_item[1]['serviceName'][1]}
                        self.assertNotEqual(self.sh.targetValid(test_item[0],
                                                                **params),
                                            test_item[2],
                                            "Target data: " +
                                            str(test_item) +
                                            " is good!")

        @classmethod
        def tearDownClass(self):
            '''
            Test destructor
            '''
            #####
            # capture end time
            test_end_time = datetime.now()

            #####
            # Calculate and log how long it took...
            test_time = (test_end_time - self.test_start_time)

            self.logger.log(lp.DEBUG, self.__module__ +
                            " took " + str(test_time) +
                            " time to complete...")
Esempio n. 2
0
sys.path.append("../../../..")
from src.stonix_resources.FileStateManager import FileStateManager
from src.stonix_resources.environment import Environment
from src.stonix_resources.CommandHelper import CommandHelper
from src.tests.lib.logdispatcher_lite import LogDispatcher, LogPriority
from src.stonix_resources.get_libc import getLibc

lp = LogPriority

LIBC = getLibc()

environ = Environment()
environ.stonixversion = "1.2.3"
logger = LogDispatcher(debug_mode=True)
logger.initializeLogs("/tmp/zzzTestFrameworkFileStateManager",
                      extension_type="time",
                      syslog=False,
                      myconsole=False)


class NotApplicableToThisOS(Exception):
    '''Custom Exception'''
    def __init__(self, *args, **kwargs):
        Exception.__init__(self, *args, **kwargs)


class zzzTestFrameworkFileStateManager(unittest.TestCase):
    '''Class for testing the FileStateManager.'''
    def setUp(self):
        ''' '''
        #self.environ = Environment()
        #self.environ.stonixversion = "1.2.3"
    class zzzTestFrameworkSHlaunchdTwoHelperMethods(unittest.TestCase):
        '''Test the launchd version 2 service helper.
        
        @author: Roy Nielsen


        '''
        @classmethod
        def setUpClass(self):
            '''Test initializer'''
            self.environ = Environment()
            self.environ.setdebugmode(True)

            # Start timer in miliseconds
            self.test_start_time = datetime.now()

            self.logger = LogDispatcher(self.environ)
            self.logger.initializeLogs()

            self.sh = SHlaunchdTwo(self.environ, self.logger)

            self.logger.log(lp.DEBUG, "test " + __file__ + " initialized...")

        def test_isValidServicePath(self):
            ''' '''
            for test_key, test_values in list(service_path_test_data.items()):
                if re.match("^valid_service_paths", test_key):
                    for test_item in test_values:
                        self.assertTrue(
                            self.sh.isValidServicePath(test_item),
                            "Invalid service path: " + str(test_item))
                if re.match("^invalid_service_paths", test_key):
                    for test_item in test_values:
                        self.assertFalse(
                            self.sh.isValidServicePath(test_item),
                            "Valid service path: " + str(test_item))

        def test_getServiceNameFromService(self):
            ''' '''
            for test_key, test_values in list(
                    name_from_service_test_data.items()):
                if re.match("^valid_service_plists", test_key):
                    for test_item in test_values:
                        self.assertTrue(
                            self.sh.isValidServicePath(test_item),
                            "Invalid service plist: " + str(test_item))
                if re.match("^invalid_service_plists", test_key):
                    for test_item in test_values:
                        self.assertFalse(
                            self.sh.isValidServicePath(test_item),
                            "Valid service plist: " + str(test_item))

        def test_targetValid(self):
            ''' '''
            for test_key, test_values in list(target_valid_test_data.items()):
                if re.match("^valid_target_data", test_key):
                    for test_item in test_values:
                        params = {
                            test_item[1]['serviceName'][0]:
                            test_item[1]['serviceName'][1]
                        }
                        self.assertEqual(
                            self.sh.targetValid(test_item[0], **params),
                            test_item[2], "Target data: " + str(test_item) +
                            " is not valid.")
                if re.match("^invalid_target_data", test_key):
                    for test_item in test_values:
                        params = {
                            test_item[1]['serviceName'][0]:
                            test_item[1]['serviceName'][1]
                        }
                        self.assertNotEqual(
                            self.sh.targetValid(test_item[0],
                                                **params), test_item[2],
                            "Target data: " + str(test_item) + " is good!")

        @classmethod
        def tearDownClass(self):
            '''Test destructor'''
            #####
            # capture end time
            test_end_time = datetime.now()

            #####
            # Calculate and log how long it took...
            test_time = (test_end_time - self.test_start_time)

            self.logger.log(
                lp.DEBUG, self.__module__ + " took " + str(test_time) +
                " time to complete...")
sys.path.append("../../../..")
from src.stonix_resources.FileStateManager import FileStateManager
from src.stonix_resources.environment import Environment
from src.stonix_resources.CommandHelper import CommandHelper
from src.tests.lib.logdispatcher_lite import LogDispatcher, LogPriority
from src.stonix_resources.get_libc import getLibc

lp = LogPriority

LIBC = getLibc()

environ = Environment()
environ.stonixversion = "1.2.3"
logger = LogDispatcher(debug_mode=True)
logger.initializeLogs("/tmp/zzzTestFrameworkFileStateManager", extension_type="time", syslog=False, myconsole=False)

class NotApplicableToThisOS(Exception):
    """
    Custom Exception
    """
    def __init__(self, *args, **kwargs):
        Exception.__init__(self, *args, **kwargs)


class zzzTestFrameworkFileStateManager(unittest.TestCase):
    """
    Class for testing the FileStateManager.
    """
    def setUp(self):
        """