def do_test_get_settings(self,
                             event: dict = {},
                             gha: Optional[GithubAction] = None,
                             expected: Settings = get_settings.__func__(),
                             **kwargs):
        event = event.copy()
        with tempfile.TemporaryDirectory() as path:
            filepath = os.path.join(path, 'event.json')
            with open(filepath, 'wt', encoding='utf-8') as w:
                w.write(json.dumps(event))

            for key in ['GITHUB_EVENT_PATH', 'INPUT_GITHUB_EVENT_PATH']:
                if key in kwargs and kwargs[key]:
                    kwargs[key] = filepath

            options = dict(
                GITHUB_EVENT_PATH=filepath,
                GITHUB_EVENT_NAME='event name',
                GITHUB_API_URL='http://github.api.url/',  #defaults to github
                GITHUB_GRAPHQL_URL=
                'http://github.graphql.url/',  #defaults to github
                GITHUB_RETRIES='2',
                TEST_CHANGES_LIMIT='10',  # not an int
                CHECK_NAME='check name',  # defaults to 'Unit Test Results'
                GITHUB_TOKEN='token',
                GITHUB_REPOSITORY='repo',
                COMMIT='commit',  # defaults to get_commit_sha(event, event_name)
                FILES='files',
                COMMENT_TITLE='title',  # defaults to check name
                COMMENT_MODE='create new',  # true unless 'false'
                HIDE_COMMENTS='off',  # defaults to 'all but latest'
                REPORT_INDIVIDUAL_RUNS='true',  # false unless 'true'
                DEDUPLICATE_CLASSES_BY_FILE_NAME='true',  # false unless 'true'
                # annotations config tested in test_get_annotations_config*
                SECONDS_BETWEEN_GITHUB_READS='1.5',
                SECONDS_BETWEEN_GITHUB_WRITES='2.5',
            )
            options.update(**kwargs)
            for arg in kwargs:
                if arg.startswith('INPUT_'):
                    del options[arg[6:]]

            # simplify functionality of get_annotations_config
            annotations_config = options.get('CHECK_RUN_ANNOTATIONS').split(',') \
                if 'CHECK_RUN_ANNOTATIONS' in options else []
            with mock.patch('publish_unit_test_results.get_annotations_config',
                            return_value=annotations_config) as m:
                actual = get_settings(options, gha)
                m.assert_called_once_with(options, event)

            self.assertEqual(expected, actual)

            return options
示例#2
0
    def do_test_get_settings(self,
                             event: dict = {},
                             expected: Settings = get_settings.__func__(),
                             **kwargs):
        with tempfile.TemporaryDirectory() as path:
            filepath = os.path.join(path, 'event.json')
            with open(filepath, 'wt') as w:
                w.write(json.dumps(event))

            for key in ['GITHUB_EVENT_PATH', 'INPUT_GITHUB_EVENT_PATH']:
                if key in kwargs and kwargs[key]:
                    kwargs[key] = filepath

            options = dict(
                GITHUB_EVENT_PATH=filepath,
                GITHUB_EVENT_NAME='event name',
                GITHUB_API_URL='http://github.api.url/',  #defaults to github
                TEST_CHANGES_LIMIT='10',  # not an int
                CHECK_NAME='check name',  # defaults to 'Unit Test Results'
                GITHUB_TOKEN='token',
                GITHUB_REPOSITORY='repo',
                COMMIT='commit',  # defaults to get_commit_sha(event, event_name)
                FILES='files',
                COMMENT_TITLE='title',  # defaulst to check name
                COMMENT_ON_PR='true',  # true unless 'false'
                HIDE_COMMENTS='off',  # defaults to 'all but latest'
                REPORT_INDIVIDUAL_RUNS='true',  # false unless 'true'
                DEDUPLICATE_CLASSES_BY_FILE_NAME='true',  # false unless 'true'
                # annotations config tested in test_get_annotations_config*
            )
            options.update(**kwargs)
            for arg in kwargs:
                if arg.startswith('INPUT_'):
                    del options[arg[6:]]

            with mock.patch('publish_unit_test_results.get_annotations_config',
                            return_value=[]) as m:
                actual = get_settings(options)
                m.assert_called_once_with(options, event)

            self.assertEqual(expected, actual)

            return options