コード例 #1
0
ファイル: test_cron.py プロジェクト: Binzzzz/kitsune
    def test_caching_changed_helpfulness(self):
        """Changed helpfulness should be calculated correctly."""
        r = _make_backdated_revision(90)

        for x in range(0, 4):
            _add_vote_in_past(r, 0, 10)

        for x in range(0, 1):
            _add_vote_in_past(r, 1, 10)

        for x in range(0, 3):
            _add_vote_in_past(r, 0, 3)

        for x in range(0, 2):
            _add_vote_in_past(r, 1, 3)

        cache_most_unhelpful_kb_articles()

        eq_(1, self.redis.llen(self.REDIS_KEY))
        result = self.redis.lrange(self.REDIS_KEY, 0, 1)
        eq_(
            u"%d::%.1f::%.1f::%.1f::%.1f::%s::%s"
            % (r.document.id, 5.0, 0.4, 0.2, 0.0, r.document.slug, r.document.title),
            result[0].decode("utf-8"),
        )
コード例 #2
0
ファイル: test_cron.py プロジェクト: 1234-/kitsune
    def test_caching_helpful(self):
        """Cron should ignore the helpful articles."""
        r = _make_backdated_revision(90)

        for x in range(0, 3):
            _add_vote_in_past(r, 1, 3)

        for x in range(0, 2):
            _add_vote_in_past(r, 0, 3)

        cache_most_unhelpful_kb_articles()

        eq_(0, self.redis.llen(self.REDIS_KEY))
コード例 #3
0
ファイル: test_cron.py プロジェクト: zctyhj/kitsune
    def test_caching_helpful(self):
        """Cron should ignore the helpful articles."""
        r = _make_backdated_revision(90)

        for x in range(0, 3):
            _add_vote_in_past(r, 1, 3)

        for x in range(0, 2):
            _add_vote_in_past(r, 0, 3)

        cache_most_unhelpful_kb_articles()

        eq_(0, self.redis.llen(self.REDIS_KEY))
コード例 #4
0
ファイル: test_cron.py プロジェクト: smillaedler/kitsune
    def test_caching_unhelpful(self):
        """Cron should get the unhelpful articles."""
        r = _make_backdated_revision(90)

        for x in range(0, 3):
            _add_vote_in_past(r, 0, 3)

        for x in range(0, 2):
            _add_vote_in_past(r, 1, 3)

        cache_most_unhelpful_kb_articles()

        eq_(1, self.redis.llen(self.REDIS_KEY))
        result = self.redis.lrange(self.REDIS_KEY, 0, 1)
        eq_(u'%d::%.1f::%.1f::%.1f::%.1f::%s::%s' %
             (r.id, 5.0, 0.4, 0.0, 0.0, r.document.slug, r.document.title),
            result[0].decode('utf-8'))
コード例 #5
0
ファイル: test_cron.py プロジェクト: zctyhj/kitsune
    def test_caching_unhelpful(self):
        """Cron should get the unhelpful articles."""
        r = _make_backdated_revision(90)

        for x in range(0, 3):
            _add_vote_in_past(r, 0, 3)

        for x in range(0, 2):
            _add_vote_in_past(r, 1, 3)

        cache_most_unhelpful_kb_articles()

        eq_(1, self.redis.llen(self.REDIS_KEY))
        result = self.redis.lrange(self.REDIS_KEY, 0, 1)
        eq_(
            u'%d::%.1f::%.1f::%.1f::%.1f::%s::%s' %
            (r.document.id, 5.0, 0.4, 0.0, 0.0, r.document.slug,
             r.document.title), result[0].decode('utf-8'))
