• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python star_ratings.get_star_ratings_rating_model函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中star_ratings.get_star_ratings_rating_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_star_ratings_rating_model函数的具体用法?Python get_star_ratings_rating_model怎么用?Python get_star_ratings_rating_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_ratings_for_instance_is_called___for_instance_is_called_with_the_correct_instance

    def test_ratings_for_instance_is_called___for_instance_is_called_with_the_correct_instance(self):
        foo = Foo.objects.create()

        with patch('star_ratings.models.RatingManager.for_instance') as for_instance_mock:
            get_star_ratings_rating_model().objects.ratings_for_instance(foo)

            for_instance_mock.assert_called_once_with(foo)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:7,代码来源:test_rating_manager.py


示例2: test_multiple_user_ratings_are_created_for_multiple_ratings___calculateion_are_updated_correctly

    def test_multiple_user_ratings_are_created_for_multiple_ratings___calculateion_are_updated_correctly(self):
        foo, bar = mommy.make(Foo, name='name', _quantity=2)

        foo_rating = get_star_ratings_rating_model().objects.for_instance(foo)
        bar_rating = get_star_ratings_rating_model().objects.for_instance(bar)

        user_a, user_b, user_c = mommy.make(get_user_model(), _quantity=3)

        data = [
            UserRating(user=user_a, ip='127.0.0.1', score=1, rating=foo_rating),
            UserRating(user=user_b, ip='127.0.0.2', score=3, rating=foo_rating),
            UserRating(user=user_a, ip='127.0.0.1', score=1, rating=bar_rating),
            UserRating(user=user_b, ip='127.0.0.2', score=3, rating=bar_rating),
            UserRating(user=user_c, ip='127.0.0.2', score=5, rating=bar_rating),
        ]

        UserRating.objects.bulk_create(data)

        foo_rating = get_star_ratings_rating_model().objects.get(pk=foo_rating.pk)
        self.assertEqual(2, foo_rating.count)
        self.assertEqual(4, foo_rating.total)
        self.assertEqual(2, foo_rating.average)

        bar_rating = get_star_ratings_rating_model().objects.get(pk=bar_rating.pk)
        self.assertEqual(3, bar_rating.count)
        self.assertEqual(9, bar_rating.total)
        self.assertEqual(3, bar_rating.average)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:27,代码来源:test_user_rating_manager.py


示例3: test_ratings_for_instance_is_called___deprication_warning_is_given

    def test_ratings_for_instance_is_called___deprication_warning_is_given(self):
        foo = Foo.objects.create()

        with patch('star_ratings.models.warn') as warn_mock:
            get_star_ratings_rating_model().objects.ratings_for_instance(foo)

            warn_mock.assert_called_once_with("RatingManager method 'ratings_for_instance' has been renamed to 'for_instance'. Please change uses of 'Rating.objects.ratings_for_instance' to 'Rating.objects.for_instance' in your code.", DeprecationWarning)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:7,代码来源:test_rating_manager.py


示例4: test_anon_ratings_is_true___none_is_returned

    def test_anon_ratings_is_true___none_is_returned(self):
        foo = mommy.make(Foo)

        get_star_ratings_rating_model().objects.rate(foo, 1, ip='127.0.0.1')
        get_star_ratings_rating_model().objects.rate(foo, 1, ip='127.0.0.1')

        self.assertIsNone(
            UserRating.objects.for_instance_by_user(foo),
        )
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:9,代码来源:test_user_rating_manager.py


示例5: test_rating_object_does_not_exist_for_model___object_is_created_and_returned

    def test_rating_object_does_not_exist_for_model___object_is_created_and_returned(self):
        item = mommy.make(Foo)

        res = get_star_ratings_rating_model().objects.for_instance(item)

        self.assertIsInstance(res, get_star_ratings_rating_model())
        self.assertEqual(item, res.content_object)
        self.assertEqual(0, res.count)
        self.assertEqual(0, res.total)
        self.assertEqual(0, res.average)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:10,代码来源:test_rating_manager.py


示例6: test_same_user_rate_twice_rerate_is_false___validation_error_is_raised

    def test_same_user_rate_twice_rerate_is_false___validation_error_is_raised(self):
        """
        If re-rating is disabled the rating should not count
        """
        ratings = get_star_ratings_rating_model().objects.rate(self.foo, 4, self.user_a, '127.0.0.1')
        with self.assertRaises(ValidationError):
            ratings = get_star_ratings_rating_model().objects.rate(self.foo, 2, self.user_a, '127.0.0.1')

        self.assertEqual(ratings.count, 1)
        self.assertEqual(ratings.total, 4)
        self.assertEqual(ratings.average, 4)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:11,代码来源:test_rating_manager.py


