Skip to content

Commit

Permalink
while 0 is less than 3, 0 means 'not in leaderboard'. So don't send a…
Browse files Browse the repository at this point in the history
… Notification is somone is in the 0th rank in social engagement
  • Loading branch information
Chris Dodge authored and ihtram committed Nov 17, 2017
1 parent 9564c2d commit bbbf868
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lms/djangoapps/social_engagement/engagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ def handle_progress_post_save_signal(sender, instance, **kwargs):
get_aggregate_exclusion_user_ids(instance.course_id)
)['position']

if leaderboard_rank == 0:
# quick escape when user is not in the leaderboard
# which means rank = 0. Trouble is 0 < 3, so unfortunately
# the semantics around 0 don't match the logic below
return

# logic for Notification trigger is when a user enters into the Leaderboard
leaderboard_size = getattr(settings, 'LEADERBOARD_SIZE', 3)
presave_leaderboard_rank = instance.presave_leaderboard_rank if instance.presave_leaderboard_rank else sys.maxint
Expand Down
36 changes: 36 additions & 0 deletions lms/djangoapps/social_engagement/tests/test_engagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,39 @@ def test_closed_course(self):
# shouldn't be anything in there because course is closed
leaderboard = StudentSocialEngagementScore.generate_leaderboard(course2.id)
self.assertEqual(len(leaderboard), 2)

def test_no_score(self):
"""
Run the engagement calculation for a user in a course who has no score
"""

self.assertEqual(get_notifications_count_for_user(self.user.id), 0)

with patch('social_engagement.engagement._get_user_social_stats') as mock_func:
mock_func.return_value = {
'num_threads': 0,
'num_comments': 0,
'num_replies': 0,
'num_upvotes': 0,
'num_thread_followers': 0,
'num_comments_generated': 0,
}

update_user_engagement_score(self.course.id, self.user.id)

leaderboard_position = StudentSocialEngagementScore.get_user_leaderboard_position(
self.course.id,
self.user.id
)

self.assertEqual(
leaderboard_position['score'],
0
)

self.assertEqual(
leaderboard_position['position'],
0
)

self.assertEqual(get_notifications_count_for_user(self.user.id), 0)

0 comments on commit bbbf868

Please sign in to comment.