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


Python Article.search_article方法代码示例

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


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

示例1: test_search_article

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import search_article [as 别名]
 def test_search_article(self):
     """
     Tests the search_article function.
     """
     article1 = Article.objects.create(
         title="The Spanish corruption",
         resume="What's going on with Spanish political parties? In this "
                "article we cover it in depth.",
         published=datetime.datetime(2012, 11, 12, 0, 0, 0, 0,
                                     get_current_timezone())
     )
     article1.tags.add(Tag.objects.create(name="Spain"))
     article1.tags.add(Tag.objects.create(name="politics"))
     article2 = Article.objects.create(
         title="Barça wins the Champions League",
         resume="As the dominant team for the last decade, Barcelona "
                "succeeds one more time after a tremendous match against "
                "Juventus.",
         published=datetime.datetime(2013, 8, 7, 0, 0, 0, 0,
                                     get_current_timezone())
     )
     article2.tags.add(Tag.objects.create(name="football"))
     article2.tags.add(Tag.objects.create(name="soccer"))
     article2.tags.add(Tag.objects.create(name="Spain"))
     article3 = Article.objects.create(
         title="The revolution of NikonD3200",
         resume="This new camera has come to be one of the dominant ones. "
                "We interview several experts to understand what makes it "
                "so appealing to amateurs and even semi-professional "
                "photographers.",
         published=datetime.datetime(2014, 5, 2, 0, 0, 0, 0,
                                     get_current_timezone())
     )
     article3.tags.add(Tag.objects.create(name="photography"))
     article4 = Article.objects.create(
         title="Winning is everything",
         resume="Sarah O'Connor brings us her perspective about how "
                "important winning is for fierce competitors. She tells us "
                "how to extrapolate the to most aspects of life.",
         published=datetime.datetime(2015, 1, 1, 0, 0, 0, 0,
                                     get_current_timezone())
     )
     article4.tags.add(Tag.objects.create(name="football"))
     article4.tags.add(Tag.objects.create(name="soccer"))
     article4.tags.add(Tag.objects.create(name="sports"))
     self.assertTrue(article1 in Article.search_article("politics"))
     self.assertEqual(Article.search_article("politics").count(), 1)
     self.assertTrue(article1 in Article.search_article("  Spain"))
     self.assertTrue(article2 in Article.search_article(" sPaIn "))
     self.assertEqual(Article.search_article("spain  \t").count(), 2)
     self.assertTrue(article2 in Article.search_article("barça"))
     self.assertEqual(Article.search_article("barça").count(), 1)
     self.assertTrue(article3 in Article.search_article("new camera has"))
     self.assertEqual(Article.search_article("new camera has").count(), 1)
     self.assertTrue(article1 in Article.search_article("the"))
     self.assertTrue(article2 in Article.search_article("the"))
     self.assertTrue(article3 in Article.search_article("the"))
     self.assertTrue(article4 in Article.search_article("the"))
     self.assertEqual(Article.search_article("the").count(), 4)
     self.assertTrue(article4 in Article.search_article("2015"))
     self.assertEqual(Article.search_article("2015").count(), 1)
     self.assertTrue(article2 in Article.search_article("auGust"))
     self.assertEqual(Article.search_article("auGust").count(), 1)
开发者ID:Lantero,项目名称:personal-portfolio,代码行数:65,代码来源:test_models.py


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