Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def get_team_members(
print(f" ⚠️ Organization '{org}' not found, skipping team '{team_slug}'")
return []

team = organization.team_by_slug(team_slug)
# team_by_name accepts a slug despite its name (hits /orgs/{org}/teams/{slug})
team = organization.team_by_name(team_slug)
if not team:
print(
f" ⚠️ Team '{team_slug}' not found in '{org}', "
Expand Down
21 changes: 18 additions & 3 deletions test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from unittest.mock import MagicMock, patch

import auth
import github3
import requests


Expand Down Expand Up @@ -180,20 +181,20 @@ def test_get_team_members_success(self):
member2.login = "bob"
mock_team.members.return_value = [member1, member2]

mock_org.team_by_slug.return_value = mock_team
mock_org.team_by_name.return_value = mock_team
mock_gh.organization.return_value = mock_org

result = auth.get_team_members(mock_gh, "my-org", "my-team")

self.assertEqual(result, ["alice", "bob"])
mock_gh.organization.assert_called_once_with("my-org")
mock_org.team_by_slug.assert_called_once_with("my-team")
mock_org.team_by_name.assert_called_once_with("my-team")

def test_get_team_members_team_not_found(self):
"""Test that a missing team returns an empty list."""
mock_gh = MagicMock()
mock_org = MagicMock()
mock_org.team_by_slug.return_value = None
mock_org.team_by_name.return_value = None
mock_gh.organization.return_value = mock_org

result = auth.get_team_members(mock_gh, "my-org", "nonexistent-team")
Expand All @@ -218,6 +219,20 @@ def test_get_team_members_api_error(self):

self.assertEqual(result, [])

def test_team_by_name_exists_on_organization(self):
"""Verify that github3.py Organization actually has team_by_name.

This guards against calling a method that doesn't exist on the real
class, which MagicMock would silently allow. See PR #25 for context:
the original code called team_by_slug which never existed in github3.py
v4.0.1, and MagicMock-based tests couldn't catch it.
"""
self.assertTrue(
hasattr(github3.orgs.Organization, "team_by_name"),
"github3.orgs.Organization is missing team_by_name - "
"check github3.py version compatibility",
)


if __name__ == "__main__":
unittest.main()
Loading