Пример #1
0
    def test_init(self, mock_shared, mock_xml, mock_json, mock_subprocess,
                  mock_log):
        """test ___init__ with filetype and check correct script finder
        picked """

        mock_json.return_value = {'name1': ['script1'], 'name2': ['script2']}
        mock_xml.return_value = {'name3': ['script3'], 'name4': ['script4']}
        mock_shared.return_value = {'name5': ['script5'], 'name6': ['script6']}

        enum_json = enum_json_config_plugin.EnumJson('path')
        ifcs_xml = shared_ifcs_config_plugin.SharedIfcsXml('path')
        shared_config = shared_config_config_plugin.SharedConfig('path')
        random_config = TestClass('path')

        # this is done to provide coverage on the __str__ function
        print random_config

        enum_fake_scripts = [['script1'], ['script2']]
        ifcs_fake_scripts = [['script3'], ['script4']]
        shared_fake_scripts = [['script5'], ['script6']]

        enum_fake_names = ['name1', 'name2']
        ifcs_fake_names = ['name3', 'name4']
        shared_fake_names = ['name5', 'name6']

        self.assertItemsEqual(enum_json.scripts.values(), enum_fake_scripts)
        self.assertItemsEqual(ifcs_xml.scripts.values(), ifcs_fake_scripts)
        self.assertItemsEqual(shared_config.scripts.values(),
                              shared_fake_scripts)
        self.assertEqual(random_config.scripts, {})

        self.assertItemsEqual(enum_json.scripts.keys(), enum_fake_names)
        self.assertItemsEqual(ifcs_xml.scripts.keys(), ifcs_fake_names)
        self.assertItemsEqual(shared_config.scripts.keys(), shared_fake_names)
Пример #2
0
    def test_validate_fails(self, mock_subprocess, mock_log):
        """use ConfigType.validate and get subprocess to raise a exception and
         check log reports this and failed scripts is not empty"""
        shared_config = shared_config_config_plugin.SharedConfig('path')
        shared_config.scripts = {'name1': ['script1'], 'name2': ['script2']}
        validation_error = subprocess.CalledProcessError('A', 'B')
        validation_error.output = "ERROR: Something went wrong"

        # The first validation script passes, the second raises an exception
        mock_subprocess.side_effect = ["", validation_error]

        # possibly want to run this within assertRaises check as well
        answer = shared_config.validate()

        self.assertListEqual(answer[0], ['name1'])
        self.assertIs(mock_subprocess.call_count, 2)
Пример #3
0
    def test_unified_diff(self):
        """tests that the unified diff is used for json and xml files but not for others"""

        # Test one type of each config - json, xml and shared_config
        shared_config = shared_config_config_plugin.SharedConfig('path')
        scscf_json = scscf_json_config_plugin.ScscfJson('path')
        fallback_ifcs = fallback_ifcs_config_plugin.FallbackIfcsXml('path')

        answer = shared_config.use_unified_diff()
        self.assertIs(answer, False)

        answer = scscf_json.use_unified_diff()
        self.assertIs(answer, True)

        answer = fallback_ifcs.use_unified_diff()
        self.assertIs(answer, True)
Пример #4
0
    def test_executable_only(self, mock_subprocess, mock_listdir, mock_access):
        """Check that we only try to run those scripts that are executable."""

        # Make only one of the scripts executable.
        mock_access.side_effect = [True, False]

        shared_config = shared_config_config_plugin.SharedConfig(
            self.config_location)
        shared_config.validate()

        # Check that only the executable script is run.
        self.assertEqual(len(mock_subprocess.call_args_list), 1)
        self.assertEqual(
            mock.call([
                os.path.join(
                    config_type_class_plugin.VALIDATION_SCRIPTS_FOLDER,
                    "clearwater-core-validate-config"), self.config_location
            ],
                      stderr=-2), mock_subprocess.call_args_list[0])
Пример #5
0
    def test_scripts_find_ok(self, mock_subprocess, mock_listdir, mock_access):
        """Check that we run the validation scripts we find in the relevant
        folder."""

        shared_config = shared_config_config_plugin.SharedConfig(
            self.config_location)

        shared_config.validate()

        self.assertIs(mock_listdir.call_count, 1)
        # Each script should be executed.
        self.assertEqual(len(mock_subprocess.call_args_list), 2)
        # We should be calling the default config validation script here.
        self.assertEqual(
            mock.call([
                os.path.join(
                    config_type_class_plugin.VALIDATION_SCRIPTS_FOLDER,
                    "clearwater-core-validate-config"), self.config_location
            ],
                      stderr=-2), mock_subprocess.call_args_list[0])