def test_empty_list(self, empty_module_hierarchy):
        """Test a config where the value is an empty list"""

        config = ZigZagConfig(empty_module_hierarchy, {})
        expected_message = "The config setting 'module_hierarchy' was not found in the config file"

        with pytest.raises(ZigZagConfigError, match=expected_message):
            config.get_config('module_hierarchy')
    def test_access_config_not_present(self, config_with_interpolation):
        """Test that we will raise error if value defined in config
        is not present in the global properties"""

        properties = {}
        config = ZigZagConfig(config_with_interpolation, properties)
        expected_message = "The config setting 'path_to_test_exec_dir' was not found in the config file"

        with pytest.raises(ZigZagConfigError, match=expected_message):
            config.get_config('path_to_test_exec_dir')
    def test_list_value_containing_empty_value(self,
                                               module_hierarchy_two_nodes):
        """Test a config where a list contains an empty string"""

        properties = {'NODE_ONE': 'FOO'}  # do not supply NODE_TWO
        config = ZigZagConfig(module_hierarchy_two_nodes, properties)
        expected_message = 'The config module_hierarchy contained an empty value'

        with pytest.raises(ZigZagConfigError, match=expected_message):
            config.get_config('module_hierarchy')
    def test_zz_testcase_class_variable(self, config_with_zz_variable, mocker):
        """Test that we can use the 'zz_testcase_class' special variable
        in a ZigZag config"""

        # Mock
        zz_test_log = mocker.MagicMock()
        zz_test_log.classname = 'this.is.the.classname'

        properties = {}
        config = ZigZagConfig(config_with_zz_variable, properties)
        assert ['one', 'two', zz_test_log.classname
                ] == config.get_config('module_hierarchy', zz_test_log)
    def test_asc_failure_link(self, asc_zigzag_config_file, mocker):
        """Validate when configured with a config file similar to the one used by the asc-team"""

        molecule_test_repo = 'molecule-validate-neutron-deploy'
        molecule_scenario_name = 'default'
        testsuite_props = {
            'REPO_URL': 'https://github.com/rcbops/rpc-openstack',
            'MOLECULE_GIT_COMMIT': SHA,
            'MOLECULE_TEST_REPO': molecule_test_repo,
            'MOLECULE_SCENARIO_NAME': molecule_scenario_name,
        }

        # mock
        zz = mocker.MagicMock()
        zztl = mocker.MagicMock()
        zztl._mediator = zz

        zztl.test_file = TEST_FILE
        zztl.failure_output = 'This property contains truncated content......'
        zztl.full_failure_output = FAILURE_OUTPUT

        zz.config_dict = ZigZagConfig(asc_zigzag_config_file, testsuite_props)

        lgf = LinkGenerationFacade(zz)
        failure_link = lgf.github_testlog_failure_link(zztl)
        assert failure_link == ('https://github.com/'
                                'rcbops/'
                                '{}/'
                                'tree/{}/'
                                'molecule/{}/tests/'
                                '{}#L{}'.format(molecule_test_repo, SHA,
                                                molecule_scenario_name,
                                                TEST_FILE, LINE_NUMBER))
    def test_mk8s_pr_testing(self, mk8s_zigzag_config_file, mocker):
        """Validate when configured with a config file similar to the one used by the mk8s-team testing a PR"""
        change_branch = 'asc-123/master/this_is_my_feature'
        change_fork = 'zreichert'

        zz = mocker.MagicMock()
        testsuite_props = {
            'GIT_URL': 'https://github.com/rcbops/mk8s.git',
            'GIT_COMMIT': SHA,
            'CHANGE_BRANCH': change_branch,
            'CHANGE_FORK': change_fork,
        }

        zztl = mocker.MagicMock()
        zztl.test_file = TEST_FILE
        zztl.failure_output = 'This property contains truncated content......'
        zztl.full_failure_output = FAILURE_OUTPUT

        zz.config_dict = ZigZagConfig(mk8s_zigzag_config_file, testsuite_props)

        lgf = LinkGenerationFacade(zz)
        failure_link = lgf.github_testlog_failure_link(zztl)
        assert failure_link == ('https://github.com/'
                                '{}/'
                                'mk8s/'
                                'tree/{}/'
                                'tools/installer/tests/'
                                '{}#L{}'.format(change_fork, SHA, TEST_FILE,
                                                LINE_NUMBER))
    def test_asc_file_link(self, asc_zigzag_config_file, mocker):
        """Validate fallback to file with no line number"""

        molecule_test_repo = 'molecule-validate-neutron-deploy'
        molecule_scenario_name = 'default'
        testsuite_props = {
            'REPO_URL': 'https://github.com/rcbops/rpc-openstack',
            'MOLECULE_GIT_COMMIT': SHA,
            'MOLECULE_TEST_REPO': molecule_test_repo,
            'MOLECULE_SCENARIO_NAME': molecule_scenario_name,
        }

        # Mock
        zz = mocker.MagicMock()
        zztl = mocker.MagicMock()

        zztl.test_file = TEST_FILE
        zztl.failure_output = 'This property contains truncated content......'
        zztl.full_failure_output = 'I dont contain an assert message'
        zztl.def_line_number = ''

        zz.config_dict = ZigZagConfig(asc_zigzag_config_file, testsuite_props)

        lgf = LinkGenerationFacade(zz)
        failure_link = lgf.github_testlog_failure_link(zztl)
        assert failure_link == ('https://github.com/'
                                'rcbops/'
                                '{}/'
                                'tree/{}/'
                                'molecule/{}/tests/'
                                '{}'.format(molecule_test_repo, SHA,
                                            molecule_scenario_name, TEST_FILE))
    def test_missing_required_config(self, config_missing_project_id_key):
        """Provide json that should not pass the validation"""
        properties = {}
        expected_message = "'project_id' is a required property"

        with pytest.raises(ZigZagConfigError, match=expected_message):
            ZigZagConfig(config_missing_project_id_key, properties)
    def test_config_not_json(self, invalid_zigzag_config_file):
        """Test that we will raise error if value defined in config
        is not present in the global properties"""

        properties = {}
        expected_message = 'config file is not valid JSON'
        with pytest.raises(ZigZagConfigError, match=expected_message):
            ZigZagConfig(invalid_zigzag_config_file, properties)
