Add option for archiver full context
This commit is contained in:
parent
4be75fd48a
commit
6eeadc8821
4 changed files with 20 additions and 1 deletions
|
@ -50,6 +50,7 @@ _downloader_options = [
|
|||
|
||||
_archiver_options = [
|
||||
click.option('--all-comments', is_flag=True, default=None),
|
||||
click.option('--full-context', is_flag=True, default=None),
|
||||
click.option('-f', '--format', type=click.Choice(('xml', 'json', 'yaml')), default=None),
|
||||
]
|
||||
|
||||
|
|
|
@ -61,6 +61,9 @@ class Archiver(RedditConnector):
|
|||
raise ArchiverError(f'Factory failed to classify item of type {type(praw_item).__name__}')
|
||||
|
||||
def write_entry(self, praw_item: (praw.models.Submission, praw.models.Comment)):
|
||||
if self.args.full_context and isinstance(praw_item, praw.models.Comment):
|
||||
logger.debug(f'Converting comment {praw_item.id} to submission {praw_item.submission.id}')
|
||||
praw_item = praw_item.submission
|
||||
archive_entry = self._pull_lever_entry_factory(praw_item)
|
||||
if self.args.format == 'json':
|
||||
self._write_entry_json(archive_entry)
|
||||
|
|
|
@ -41,8 +41,9 @@ class Configuration(Namespace):
|
|||
self.verbose: int = 0
|
||||
|
||||
# Archiver-specific options
|
||||
self.format = 'json'
|
||||
self.all_comments = False
|
||||
self.format = 'json'
|
||||
self.full_context: bool = False
|
||||
|
||||
def process_click_arguments(self, context: click.Context):
|
||||
for arg_key in context.params.keys():
|
||||
|
|
|
@ -252,6 +252,20 @@ def test_cli_archive_all_user_comments(test_args: list[str], tmp_path: Path):
|
|||
assert result.exit_code == 0
|
||||
|
||||
|
||||
@pytest.mark.online
|
||||
@pytest.mark.reddit
|
||||
@pytest.mark.skipif(not does_test_config_exist, reason='A test config file is required for integration tests')
|
||||
@pytest.mark.parametrize('test_args', (
|
||||
['--full-context', '--link', 'gxqapql'],
|
||||
))
|
||||
def test_cli_archive_full_context(test_args: list[str], tmp_path: Path):
|
||||
runner = CliRunner()
|
||||
test_args = create_basic_args_for_archive_runner(test_args, tmp_path)
|
||||
result = runner.invoke(cli, test_args)
|
||||
assert result.exit_code == 0
|
||||
assert 'Converting comment' in result.output
|
||||
|
||||
|
||||
@pytest.mark.online
|
||||
@pytest.mark.reddit
|
||||
@pytest.mark.slow
|
||||
|
|
Loading…
Reference in a new issue