当前位置: 首页>>代码示例>>Python>>正文


Python Article.get_available_language_codes方法代码示例

本文整理汇总了Python中wikipendium.wiki.models.Article.get_available_language_codes方法的典型用法代码示例。如果您正苦于以下问题:Python Article.get_available_language_codes方法的具体用法?Python Article.get_available_language_codes怎么用?Python Article.get_available_language_codes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wikipendium.wiki.models.Article的用法示例。


在下文中一共展示了Article.get_available_language_codes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ArticleTest

# 需要导入模块: from wikipendium.wiki.models import Article [as 别名]
# 或者: from wikipendium.wiki.models.Article import get_available_language_codes [as 别名]

#.........这里部分代码省略.........
        self.article1.save()
        self.article2 = Article(slug=u'TIØ4258')
        self.article2.save()
        self.ac1 = ArticleContent(article=self.article1,
                                  updated=datetime.datetime(2012, 1, 1))
        self.ac2 = ArticleContent(article=self.article1,
                                  updated=datetime.datetime(2013, 1, 1),
                                  title='per')
        self.ac3 = ArticleContent(article=self.article2,
                                  updated=datetime.datetime(2001, 3, 7))
        self.ac4 = ArticleContent(article=self.article2,
                                  updated=datetime.datetime(2001, 3, 8),
                                  lang='nb')
        self.ac1.edited_by = self.u1
        self.ac2.edited_by = self.u2
        self.ac3.edited_by = self.u1
        self.ac4.edited_by = self.u2
        self.ac1.save()
        self.ac2.save()
        self.ac3.save()
        self.ac4.save()

    def test_slug_should_uppercase_when_saved(self):
        article = Article()
        article.slug = u'lowercase'
        article.save()
        self.assertEqual(article.slug, u'LOWERCASE')

    def test_slug_should_strip_whitespace_when_saved(self):
        article = Article()
        article.slug = u'   PADDED\v\t \n'
        article.save()
        self.assertEqual(article.slug, u'PADDED')

    def test_slug_cannot_contain_slashes(self):
        article = Article()
        article.slug = u'TDT/4100'
        try:
            article.save()
            self.assertEqual(1, 2)  # this should not be reached
        except ValidationError:
            self.assertEqual(1, 1)  # correct error was raised

    def test_get_contributors(self):
        self.assertEquals(self.article1.get_contributors(),
                          set([self.u1, self.u2]))

    def test_get_newest_content(self):
        self.assertEquals(self.article1.get_newest_content(), self.ac2)

    def test_get_available_languages(self):
        self.assertEquals(self.article1.get_available_languages(),
                          [('English', self.ac2)])
        result = self.article2.get_available_languages()
        expected_result = [('English', self.ac3),
                           ('Norwegian', self.ac4)]
        self.assertEquals(expected_result, result)

    def test_get_absolute_url(self):
        self.assertEquals(self.article1.get_absolute_url(), '/TDT4100_per')

    def test_get_all_article_content(self):
        result = Article.get_all_article_content()
        expected_result = [[self.ac2], [self.ac3, self.ac4]]
        self.assertEquals(expected_result, result)

    def test_get_all_newest_contents(self):
        result = Article.get_all_newest_contents()
        expected_result = [self.ac2, self.ac4]
        self.assertEquals(expected_result, result)

    def test_get_all_newest_contents_all_languages(self):
        result = Article.get_all_newest_contents_all_languages()
        expected_result = [self.ac4, self.ac3, self.ac2]
        self.assertEquals(expected_result, result)

    def test___unicode__(self):
        self.assertEquals(u'TIØ4258', unicode(self.article2))
        self.assertEquals(unicode, type(unicode(self.article2)))

    def test_get_sorted_contents(self):
        result = list(self.article1.get_sorted_contents())
        expected_result = [self.ac2, self.ac1]
        self.assertEquals(expected_result, result)

        result = list(self.article2.get_sorted_contents())
        expected_result = [self.ac3]
        self.assertEquals(expected_result, result)

        result = list(self.article2.get_sorted_contents(lang='nb'))
        expected_result = [self.ac4]
        self.assertEquals(expected_result, result)

    def test_get_available_language_codes(self):
        result = self.article2.get_available_language_codes()
        expected_result = ['en', 'nb']
        self.assertEquals(expected_result, result)

    def test_get_slug(self):
        self.assertEquals(u'TIØ4258', self.article2.get_slug())
开发者ID:stianjensen,项目名称:wikipendium.no,代码行数:104,代码来源:tests.py


注:本文中的wikipendium.wiki.models.Article.get_available_language_codes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。