Exemplo n.º 1
0
    async def test_populate_should_add_translation_links(self,
                                                         m_retriever) -> None:
        entry_language = 'en'
        entry_name = 'Amsterdam'
        entry_title = 'Amsterdam'
        entry_content = 'Capitol of the Netherlands'
        entry = Entry(entry_language, entry_name, entry_title, entry_content)
        added_entry_language = 'nl'
        added_entry_name = 'Amsterdam'
        added_entry_title = 'Amsterdam'
        added_entry_content = 'Hoofdstad van Nederland'
        added_entry = Entry(added_entry_language, added_entry_name,
                            added_entry_title, added_entry_content)
        m_retriever.get_entry.side_effect = [entry, added_entry]

        m_retriever.get_translations.return_value = {
            entry_language: entry_name,
            added_entry_language: added_entry_name,
        }

        resource = IdentifiableSource('the_source', 'The Source')
        link_en = Link('https://en.wikipedia.org/wiki/Amsterdam')
        resource.links.add(link_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
                configuration.locales.clear()
                configuration.locales['en-US'] = LocaleConfiguration(
                    'en-US', 'en')
                configuration.locales['nl-NL'] = LocaleConfiguration(
                    'nl-NL', 'nl')
                async with App(configuration) as app:
                    app.ancestry.sources[resource.id] = resource
                    sut = _Populator(app, m_retriever)
                    await sut.populate()

        m_retriever.get_entry.assert_has_calls([
            call(entry_language, entry_name),
            call(added_entry_language, added_entry_name),
        ])
        m_retriever.get_translations.assert_called_once_with(
            entry_language, entry_name)
        self.assertEqual(2, len(resource.links))
        link_nl = resource.links.difference({link_en}).pop()
        self.assertEqual('Amsterdam', link_nl.label)
        self.assertEqual('nl', link_nl.locale)
        self.assertEqual(MediaType('text/html'), link_nl.media_type)
        self.assertIsNotNone(link_nl.description)
        self.assertEqual('external', link_nl.relationship)
Exemplo n.º 2
0
    async def test_populate_should_populate_existing_link(self, m_retriever) -> None:
        entry_language = 'en'
        entry_name = 'Amsterdam'
        entry_title = 'Amsterdam'
        entry_content = 'Capitol of the Netherlands'
        entry = Entry(entry_language, entry_name, entry_title, entry_content)
        m_retriever.get_entry.return_value = entry

        resource = Source('the_source', 'The Source')
        link = Link('https://en.wikipedia.org/wiki/Amsterdam')
        resource.links.add(link)
        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:
                    app.ancestry.entities.append(resource)
                    sut = _Populator(app, m_retriever)
                    await sut.populate()
        m_retriever.get_entry.assert_called_once_with(entry_language, entry_name)
        self.assertEqual(1, len(resource.links))
        self.assertEqual('Amsterdam', link.label)
        self.assertEqual('en', link.locale)
        self.assertEqual(MediaType('text/html'), link.media_type)
        self.assertIsNotNone(link.description)
        self.assertEqual('external', link.relationship)
Exemplo n.º 3
0
 async def test_populate_link_should_set_label(self, expected: str, label: Optional[str], m_retriever) -> None:
     link = Link('http://en.wikipedia.org/wiki/Amsterdam')
     link.label = label
     entry = Entry('en', 'The_city_of_Amsterdam', 'The city of Amsterdam', 'Amsterdam, such a lovely place!')
     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, 'en', entry)
     self.assertEqual(expected, link.label)
Exemplo n.º 4
0
 def test_content(self) -> None:
     content = 'Content for Amsterdam'
     sut = Entry('nl', 'Amsterdam', 'Title for Amsterdam', content)
     self.assertEquals(content, sut.content)
Exemplo n.º 5
0
 def test_title(self) -> None:
     title = 'Title for Amsterdam'
     sut = Entry('nl', 'Amsterdam', title, 'Content for Amsterdam')
     self.assertEquals(title, sut.title)
Exemplo n.º 6
0
 def test_url(self) -> None:
     sut = Entry('nl', 'Amsterdam', 'Title for Amsterdam', 'Content for Amsterdam')
     self.assertEquals('https://nl.wikipedia.org/wiki/Amsterdam', sut.url)