當前位置: 首頁>>代碼示例>>Python>>正文


Python UserMappingType.suggest_completions方法代碼示例

本文整理匯總了Python中kitsune.users.models.UserMappingType.suggest_completions方法的典型用法代碼示例。如果您正苦於以下問題:Python UserMappingType.suggest_completions方法的具體用法?Python UserMappingType.suggest_completions怎麽用?Python UserMappingType.suggest_completions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在kitsune.users.models.UserMappingType的用法示例。


在下文中一共展示了UserMappingType.suggest_completions方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_suggest_completions

# 需要導入模塊: from kitsune.users.models import UserMappingType [as 別名]
# 或者: from kitsune.users.models.UserMappingType import suggest_completions [as 別名]
    def test_suggest_completions(self):
        u1 = UserFactory(username='r1cky', profile__name=u'Rick Róss')
        u2 = UserFactory(username='Willkg', profile__name=u'Will Cage')

        self.refresh()
        eq_(UserMappingType.search().count(), 2)

        results = UserMappingType.suggest_completions('wi')
        eq_(1, len(results))
        eq_('Will Cage (Willkg)', results[0]['text'])
        eq_(u2.id, results[0]['payload']['user_id'])

        results = UserMappingType.suggest_completions('R1')
        eq_(1, len(results))
        eq_(u'Rick Róss (r1cky)', results[0]['text'])
        eq_(u1.id, results[0]['payload']['user_id'])

        # Add another Ri....
        UserFactory(username='richard', profile__name=u'Richard Smith')

        self.refresh()
        eq_(UserMappingType.search().count(), 3)

        results = UserMappingType.suggest_completions('ri')
        eq_(2, len(results))
        texts = [r['text'] for r in results]
        assert u'Rick Róss (r1cky)' in texts
        assert u'Richard Smith (richard)' in texts

        results = UserMappingType.suggest_completions(u'Rick Ró')
        eq_(1, len(results))
        texts = [r['text'] for r in results]
        eq_(u'Rick Róss (r1cky)', results[0]['text'])
開發者ID:1234-,項目名稱:kitsune,代碼行數:35,代碼來源:test_es.py

示例2: test_suggest_completions_numbers

# 需要導入模塊: from kitsune.users.models import UserMappingType [as 別名]
# 或者: from kitsune.users.models.UserMappingType import suggest_completions [as 別名]
    def test_suggest_completions_numbers(self):
        u1 = UserFactory(username='1337mike', profile__name=u'Elite Mike')
        UserFactory(username='crazypants', profile__name=u'Crazy Pants')

        self.refresh()
        eq_(UserMappingType.search().count(), 2)

        results = UserMappingType.suggest_completions('13')
        eq_(1, len(results))
        eq_('Elite Mike (1337mike)', results[0]['text'])
        eq_(u1.id, results[0]['payload']['user_id'])
開發者ID:1234-,項目名稱:kitsune,代碼行數:13,代碼來源:test_es.py

示例3: test_suggest_completions_numbers

# 需要導入模塊: from kitsune.users.models import UserMappingType [as 別名]
# 或者: from kitsune.users.models.UserMappingType import suggest_completions [as 別名]
    def test_suggest_completions_numbers(self):
        u1 = user(username="1337mike", save=True)
        profile(user=u1, name=u"Elite Mike")
        u2 = user(username="crazypants", save=True)
        profile(user=u2, name=u"Crazy Pants")

        self.refresh()
        eq_(UserMappingType.search().count(), 2)

        results = UserMappingType.suggest_completions("13")
        eq_(1, len(results))
        eq_("Elite Mike (1337mike)", results[0]["text"])
        eq_(u1.id, results[0]["payload"]["user_id"])
開發者ID:Zucus,項目名稱:kitsune,代碼行數:15,代碼來源:test_es.py

示例4: test_suggest_completions

# 需要導入模塊: from kitsune.users.models import UserMappingType [as 別名]
# 或者: from kitsune.users.models.UserMappingType import suggest_completions [as 別名]
    def test_suggest_completions(self):
        u1 = user(username="r1cky", save=True)
        profile(user=u1, name=u"Rick Róss")
        u2 = user(username="Willkg", save=True)
        profile(user=u2, name=u"Will Cage")

        self.refresh()
        eq_(UserMappingType.search().count(), 2)

        results = UserMappingType.suggest_completions("wi")
        eq_(1, len(results))
        eq_("Will Cage (Willkg)", results[0]["text"])
        eq_(u2.id, results[0]["payload"]["user_id"])

        results = UserMappingType.suggest_completions("R1")
        eq_(1, len(results))
        eq_(u"Rick Róss (r1cky)", results[0]["text"])
        eq_(u1.id, results[0]["payload"]["user_id"])

        # Add another Ri....
        u3 = user(username="richard", save=True)
        profile(user=u3, name=u"Richard Smith")

        self.refresh()
        eq_(UserMappingType.search().count(), 3)

        results = UserMappingType.suggest_completions("ri")
        eq_(2, len(results))
        texts = [r["text"] for r in results]
        assert u"Rick Róss (r1cky)" in texts
        assert u"Richard Smith (richard)" in texts

        results = UserMappingType.suggest_completions(u"Rick Ró")
        eq_(1, len(results))
        texts = [r["text"] for r in results]
        eq_(u"Rick Róss (r1cky)", results[0]["text"])
開發者ID:Zucus,項目名稱:kitsune,代碼行數:38,代碼來源:test_es.py


注:本文中的kitsune.users.models.UserMappingType.suggest_completions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。