def test_get_active_posters_ranking(self): """get_active_posters_ranking returns list of active posters""" # no posts, empty tanking empty_ranking = get_active_posters_ranking() self.assertEqual(empty_ranking['users'], []) self.assertEqual(empty_ranking['users_count'], 0) # other user other_user = UserModel.objects.create_user("OtherUser", "*****@*****.**", "pass123") other_user.posts = 1 other_user.save() post_thread(self.category, poster=other_user) build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [other_user]) self.assertEqual(ranking['users_count'], 1) # two users in ranking post_thread(self.category, poster=self.user) post_thread(self.category, poster=self.user) self.user.posts = 2 self.user.save() build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [self.user, other_user]) self.assertEqual(ranking['users_count'], 2) self.assertEqual(ranking['users'][0].score, 2) self.assertEqual(ranking['users'][1].score, 1) # disabled users are not ranked disabled = UserModel.objects.create_user("DisabledUser", "*****@*****.**", "pass123") disabled.is_active = False disabled.save() post_thread(self.category, poster=disabled) post_thread(self.category, poster=disabled) post_thread(self.category, poster=disabled) disabled.posts = 3 disabled.save() build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [self.user, other_user]) self.assertEqual(ranking['users_count'], 2) self.assertEqual(ranking['users'][0].score, 2) self.assertEqual(ranking['users'][1].score, 1)
def test_get_active_posters_ranking(self): """get_active_posters_ranking returns list of active posters""" # no posts, empty tanking empty_ranking = get_active_posters_ranking() self.assertEqual(empty_ranking['users'], []) self.assertEqual(empty_ranking['users_count'], 0) # other user other_user = UserModel.objects.create_user("OtherUser", "*****@*****.**", "pass123") post_thread(self.category, poster=other_user) build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [other_user]) self.assertEqual(ranking['users_count'], 1) # two users in ranking post_thread(self.category, poster=self.user) post_thread(self.category, poster=self.user) build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [self.user, other_user]) self.assertEqual(ranking['users_count'], 2) self.assertEqual(ranking['users'][0].score, 2) self.assertEqual(ranking['users'][1].score, 1) # disabled users are not ranked disabled = UserModel.objects.create_user("DisabledUser", "*****@*****.**", "pass123") disabled.is_active = False disabled.save() post_thread(self.category, poster=disabled) post_thread(self.category, poster=disabled) post_thread(self.category, poster=disabled) disabled.posts = 3 disabled.save() build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [self.user, other_user]) self.assertEqual(ranking['users_count'], 2) self.assertEqual(ranking['users'][0].score, 2) self.assertEqual(ranking['users'][1].score, 1)
def __init__(self, request): ranking = get_active_posters_ranking() make_users_status_aware(request.user, ranking['users'], fetch_state=True) self.count = ranking['users_count'] self.tracked_period = settings.MISAGO_RANKING_LENGTH self.users = ranking['users']
def active(request): ranking = get_active_posters_ranking() make_users_status_aware( ranking['users'], request.user.acl, fetch_state=True) return Response({ 'tracked_period': settings.MISAGO_RANKING_LENGTH, 'results': ScoredUserSerializer(ranking['users'], many=True).data, 'count': ranking['users_count'] })
def active(request): ranking = get_active_posters_ranking() make_users_status_aware(request.user, ranking['users'], fetch_state=True) return Response({ 'tracked_period': settings.MISAGO_RANKING_LENGTH, 'results': ScoredUserSerializer(ranking['users'], many=True).data, 'count': ranking['users_count'] })
def test_get_active_posters_ranking(self): """get_active_posters_ranking returns list of active posters""" # no posts, empty tanking empty_ranking = get_active_posters_ranking() self.assertEqual(empty_ranking['users'], []) self.assertEqual(empty_ranking['users_count'], 0) # other user User = get_user_model() other_user = User.objects.create_user("OtherUser", "*****@*****.**", "pass123") other_user.posts = 1 other_user.save() post_thread(self.category, poster=other_user) build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [other_user]) self.assertEqual(ranking['users_count'], 1) # two users in ranking post_thread(self.category, poster=self.user) post_thread(self.category, poster=self.user) self.user.posts = 2 self.user.save() build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [self.user, other_user]) self.assertEqual(ranking['users_count'], 2) self.assertEqual(ranking['users'][0].score, 2) self.assertEqual(ranking['users'][1].score, 1)
def test_get_active_posters_ranking(self): """get_active_posters_ranking returns list of active posters""" # no posts, empty tanking empty_ranking = get_active_posters_ranking() self.assertEqual(empty_ranking['users'], []) self.assertEqual(empty_ranking['users_count'], 0) # other user User = get_user_model() other_user = User.objects.create_user( "OtherUser", "*****@*****.**", "pass123") other_user.posts = 1 other_user.save() post_thread(self.category, poster=other_user) build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [other_user]) self.assertEqual(ranking['users_count'], 1) # two users in ranking post_thread(self.category, poster=self.user) post_thread(self.category, poster=self.user) self.user.posts = 2 self.user.save() build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [self.user, other_user]) self.assertEqual(ranking['users_count'], 2) self.assertEqual(ranking['users'][0].score, 2) self.assertEqual(ranking['users'][1].score, 1)
def active_posters(request): ranking = get_active_posters_ranking() request.frontend_context['USERS'] = { 'tracked_period': settings.MISAGO_RANKING_LENGTH, 'results': ScoredUserSerializer(ranking['users'], many=True).data, 'count': ranking['users_count'] } template = "misago/userslists/active_posters.html" return render(request, template, { 'tracked_period': settings.MISAGO_RANKING_LENGTH, 'users': ranking['users'], 'users_count': ranking['users_count'] })
def active_posters(request): ranking = get_active_posters_ranking() request.frontend_context['USERS'] = { 'tracked_period': settings.MISAGO_RANKING_LENGTH, 'results': ScoredUserSerializer(ranking['users'], many=True).data, 'count': ranking['users_count'] } template = "misago/userslists/active_posters.html" return render( request, template, { 'tracked_period': settings.MISAGO_RANKING_LENGTH, 'users': ranking['users'], 'users_count': ranking['users_count'] })
def test_get_active_posters_ranking(self): """get_active_posters_ranking returns list of active posters""" # no posts, empty tanking empty_ranking = get_active_posters_ranking() self.assertEqual(empty_ranking['users'], []) self.assertEqual(empty_ranking['users_count'], 0) # other user that will be posting other_user = UserModel.objects.create_user("OtherUser", "*****@*****.**", "pass123") # lurker user that won't post anything UserModel.objects.create_user("Lurker", "*****@*****.**", "pass123") # unranked user that posted something 400 days ago unranked_user = UserModel.objects.create_user( "UnrankedUser", "*****@*****.**", "pass123" ) started_on = timezone.now() - timedelta(days=400) post_thread(self.category, poster=unranked_user, started_on=started_on) # Start testing scenarios post_thread(self.category, poster=other_user) build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [other_user]) self.assertEqual(ranking['users_count'], 1) # two users in ranking post_thread(self.category, poster=self.user) post_thread(self.category, poster=self.user) build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [self.user, other_user]) self.assertEqual(ranking['users_count'], 2) self.assertEqual(ranking['users'][0].score, 2) self.assertEqual(ranking['users'][1].score, 1) # disabled users are not ranked disabled = UserModel.objects.create_user("DisabledUser", "*****@*****.**", "pass123") disabled.is_active = False disabled.save() post_thread(self.category, poster=disabled) post_thread(self.category, poster=disabled) post_thread(self.category, poster=disabled) disabled.posts = 3 disabled.save() build_active_posters_ranking() ranking = get_active_posters_ranking() self.assertEqual(ranking['users'], [self.user, other_user]) self.assertEqual(ranking['users_count'], 2) self.assertEqual(ranking['users'][0].score, 2) self.assertEqual(ranking['users'][1].score, 1)