Example #10
0
    def config_dict(self):
        """Gets the config dictionary

        Returns:
             ZigZagConfig: The zigzag config dictionary
        """

        if self._config_dict is None:
            self._config_dict = ZigZagConfig(self._config_file,
                                             self.testsuite_props)
        return self._config_dict
    def test_asc_missing_data(self, asc_zigzag_config_file, mocker):
        """Failure link should be None when it cant be calculated"""
        zz = mocker.MagicMock()

        zztl = mocker.MagicMock()
        zztl.test_file = TEST_FILE
        zztl.failure_output = 'This property contains truncated content......'
        zztl.full_failure_output = FAILURE_OUTPUT

        zz.config_dict = ZigZagConfig(asc_zigzag_config_file, {})

        lgf = LinkGenerationFacade(zz)
        failure_link = lgf.github_testlog_failure_link(zztl)
        assert failure_link is None
    def test_mk8s_master_branch(self, mk8s_zigzag_config_file, mocker):
        """Validate when configured with a config file similar to the one used by the mk8s-team"""

        zz = mocker.MagicMock()
        testsuite_props = {
            'GIT_URL': 'https://github.com/rcbops/mk8s.git',
            'GIT_COMMIT': SHA,
        }

        zztl = mocker.MagicMock()
        zztl.test_file = TEST_FILE
        zztl.failure_output = 'This property contains truncated content......'
        zztl.full_failure_output = FAILURE_OUTPUT

        zz.config_dict = ZigZagConfig(mk8s_zigzag_config_file, testsuite_props)

        lgf = LinkGenerationFacade(zz)
        failure_link = lgf.github_testlog_failure_link(zztl)
        assert failure_link == ('https://github.com/'
                                'rcbops/'
                                'mk8s/'
                                'tree/{}/'
                                'tools/installer/tests/'
                                '{}#L{}'.format(SHA, TEST_FILE, LINE_NUMBER))
Example #13
0
    def test_pull_value_from_properties(self, config_with_interpolation):
        """Test that we can interpolate one value successfully"""

        properties = {'FOO': '/Hello/is/it/me/youre/looking/for'}
        config = ZigZagConfig(config_with_interpolation, properties)
        assert properties['FOO'] == config.get_config('path_to_test_exec_dir')