async def test_populate_link_should_set_description(self, expected: str, description: str, m_retriever) -> None: link = Link('http://en.wikipedia.org/wiki/Amsterdam') link.description = description entry_language = 'en' with TemporaryDirectory() as output_directory_path: with TemporaryDirectory() as cache_directory_path: configuration = Configuration( output_directory_path, 'https://example.com') configuration.cache_directory_path = cache_directory_path async with App(configuration) as app: sut = _Populator(app, m_retriever) await sut.populate_link(link, entry_language) self.assertEqual(expected, link.description)
async def populate_link(self, link: Link, entry_language: str, entry: Optional[Entry] = None) -> None: if link.url.startswith('http:'): link.url = 'https:' + link.url[5:] if link.media_type is None: link.media_type = MediaType('text/html') if link.relationship is None: link.relationship = 'external' if link.locale is None: link.locale = entry_language if link.description is None: # There are valid reasons for links in locales that aren't supported. with suppress(ValueError): async with self._app.with_locale(link.locale): link.description = _('Read more on Wikipedia.') if entry is not None and link.label is None: link.label = entry.title