示例7: test_user_is_set___rating_object_for_is_returned

    def test_user_is_set___rating_object_for_is_returned(self):
        foo = mommy.make(Foo)
        user = mommy.make(get_user_model())

        get_star_ratings_rating_model().objects.rate(foo, 1, user=mommy.make(get_user_model()))
        expected = get_star_ratings_rating_model().objects.rate(foo, 1, user=user).user_ratings.get(user=user)

        self.assertEqual(
            expected,
            UserRating.objects.for_instance_by_user(foo, user=user),
        )
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:11,代码来源:test_user_rating_manager.py


示例8: test_same_user_rate_twice_rerate_is_true___rating_is_changed

    def test_same_user_rate_twice_rerate_is_true___rating_is_changed(self, scores):
        first, second = scores

        ratings = get_star_ratings_rating_model().objects.rate(self.foo, first, self.user_a, '127.0.0.1')
        self.assertTrue(ratings.user_ratings.filter(user=self.user_a, score=first))
        self.assertEqual(ratings.count, 1)
        self.assertEqual(ratings.total, first)
        self.assertEqual(ratings.average, first)

        ratings = get_star_ratings_rating_model().objects.rate(self.foo, second, self.user_a, '127.0.0.1')
        self.assertTrue(ratings.user_ratings.filter(user=self.user_a, score=second))
        self.assertEqual(ratings.count, 1)
        self.assertEqual(ratings.total, second)
        self.assertEqual(ratings.average, second)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:14,代码来源:test_rating_manager.py


示例9: test_order_item_by_total_rating_is_possible

    def test_order_item_by_total_rating_is_possible(self):
        user = fake_user()
        foo_a = self.foo = Foo.objects.create(name='foo a')
        foo_b = self.foo = Foo.objects.create(name='foo b')

        # total rating: 4
        get_star_ratings_rating_model().objects.rate(foo_a, 4, user, '127.0.0.1')

        # total rating: 3
        get_star_ratings_rating_model().objects.rate(foo_b, 3, user, '127.0.0.1')

        foos = Foo.objects.filter(ratings__isnull=False).order_by('ratings__total')
        self.assertEqual(foos[1].pk, foo_a.pk)
        self.assertEqual(foos[0].pk, foo_b.pk)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:14,代码来源:test_rating.py


示例10: test_rating_object_exists_for_model___that_object_is_returned

    def test_rating_object_exists_for_model___that_object_is_returned(self):
        item = mommy.make(Foo)
        rating = fake_rating(content_object=item)

        res = get_star_ratings_rating_model().objects.for_instance(item)

        self.assertEqual(rating, res)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:7,代码来源:test_rating_manager.py


示例11: test_has_rate_is_passed_a_rating_instance___type_error_is_raised

    def test_has_rate_is_passed_a_rating_instance___type_error_is_raised(self):
        user = mommy.make(get_user_model())
        foo = mommy.make(Foo)
        ratings = get_star_ratings_rating_model().objects.for_instance(foo)

        with assertRaisesRegex(self, TypeError, "UserRating manager 'has_rated' expects model to be rated, not UserRating model."):
            UserRating.objects.has_rated(ratings, user)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:7,代码来源:test_user_rating_manager.py


示例12: test_view_is_called_when_nobody_is_logged_in_and_anon_ratings_is_false___user_is_forwarded_to_login

    def test_view_is_called_when_nobody_is_logged_in_and_anon_ratings_is_false___user_is_forwarded_to_login(self):
        foo = mommy.make(Foo)
        ratings = get_star_ratings_rating_model().objects.for_instance(foo)

        url = reverse('ratings:rate', args=(ratings.content_type_id, ratings.object_id))
        response = self.post_json(url, {'score': 1})

        self.assertRedirects(response, settings.LOGIN_URL + '?next=' + url, fetch_redirect_response=False)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:8,代码来源:test_views_rate.py


示例13: test_order_item_by_count_rating_is_possible

    def test_order_item_by_count_rating_is_possible(self):
        user_a, user_b = fake_user(_quantity=2)
        foo_a = self.foo = Foo.objects.create(name='foo a')
        foo_b = self.foo = Foo.objects.create(name='foo b')

        # 2 ratings
        get_star_ratings_rating_model().objects.rate(foo_a, 4, user_a, '127.0.0.1')
        get_star_ratings_rating_model().objects.rate(foo_a, 1, user_a, '127.0.0.1')

        # 3 ratings
        get_star_ratings_rating_model().objects.rate(foo_b, 2, user_b, '127.0.0.1')
        get_star_ratings_rating_model().objects.rate(foo_b, 3, user_b, '127.0.0.1')
        get_star_ratings_rating_model().objects.rate(foo_b, 2, user_b, '127.0.0.1')

        foos = Foo.objects.filter(ratings__isnull=False).order_by('ratings__count')
        self.assertEqual(foos[0].pk, foo_a.pk)
        self.assertEqual(foos[1].pk, foo_b.pk)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:17,代码来源:test_rating.py


