def test_entry_html_content_with_annotations_multiline(self, monkeypatch): def request(self): return Response(200, ('{"id": 1, "title": "title", "content":' '"<h1>header text</h1>content<p>end anno</p>",' '"url": "url", "is_archived": 0, "is_starred": 1,' '"annotations":[{' '"user": "******", "annotator_schema_version":' ' "v1.0", "id": 1, "text": "content", ' '"created_at": "2020-10-28T10:50:51+0000", ' '"updated_at": "2020-10-28T10:50:51+0000", ' '"quote": "quote", "ranges": ' '[{"start": "/h1", "startOffset": "2", ' '"end": "/p", "endOffset": "4"}]}]}')) monkeypatch.setattr(GetEntry, 'request', request) params = ShowCommandParams(1, html=False, colors=True, image_links=True) params.width = '100%' result, output = ShowCommand(self.config, params).execute() assert result assert output == (f'title\n{"="*ShowCommand.FAILWIDTH}\n\n\n' f'{Fore.BLUE}he{Back.CYAN}ader text' f'{Fore.RESET}\ncontent\n\nend {Back.RESET} [1]anno')
def show(ctx, entry_id, color, html, raw, width, alignment, image_links): """ Show the text of an entry. The ENTRY_ID can be found with `list` command. """ params = ShowCommandParams(entry_id, color, html, raw, image_links) params.width = width params.align = Alignment.get(alignment) run_command(ShowCommand(ctx.obj, params))
def test_entry_not_exist(self, monkeypatch): def request(self): response = Response(404, None) raise RequestException( response.error_text, response.error_description) monkeypatch.setattr(GetEntry, 'request', request) result, output = ShowCommand( self.config, ShowCommandParams(1000)).execute() assert not result assert output == "Error: 404: API was not found."
def test_entry_content(self, monkeypatch): def request(self): return Response( 200, '{"id": 1, "title": "title", "content": "content",\ "url": "url", "is_archived": 0, "is_starred": 1}') monkeypatch.setattr(GetEntry, 'request', request) params = ShowCommandParams(1) params.width = '100%' result, output = ShowCommand(self.config, params).execute() assert result assert output == f'title\n{"="*ShowCommand.FAILWIDTH}\ncontent'
def test_custom_width(self, monkeypatch, values): def request(self): return Response( 200, '{"id": 1, "title": "title", "content": "content",\ "url": "url", "is_archived": 0, "is_starred": 1}') monkeypatch.setattr(GetEntry, 'request', request) params = ShowCommandParams(1) params.width = values[0] result, output = ShowCommand(self.config, params).execute() assert result assert output == (f'{values[1]}title\n{values[1]}' f'{values[2]}\n{values[1]}content')
def test_entry_html_strip_content_with_colors(self, monkeypatch): def request(self): return Response( 200, '{"id": 1, "title": "title", "content": "<h1>head</h1>content",\ "url": "url", "is_archived": 0, "is_starred": 1}') monkeypatch.setattr(GetEntry, 'request', request) params = ShowCommandParams(1, html=False, colors=True) params.width = '100%' result, output = ShowCommand(self.config, params).execute() assert result assert output == (f'title\n{"="*ShowCommand.FAILWIDTH}\n\n\n' f'{Fore.BLUE}head{Fore.RESET}\ncontent')
def test_entry_html_content(self, monkeypatch): def request(self): return Response( 200, '{"id": 1, "title": "title", "content": "content",\ "url": "url", "is_archived": 0, "is_starred": 1}') monkeypatch.setattr(GetEntry, 'request', request) params = ShowCommandParams(1, type=ScreenType.HTML) params.width = '100%' result, output = ShowCommand(self.config, params).execute() assert result assert output == ( '<h1>title</h1>\n' 'content')
def test_entry_html_image_content(self, monkeypatch): def request(self): return Response( 200, '{"id": 1, "title": "title", "content":\ "<h1>head</h1>content<img alt=\\"Message desc\\"\ src=\\"https://imag.es/1.jpg\\" />",\ "url": "url", "is_archived": 0, "is_starred": 1}') monkeypatch.setattr(GetEntry, 'request', request) params = ShowCommandParams(1, html=False, colors=False) params.width = '100%' result, output = ShowCommand(self.config, params).execute() assert result assert output == (f'title\n{"="*ShowCommand.FAILWIDTH}\n\n\n' 'head\ncontent [IMAGE "Message desc"]')
def test_entry_markdown(self, monkeypatch): def request(self): return Response( 200, '{"id": 1, "title": "title", "content": "<h2>Sub title</h2><p>content<p>",\ "url": "url", "is_archived": 0, "is_starred": 1}') monkeypatch.setattr(GetEntry, 'request', request) params = ShowCommandParams(1, type=ScreenType.MARKDOWN) params.width = '100%' result, output = ShowCommand(self.config, params).execute() assert result assert output == ( '# title\n' '## Sub title\n\n' 'content\n')