Skip to content

Commit

Permalink
test: Add test to cover ignored users in mentor_count
Browse files Browse the repository at this point in the history
Signed-off-by: Zack Koppert <[email protected]>
  • Loading branch information
zkoppert committed Apr 29, 2024
1 parent 1f04c74 commit 79a3995
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion test_most_active_mentors.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class TestCountCommentsPerUser(unittest.TestCase):
"""Test the count_comments_per_user function."""

def test_count_comments_per_user(self):
def test_count_comments_per_user_limit(self):
"""Test that count_comments_per_user correctly counts user comments.
This test mocks the GitHub connection and issue comments, and checks
Expand Down Expand Up @@ -54,6 +54,45 @@ def test_count_comments_per_user(self):
# Check the results
self.assertEqual(result, expected_result)

def test_count_comments_per_user_with_ignores(self):
"""Test that count_comments_per_user correctly counts user comments with some users ignored."""
# Set up the mock GitHub issues
mock_issue1 = MagicMock()
mock_issue1.comments = 2
mock_issue1.issue.user.login = "issue_owner"
mock_issue1.created_at = "2023-01-01T00:00:00Z"

# Set up mock GitHub issue comments by several users
mock_issue1.issue.comments.return_value = []
for i in range(5):
mock_comment1 = MagicMock()
mock_comment1.user.login = "very_active_user"
mock_comment1.created_at = datetime.fromisoformat(
f"2023-01-02T{i:02d}:00:00Z"
)
# pylint: disable=maybe-no-member
mock_issue1.issue.comments.return_value.append(mock_comment1)
for i in range(5):
mock_comment1 = MagicMock()
mock_comment1.user.login = "very_active_user_ignored"
mock_comment1.created_at = datetime.fromisoformat(
f"2023-01-02T{i:02d}:00:00Z"
)
# pylint: disable=maybe-no-member
mock_issue1.issue.comments.return_value.append(mock_comment1)

# Call the function
result = count_comments_per_user(
mock_issue1, ignore_users=["very_active_user_ignored"]
)
# Only the comments by "very_active_user" should be counted,
# so the count should be 3 since that is the threshold for heavily involved
expected_result = {"very_active_user": 3}

# Check the results
self.assertEqual(result, expected_result)
self.assertNotIn("very_active_user_ignored", result)

def test_get_mentor_count(self):
"""Test that get_mentor_count correctly counts comments per user."""
mentor_activity = {"sue": 15, "bob": 10}
Expand Down

0 comments on commit 79a3995

Please sign in to comment.