示例14: test_anon_is_true___result_contains_ip_and_rating_name

    def test_anon_is_true___result_contains_ip_and_rating_name(self):
        user = mommy.make(get_user_model())
        foo = mommy.make(Foo)

        rating = get_star_ratings_rating_model().objects.rate(foo, 1, user, '127.0.0.1')
        user_rating = rating.user_ratings.get(ip='127.0.0.1')

        self.assertEqual('{} rating {} for {}'.format('127.0.0.1', user_rating.score, foo), str(user_rating))
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:8,代码来源:test_user_rating.py


示例15: test_multiple_users_rating_the_object___aggregates_are_updated

    def test_multiple_users_rating_the_object___aggregates_are_updated(self, scores):
        ratings = None
        for score in scores:
            ratings = get_star_ratings_rating_model().objects.rate(self.foo, score, fake_user(), '127.0.0.1')

        self.assertEqual(ratings.count, len(scores))
        self.assertAlmostEqual(ratings.total, sum(scores))
        self.assertAlmostEqual(ratings.average, mean(scores))
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:8,代码来源:test_rating_manager.py


示例16: test_several_ratings_are_made___percentage_is_correct_in_result

    def test_several_ratings_are_made___percentage_is_correct_in_result(self, scores):
        with patch('django.template.Template.render') as render_mock:
            item = mommy.make(Foo)

            request = RequestFactory().get('/')
            request.user = fake_user()

            for score in scores:
                get_star_ratings_rating_model().objects.rate(item, score, mommy.make(get_user_model()))

            rating = get_star_ratings_rating_model().objects.for_instance(item)

            ratings({
                'request': request,
            }, item)

            context = render_mock.call_args_list[0][0][0]
            expected_avg = 100 * (rating.average / Decimal(app_settings.STAR_RATINGS_RANGE))
            self.assertEqual(expected_avg, context['percentage'])
开发者ID:wildfish,项目名称:django-star-ratings,代码行数:19,代码来源:test_template_tags_ratings.py


示例17: test_object_name_contains_any_unicode___str_does_not_error

    def test_object_name_contains_any_unicode___str_does_not_error(self, name):
        user = mommy.make(get_user_model())
        foo = mommy.make(Foo, name=name)

        rating = get_star_ratings_rating_model().objects.rate(foo, 1, user, '0.0.0.0')
        user_rating = rating.user_ratings.get(user=user)

        try:
            str(user_rating)
        except:
            self.fail('"str" raised when it should\'nt')
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:11,代码来源:test_user_rating.py


示例18: test_user_is_logged_in_and_doesnt_already_have_a_rating_next_url_is_given___redirected_to_next

    def test_user_is_logged_in_and_doesnt_already_have_a_rating_next_url_is_given___redirected_to_next(self):
        user = self.get_user()
        foo = mommy.make(Foo)
        ratings = get_star_ratings_rating_model().objects.for_instance(foo)

        score = randint(1, 5)

        url = reverse('ratings:rate', args=(ratings.content_type_id, ratings.object_id)) + '?next=/foo/bar'
        response = self.post_json(url, {'score': score}, user=user)

        self.assertRedirects(response, '/foo/bar', fetch_redirect_response=False)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:11,代码来源:test_views_rate.py


示例19: test_deleting_the_rating___aggregates_are_updated

    def test_deleting_the_rating___aggregates_are_updated(self, scores):
        ratings = None
        for score in scores:
            ratings = get_star_ratings_rating_model().objects.rate(self.foo, score, fake_user(), '127.0.0.1')

        removed_score = scores.pop()
        ratings.user_ratings.filter(score=removed_score).first().delete()

        self.assertEqual(ratings.count, len(scores))
        self.assertAlmostEqual(ratings.total, sum(scores))
        self.assertAlmostEqual(ratings.average, mean(scores))
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:11,代码来源:test_rating_manager.py


示例20: test_correct_number_of_

    def test_correct_number_of_(self):
        foo = mommy.make(Foo, name='name')
        rating = get_star_ratings_rating_model().objects.for_instance(foo)
        user_a, user_b = mommy.make(get_user_model(), _quantity=2)

        data = [
            UserRating(user=user_a, ip='127.0.0.1', score=3, rating=rating),
            UserRating(user=user_b, ip='127.0.0.2', score=3, rating=rating),
        ]

        UserRating.objects.bulk_create(data)
        self.assertEqual(UserRating.objects.count(), 2)
开发者ID:RabidCicada,项目名称:django-star-ratings,代码行数:12,代码来源:test_user_rating_manager.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python log.debug函数代码示例发布时间:2022-05-27
下一篇:
Python config.options函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap