def setUp(self):
        """
            Setting up tests by running the first run setup and setting specific variables
            based on the config file.
        """

        SettingsManager().first_run_test()
        self.app_name = etltest_config['app_name']
        self.app_author = etltest_config['app_author']
        self.data_dir = appdirs.user_data_dir(self.app_name, self.app_author)
        self.log_dir = appdirs.user_log_dir(self.app_name, self.app_author)
        self.settings_file = os.path.join(self.data_dir,
                                          etltest_config['settings_file'])
        self.connection_file = os.path.join(self.data_dir,
                                            etltest_config['connection_file'])
        self.data_location = SettingsManager().find_setting(
            'Locations', 'data')
        self.tools_file = os.path.join(self.data_dir,
                                       etltest_config['tools_file'])
        self.copy_file = os.path.join(self.data_dir, 'copy.test')
        self.tests_location = SettingsManager().find_setting(
            'Locations', 'tests')
        self.output_location = SettingsManager().find_setting(
            'Locations', 'output')

        self.maxDiff = None
Exemplo n.º 2
0
 def setUp(self):
     SettingsManager().first_run_test()
     self.tmp_path = SettingsManager().get_file_location()
     self.data_loc = SettingsManager().find_setting('Locations', 'data')
     self.test_dir = self.tmp_path + "/etltest/samples/test/"
     self.data_dir = self.tmp_path + "/etltest/samples/data/"
     self.test_file = self.test_dir + "dataMart/users_dim.yml"
     self.data_file = self.data_dir + "etlUnitTest/users.yml"
     self.maxDiff = None
    def test_fail_find_single_setting(self):
        """
        Testing that a setting that doesn't exist returns an error message.
        """
        given_result = SettingsManager().find_setting('Location', 'tests')
        expected_result = 'Setting does not exist or something went wrong.'

        self.assertEqual(given_result, expected_result)
    def test_no_system_variable_replace(self):
        """
        Testing that even if a variable is passed and it doesn't exist, it gets ignored.
        """
        parameter = "no_parameter/this_is_a_test/file.txt"
        given_result = SettingsManager().system_variable_replace(parameter)
        expected_result = "no_parameter/this_is_a_test/file.txt"

        self.assertEqual(given_result, expected_result)
    def test_copy_settings_file(self):
        """
        Testing that files are being copied properly with the copy_settings_file.
        """
        SettingsManager().copy_settings_file('copy.test')
        given_result = os.path.isfile(self.copy_file)
        expected_result = True

        self.assertEqual(given_result, expected_result)
    def test_find_single_setting(self):
        """
        Testing to ensure that a single setting is retrieved.
        """
        given_result = SettingsManager().find_setting('Locations', 'tests')
        expected_result = os.environ.get(
            'ETL_TEST_ROOT') + "/Documents/etlTest/tests"

        self.assertEqual(given_result, expected_result)
    def test_system_variable_replace(self):
        """
        Testing that variables in a setting value are replaced with their proper value.
        """
        parameter = "${ETL_TEST_ROOT}/this_is_a_test/file.txt"
        given_result = SettingsManager().system_variable_replace(parameter)
        expected_result = str(
            os.environ.get('ETL_TEST_ROOT')) + "/this_is_a_test/file.txt"

        self.assertEqual(given_result, expected_result)
    def test_bad_system_variable_replace(self):
        """
        Testing that if a variable being replaced doesn't exist, an error is thrown.
        """
        parameter = "${ETL_TEST_TOOT}/this_is_a_test/file.txt"
        expected_result = "The system variable either does not exist or has a bad value. System variable: ETL_TEST_TOOT"

        with self.assertRaises(Exception) as raises:
            SettingsManager().system_variable_replace(parameter)

        self.assertEqual(str(raises.exception), expected_result)
    def test_get_file_location(self):
        """
        Testing that get_file_location returns back the root directory for etlTest.
        """
        given_result = SettingsManager().get_file_location()
        expected_result = os.path.dirname(
            os.path.abspath(inspect.getfile(inspect.currentframe())))
        expected_result = re.sub(os.path.join('etltest', 'test', 'utilities'),
                                 '', expected_result)

        self.assertEqual(given_result, expected_result)
Exemplo n.º 10
0
 def test_get_tool(self):
     """
     Testing to ensure that etlTest gets only one Tool from the tool configuration file.
     """
     given_result = list(SettingsManager().get_tool('PDI'))
     expected_result = [
         'host_name', 'user_name', 'password', 'port', 'private_key',
         'tool_path', 'script_types', 'params', 'process_param',
         'code_path', 'logging_filename_format'
     ]
     self.assertCountEqual(given_result, expected_result)
Exemplo n.º 11
0
    def test_get_connections(self):
        """
        Testing to ensure that the data source connections match from the configuration file.
        :return:
        """
        given_result = SettingsManager().get_connections()
        expected_result = OrderedDict([('etlUnitTest',
                                        OrderedDict([
                                            ('__name__', 'etlUnitTest'),
                                            ('hostname', '127.0.0.1'),
                                            ('username', 'root'),
                                            ('password', ''), ('port', '3306'),
                                            ('type', 'mysql'),
                                            ('dbname', 'etlUnitTest')
                                        ]))])

        self.assertCountEqual(given_result, expected_result)
Exemplo n.º 12
0
    def test_get_config_settings(self):
        """
        Testing to see if the configuration settings are valid.
        """
        given_result = SettingsManager().get_settings()
        expected_result = OrderedDict([
            ('Locations',
             OrderedDict([
                 ('__name__', 'Locations'),
                 ('tests', '${ETL_TEST_ROOT}/Documents/etlTest/tests'),
                 ('data', '${ETL_TEST_ROOT}/Documents/etlTest/data'),
                 ('output', '${ETL_TEST_ROOT}/Documents/etlTest/output')
             ])),
            ('Results',
             OrderedDict([('__name__', 'Results'), ('verbose', 'True'),
                          ('failurerate', '10'), ('reporttype', 'Normal')]))
        ])

        self.assertCountEqual(given_result, expected_result)
Exemplo n.º 13
0
    def __init__(self, in_file=None, in_dir=None):
        """
            Initialization of method to setup the logging.
        """
        from .custom_logging import etltest_config, console

        self.log = logging.getLogger(name="YAMLParser")
        self.log.setLevel(etltest_config['logging_level'])
        self.log.addHandler(console)

        self.in_file = in_file
        self.in_dir = in_dir
        self.data_dir = SettingsManager().find_setting('Locations', 'data')

        if in_file is not None:
            self.read_file(self.in_file)

        if in_dir is not None:
            self.read_dir(self.in_dir)
Exemplo n.º 14
0
    def test_get_tools(self):
        """
        Testing to ensure that the tool configuration settings match the tool configuration file.
        """
        given_result = list(SettingsManager().get_tools())
        expected_result = [{
            'PDI': {
                'code_path':
                '${ETL_TEST_ROOT}/etltest/samples/etl',
                'script_types': [{
                    'script': 'kitchen.sh',
                    'type': 'job'
                }, {
                    'script': 'pan.sh',
                    'type': 'trans'
                }],
                'port':
                None,
                'password':
                None,
                'private_key':
                '~/.ssh/id_rsa',
                'process_param':
                '/file:',
                'user_name':
                None,
                'host_name':
                'localhost',
                'logging_filename_format':
                '${name}_%Y-%m-%d',
                'tool_path':
                '${TOOL_PATH}',
                'params':
                '/level: Detailed'
            }
        }]

        self.assertCountEqual(given_result, expected_result)