本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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),
)
示例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)
示例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)
示例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),
)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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))
示例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))