Пример #1
0
    def test_wrong_format_type(self, monkeypatch, tmpdir):
        def export_entry(self):
            return Response(200, None, b'123', 'application/epub')

        monkeypatch.setattr(ExportEntry, 'request', export_entry)

        command = ExportCommand(
            self.config,
            ExportCommandParams(10, FormatType.get('epub2'), PurePath(tmpdir)))
        result, msg = command.execute()

        assert result
        assert command.params.format == FormatType.get('json')
Пример #2
0
    def test_wrong_entry_id(self, values):
        result, msg = ExportCommand(
            self.config,
            ExportCommandParams(values[0], FormatType.get('json'))).execute()

        assert not result
        assert msg == values[1]
Пример #3
0
    def test_wrong_format_type(self, monkeypatch, tmpdir):
        command = ExportCommand(
            self.config,
            ExportCommandParams(10, FormatType.get('epub2'), PurePath(tmpdir)))
        result, msg = command.execute()

        assert not result
        assert msg == 'Unsupported type'
Пример #4
0
def export(ctx, entry_id, format, output, filename_with_id):
    """
    Export entry to file.

    Default output to current directory.
    """
    output = PurePath(output) if output else None
    format = FormatType.get(format)
    params = ExportCommandParams(entry_id, format, output)
    params.filename_with_id = filename_with_id
    run_command(ExportCommand(ctx.obj, params))
Пример #5
0
    def test_export(self, monkeypatch, tmp_path):
        def export_entry(self):
            return Response(200, None, b'123', 'application/epub')

        monkeypatch.setattr(ExportEntry, 'request', export_entry)

        params = ExportCommandParams(10, FormatType.get('epub'),
                                     PurePath(f'{tmp_path}/file.epub'))
        params.filename_with_id = False
        result, msg = ExportCommand(self.config, params).execute()
        assert result
        assert msg == f'Exported to: {tmp_path}/file.epub'
Пример #6
0
    def test_empty_output(self, monkeypatch, tmpdir):
        def export_entry(self):
            return Response(200, None, b'123', 'application/epub')

        monkeypatch.setattr(ExportEntry, 'request', export_entry)

        result, msg = ExportCommand(
            self.config,
            ExportCommandParams(10, FormatType.get('epub'),
                                PurePath(tmpdir))).execute()
        assert result
        assert re.search(f'Exported to: {PurePath(tmpdir)}/.+.epub', msg)
Пример #7
0
    def test_empty_output_cdisposition(self, monkeypatch):
        def export_entry(self):
            return Response(200, None, b'123', 'application/epub',
                            'attachment; filename="file.epub"')

        monkeypatch.setattr(ExportEntry, 'request', export_entry)

        result, msg = ExportCommand(
            self.config,
            ExportCommandParams(10, FormatType.get('epub'))).execute()
        assert result
        assert msg == f'Exported to: {Path.cwd()}/10. file.epub'

        os.remove(f'{Path.cwd()}/10. file.epub')
Пример #8
0
    def test_empty_output(self, monkeypatch, tmpdir):
        def export_entry(self):
            return Response(200, None, b'123', 'application/epub')

        def get_entry(self):
            return Response(
                200, '{"id": 10, "title": "title", "content": "content",\
                            "url": "url", "is_archived": 0, "is_starred": 1}')

        monkeypatch.setattr(ExportEntry, 'request', export_entry)
        monkeypatch.setattr(GetEntry, 'request', get_entry)

        result, msg = ExportCommand(
            self.config,
            ExportCommandParams(10, FormatType.get('epub'),
                                PurePath(tmpdir))).execute()
        assert result
        assert f'Exported to: {PurePath(tmpdir)}/10. title.epub' == msg
Пример #9
0
    The `browser` parameter should be one of this list:
    https://docs.python.org/3/library/webbrowser.html#webbrowser.register

    Example: open 10 -b w3m
    """
    run_command(
        OpenCommand(ctx.obj, OpenCommandParams(entry_id, open_original,
                                               browser)))


@cli.command(short_help="Export entry to file.")
@click.option('-o', '--output', help="Output directory or file name")
@click.option('-f',
              '--format',
              default=FormatType.JSON.name,
              type=click.Choice(FormatType.list(), case_sensitive=False),
              help="Export format")
@click.option('--filename-with-id/--filename-no-id',
              default=True,
              is_flag=True,
              help="Add id to filename")
@click.argument('entry_id', required=True)
@need_config
@click.pass_context
def export(ctx, entry_id, format, output, filename_with_id):
    """
    Export entry to file.

    Default output to current directory.
    """
    output = PurePath(output) if output else None