コード例 #6
0
ファイル: test_cron.py プロジェクト: 1234-/kitsune
    def test_caching_sorting(self):
        """Tests if Bayesian Average sorting works correctly."""
        # This should be at the bottom.
        r = _make_backdated_revision(90)

        for x in range(0, 26):
            _add_vote_in_past(r, 1, 3)

        for x in range(0, 76):
            _add_vote_in_past(r, 0, 3)

        # This should be at the top.
        r2 = _make_backdated_revision(90)

        for x in range(0, 61):
            _add_vote_in_past(r2, 1, 3)

        for x in range(0, 181):
            _add_vote_in_past(r2, 0, 3)

        # This should be in the middle.
        r3 = _make_backdated_revision(90)

        for x in range(0, 31):
            _add_vote_in_past(r3, 1, 3)

        for x in range(0, 91):
            _add_vote_in_past(r3, 0, 3)

        cache_most_unhelpful_kb_articles()

        eq_(3, self.redis.llen(self.REDIS_KEY))
        result = self.redis.lrange(self.REDIS_KEY, 0, 3)
        assert '%d::%.1f:' % (r2.document.id, 242.0) in result[0]
        assert '%d::%.1f:' % (r3.document.id, 122.0) in result[1]
        assert '%d::%.1f:' % (r.document.id, 102.0) in result[2]
コード例 #7
0
ファイル: test_cron.py プロジェクト: zctyhj/kitsune
    def test_caching_sorting(self):
        """Tests if Bayesian Average sorting works correctly."""
        # This should be at the bottom.
        r = _make_backdated_revision(90)

        for x in range(0, 26):
            _add_vote_in_past(r, 1, 3)

        for x in range(0, 76):
            _add_vote_in_past(r, 0, 3)

        # This should be at the top.
        r2 = _make_backdated_revision(90)

        for x in range(0, 61):
            _add_vote_in_past(r2, 1, 3)

        for x in range(0, 181):
            _add_vote_in_past(r2, 0, 3)

        # This should be in the middle.
        r3 = _make_backdated_revision(90)

        for x in range(0, 31):
            _add_vote_in_past(r3, 1, 3)

        for x in range(0, 91):
            _add_vote_in_past(r3, 0, 3)

        cache_most_unhelpful_kb_articles()

        eq_(3, self.redis.llen(self.REDIS_KEY))
        result = self.redis.lrange(self.REDIS_KEY, 0, 3)
        assert '%d::%.1f:' % (r2.document.id, 242.0) in result[0]
        assert '%d::%.1f:' % (r3.document.id, 122.0) in result[1]
        assert '%d::%.1f:' % (r.document.id, 102.0) in result[2]
コード例 #8
0
ファイル: test_cron.py プロジェクト: zctyhj/kitsune
    def test_caching_changed_helpfulness(self):
        """Changed helpfulness should be calculated correctly."""
        r = _make_backdated_revision(90)

        for x in range(0, 4):
            _add_vote_in_past(r, 0, 10)

        for x in range(0, 1):
            _add_vote_in_past(r, 1, 10)

        for x in range(0, 3):
            _add_vote_in_past(r, 0, 3)

        for x in range(0, 2):
            _add_vote_in_past(r, 1, 3)

        cache_most_unhelpful_kb_articles()

        eq_(1, self.redis.llen(self.REDIS_KEY))
        result = self.redis.lrange(self.REDIS_KEY, 0, 1)
        eq_(
            u'%d::%.1f::%.1f::%.1f::%.1f::%s::%s' %
            (r.document.id, 5.0, 0.4, 0.2, 0.0, r.document.slug,
             r.document.title), result[0].decode('utf-8'))
コード例 #9
0
ファイル: test_cron.py プロジェクト: 1234-/kitsune
 def test_no_articles(self):
     """Full cron with no articles returns no unhelpful articles."""
     cache_most_unhelpful_kb_articles()
     eq_(0, self.redis.llen(self.REDIS_KEY))
コード例 #10
0
ファイル: test_cron.py プロジェクト: zctyhj/kitsune
 def test_no_articles(self):
     """Full cron with no articles returns no unhelpful articles."""
     cache_most_unhelpful_kb_articles()
     eq_(0, self.redis.llen(self.REDIS_KEY))