def get_generator(self): category = Category("misc", self.settings) podcast_articles = [ get_article( "podcast title", "podcast cocntent", podcast="http://example.com/audio/test.mp3", category=category, date=datetime.datetime.now(), length="120", duration="120", ), get_article( "podcast title", "podcast cocntent", podcast="http://example.com/audio/test.mp3", category=category, date=datetime.datetime.now(), length="120", duration="120", ), ] context = get_context(**self.settings) context["articles"] = podcast_articles generator = PodcastFeedGenerator( context=context, settings=self.settings, path=self.temp_content, theme="", output_path=self.temp_output, ) generator.generate_context() return generator
def test_process_translations(self): fr_articles = [] en_articles = [] # create a bunch of articles # 0: no translation metadata fr_articles.append(get_article(lang='fr', slug='yay0', title='Titre', content='en français')) en_articles.append(get_article(lang='en', slug='yay0', title='Title', content='in english')) # 1: translation metadata on default lang fr_articles.append(get_article(lang='fr', slug='yay1', title='Titre', content='en français')) en_articles.append(get_article(lang='en', slug='yay1', title='Title', content='in english', extra_metadata={'translation': 'true'})) # 2: translation metadata not on default lang fr_articles.append(get_article(lang='fr', slug='yay2', title='Titre', content='en français', extra_metadata={'translation': 'true'})) en_articles.append(get_article(lang='en', slug='yay2', title='Title', content='in english')) # 3: back to default language detection if all items have the # translation metadata fr_articles.append(get_article(lang='fr', slug='yay3', title='Titre', content='en français', extra_metadata={'translation': 'yep'})) en_articles.append(get_article(lang='en', slug='yay3', title='Title', content='in english', extra_metadata={'translation': 'yes'})) # try adding articles in both orders for lang0_articles, lang1_articles in ((fr_articles, en_articles), (en_articles, fr_articles)): articles = lang0_articles + lang1_articles index, trans = utils.process_translations(articles) self.assertIn(en_articles[0], index) self.assertIn(fr_articles[0], trans) self.assertNotIn(en_articles[0], trans) self.assertNotIn(fr_articles[0], index) self.assertIn(fr_articles[1], index) self.assertIn(en_articles[1], trans) self.assertNotIn(fr_articles[1], trans) self.assertNotIn(en_articles[1], index) self.assertIn(en_articles[2], index) self.assertIn(fr_articles[2], trans) self.assertNotIn(en_articles[2], trans) self.assertNotIn(fr_articles[2], index) self.assertIn(en_articles[3], index) self.assertIn(fr_articles[3], trans) self.assertNotIn(en_articles[3], trans) self.assertNotIn(fr_articles[3], index)
def test_generate_context(self): settings = self.settings.copy() settings["PODCAST_FEED_PATH"] = PODCAST_FEED_PATH article = get_article("title", "cocntent") podcast_article = get_article( "podcast title", "podcast cocntent", podcast="aaa.mp3" ) context = get_context(settings) context["articles"] = [article, podcast_article] generator = PodcastFeedGenerator( settings=settings, context=context, path=None, theme=settings["THEME"], output_path=None, ) generator.generate_context() self.assertEqual(1, len(generator.episodes))
def test_process_translations(self): # create a bunch of articles # 1: no translation metadata fr_article1 = get_article(lang='fr', slug='yay', title='Un titre', content='en français') en_article1 = get_article(lang='en', slug='yay', title='A title', content='in english') # 2: reverse which one is the translation thanks to metadata fr_article2 = get_article(lang='fr', slug='yay2', title='Un titre', content='en français') en_article2 = get_article(lang='en', slug='yay2', title='A title', content='in english', extra_metadata={'translation': 'true'}) # 3: back to default language detection if all items have the # translation metadata fr_article3 = get_article(lang='fr', slug='yay3', title='Un titre', content='en français', extra_metadata={'translation': 'yep'}) en_article3 = get_article(lang='en', slug='yay3', title='A title', content='in english', extra_metadata={'translation': 'yes'}) articles = [ fr_article1, en_article1, fr_article2, en_article2, fr_article3, en_article3 ] index, trans = utils.process_translations(articles) self.assertIn(en_article1, index) self.assertIn(fr_article1, trans) self.assertNotIn(en_article1, trans) self.assertNotIn(fr_article1, index) self.assertIn(fr_article2, index) self.assertIn(en_article2, trans) self.assertNotIn(fr_article2, trans) self.assertNotIn(en_article2, index) self.assertIn(en_article3, index) self.assertIn(fr_article3, trans) self.assertNotIn(en_article3, trans) self.assertNotIn(fr_article3, index)
def test_process_translations(self): # create a bunch of articles # 1: no translation metadata fr_article1 = get_article(lang='fr', slug='yay', title='Un titre', content='en français') en_article1 = get_article(lang='en', slug='yay', title='A title', content='in english') # 2: reverse which one is the translation thanks to metadata fr_article2 = get_article(lang='fr', slug='yay2', title='Un titre', content='en français') en_article2 = get_article(lang='en', slug='yay2', title='A title', content='in english', extra_metadata={'translation': 'true'}) # 3: back to default language detection if all items have the # translation metadata fr_article3 = get_article(lang='fr', slug='yay3', title='Un titre', content='en français', extra_metadata={'translation': 'yep'}) en_article3 = get_article(lang='en', slug='yay3', title='A title', content='in english', extra_metadata={'translation': 'yes'}) articles = [fr_article1, en_article1, fr_article2, en_article2, fr_article3, en_article3] index, trans = utils.process_translations(articles) self.assertIn(en_article1, index) self.assertIn(fr_article1, trans) self.assertNotIn(en_article1, trans) self.assertNotIn(fr_article1, index) self.assertIn(fr_article2, index) self.assertIn(en_article2, trans) self.assertNotIn(fr_article2, trans) self.assertNotIn(en_article2, index) self.assertIn(en_article3, index) self.assertIn(fr_article3, trans) self.assertNotIn(en_article3, trans) self.assertNotIn(fr_article3, index)
def test_process_translations(self): # create a bunch of articles # 1: no translation metadata fr_article1 = get_article(lang="fr", slug="yay", title="Un titre", content="en français") en_article1 = get_article(lang="en", slug="yay", title="A title", content="in english") # 2: reverse which one is the translation thanks to metadata fr_article2 = get_article(lang="fr", slug="yay2", title="Un titre", content="en français") en_article2 = get_article( lang="en", slug="yay2", title="A title", content="in english", extra_metadata={"translation": "true"} ) # 3: back to default language detection if all items have the # translation metadata fr_article3 = get_article( lang="fr", slug="yay3", title="Un titre", content="en français", extra_metadata={"translation": "yep"} ) en_article3 = get_article( lang="en", slug="yay3", title="A title", content="in english", extra_metadata={"translation": "yes"} ) articles = [fr_article1, en_article1, fr_article2, en_article2, fr_article3, en_article3] index, trans = utils.process_translations(articles) self.assertIn(en_article1, index) self.assertIn(fr_article1, trans) self.assertNotIn(en_article1, trans) self.assertNotIn(fr_article1, index) self.assertIn(fr_article2, index) self.assertIn(en_article2, trans) self.assertNotIn(fr_article2, trans) self.assertNotIn(en_article2, index) self.assertIn(en_article3, index) self.assertIn(fr_article3, trans) self.assertNotIn(en_article3, trans) self.assertNotIn(fr_article3, index)
def test_process_translations(self): fr_articles = [] en_articles = [] # create a bunch of articles # 0: no translation metadata fr_articles.append( get_article(lang='fr', slug='yay0', title='Titre', content='en français')) en_articles.append( get_article(lang='en', slug='yay0', title='Title', content='in english')) # 1: translation metadata on default lang fr_articles.append( get_article(lang='fr', slug='yay1', title='Titre', content='en français')) en_articles.append( get_article(lang='en', slug='yay1', title='Title', content='in english', translation='true')) # 2: translation metadata not on default lang fr_articles.append( get_article(lang='fr', slug='yay2', title='Titre', content='en français', translation='true')) en_articles.append( get_article(lang='en', slug='yay2', title='Title', content='in english')) # 3: back to default language detection if all items have the # translation metadata fr_articles.append( get_article(lang='fr', slug='yay3', title='Titre', content='en français', translation='yep')) en_articles.append( get_article(lang='en', slug='yay3', title='Title', content='in english', translation='yes')) # 4-5: translation pairs with the same slug but different category fr_articles.append( get_article(lang='fr', slug='yay4', title='Titre', content='en français', category='foo')) en_articles.append( get_article(lang='en', slug='yay4', title='Title', content='in english', category='foo')) fr_articles.append( get_article(lang='fr', slug='yay4', title='Titre', content='en français', category='bar')) en_articles.append( get_article(lang='en', slug='yay4', title='Title', content='in english', category='bar')) # try adding articles in both orders for lang0_articles, lang1_articles in ((fr_articles, en_articles), (en_articles, fr_articles)): articles = lang0_articles + lang1_articles # test process_translations with falsy translation_id index, trans = utils.process_translations(articles, translation_id=None) for i in range(6): for lang_articles in [en_articles, fr_articles]: self.assertIn(lang_articles[i], index) self.assertNotIn(lang_articles[i], trans) # test process_translations with simple and complex translation_id for translation_id in ['slug', {'slug', 'category'}]: index, trans = utils.process_translations( articles, translation_id=translation_id) for a in [ en_articles[0], fr_articles[1], en_articles[2], en_articles[3], en_articles[4], en_articles[5] ]: self.assertIn(a, index) self.assertNotIn(a, trans) for a in [ fr_articles[0], en_articles[1], fr_articles[2], fr_articles[3], fr_articles[4], fr_articles[5] ]: self.assertIn(a, trans) self.assertNotIn(a, index) for i in range(6): self.assertIn(en_articles[i], fr_articles[i].translations) self.assertIn(fr_articles[i], en_articles[i].translations) for a_arts in [en_articles, fr_articles]: for b_arts in [en_articles, fr_articles]: if translation_id == 'slug': self.assertIn(a_arts[4], b_arts[5].translations) self.assertIn(a_arts[5], b_arts[4].translations) elif translation_id == {'slug', 'category'}: self.assertNotIn(a_arts[4], b_arts[5].translations) self.assertNotIn(a_arts[5], b_arts[4].translations)
def test_process_translations(self): fr_articles = [] en_articles = [] # create a bunch of articles # 0: no translation metadata fr_articles.append(get_article(lang='fr', slug='yay0', title='Titre', content='en français')) en_articles.append(get_article(lang='en', slug='yay0', title='Title', content='in english')) # 1: translation metadata on default lang fr_articles.append(get_article(lang='fr', slug='yay1', title='Titre', content='en français')) en_articles.append(get_article(lang='en', slug='yay1', title='Title', content='in english', translation='true')) # 2: translation metadata not on default lang fr_articles.append(get_article(lang='fr', slug='yay2', title='Titre', content='en français', translation='true')) en_articles.append(get_article(lang='en', slug='yay2', title='Title', content='in english')) # 3: back to default language detection if all items have the # translation metadata fr_articles.append(get_article(lang='fr', slug='yay3', title='Titre', content='en français', translation='yep')) en_articles.append(get_article(lang='en', slug='yay3', title='Title', content='in english', translation='yes')) # 4-5: translation pairs with the same slug but different category fr_articles.append(get_article(lang='fr', slug='yay4', title='Titre', content='en français', category='foo')) en_articles.append(get_article(lang='en', slug='yay4', title='Title', content='in english', category='foo')) fr_articles.append(get_article(lang='fr', slug='yay4', title='Titre', content='en français', category='bar')) en_articles.append(get_article(lang='en', slug='yay4', title='Title', content='in english', category='bar')) # try adding articles in both orders for lang0_articles, lang1_articles in ((fr_articles, en_articles), (en_articles, fr_articles)): articles = lang0_articles + lang1_articles # test process_translations with falsy translation_id index, trans = utils.process_translations( articles, translation_id=None) for i in range(6): for lang_articles in [en_articles, fr_articles]: self.assertIn(lang_articles[i], index) self.assertNotIn(lang_articles[i], trans) # test process_translations with simple and complex translation_id for translation_id in ['slug', {'slug', 'category'}]: index, trans = utils.process_translations( articles, translation_id=translation_id) for a in [en_articles[0], fr_articles[1], en_articles[2], en_articles[3], en_articles[4], en_articles[5]]: self.assertIn(a, index) self.assertNotIn(a, trans) for a in [fr_articles[0], en_articles[1], fr_articles[2], fr_articles[3], fr_articles[4], fr_articles[5]]: self.assertIn(a, trans) self.assertNotIn(a, index) for i in range(6): self.assertIn(en_articles[i], fr_articles[i].translations) self.assertIn(fr_articles[i], en_articles[i].translations) for a_arts in [en_articles, fr_articles]: for b_arts in [en_articles, fr_articles]: if translation_id == 'slug': self.assertIn(a_arts[4], b_arts[5].translations) self.assertIn(a_arts[5], b_arts[4].translations) elif translation_id == {'slug', 'category'}: self.assertNotIn(a_arts[4], b_arts[5].translations) self.assertNotIn(a_arts[5], b_arts[4].translations)