Added nested teams and parent (#1348)

* Added nested teams and parent

- Added github.Team.Team.get_teams() to get nested teams.
- Added github.Team.Team.parent which points to the parent team.

Fixes #1337
This commit is contained in:
Gilad Shefer
2020-01-12 10:17:54 +10:00
committed by Steve Kowalik
parent 16e5f9891f
commit eacabb2fb9
3 changed files with 48 additions and 0 deletions
+25
View File
@@ -155,6 +155,14 @@ class Team(github.GithubObject.CompletableGithubObject):
self._completeIfNotSet(self._privacy)
return self._privacy.value
@property
def parent(self):
"""
:type: string
"""
self._completeIfNotSet(self._parent)
return self._parent.value
def add_to_members(self, member):
"""
This API call is deprecated. Use `add_membership` instead.
@@ -263,6 +271,18 @@ class Team(github.GithubObject.CompletableGithubObject):
)
self._useAttributes(data)
def get_teams(self):
"""
:calls: `GET /teams/:id/teams <https://developer.github.com/v3/teams/#list-child-teams>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team`
"""
return github.PaginatedList.PaginatedList(
github.Team.Team,
self._requester,
self.url + '/teams',
None,
)
def get_discussions(self):
"""
:calls: `GET /teams/:id/discussions <https://developer.github.com/v3/teams/discussions/#list-discussions>`_
@@ -393,6 +413,7 @@ class Team(github.GithubObject.CompletableGithubObject):
self._url = github.GithubObject.NotSet
self._organization = github.GithubObject.NotSet
self._privacy = github.GithubObject.NotSet
self._parent = github.GithubObject.NotSet
def _useAttributes(self, attributes):
if "id" in attributes: # pragma no branch
@@ -423,3 +444,7 @@ class Team(github.GithubObject.CompletableGithubObject):
)
if "privacy" in attributes: # pragma no branch
self._privacy = self._makeStringAttribute(attributes["privacy"])
if "parent" in attributes: # pragma no branch
self._parent = self._makeClassAttribute(
github.Team.Team, attributes["parent"]
)
+11
View File
@@ -0,0 +1,11 @@
https
GET
api.github.com
None
/teams/189850/teams
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4973'), ('content-length', '150'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"43d7c883d1cb7d50a08d2c189550023c"'), ('date', 'Sun, 27 May 2012 05:13:46 GMT'), ('content-type', 'application/json; charset=utf-8')]
[{"name":"DummyTeam1","id":189851,"parent":{"name":"Team created by PyGithub","id":189850}},{"name":"DummyTeam2","id":189852,"parent":{"name":"Team created by PyGithub","id":189850}},{"name":"DummyTeam3","id":189853,"parent":{"name":"Team created by PyGithub","id":189850}}]
+12
View File
@@ -55,6 +55,7 @@ class Team(Framework.TestCase):
self.assertEqual(self.team.url, "https://api.github.com/teams/189850")
self.assertEqual(self.team.organization, self.org)
self.assertEqual(self.team.privacy, "closed")
self.assertEqual(self.team.parent, None)
# test __repr__() based on this attributes
self.assertEqual(
@@ -138,5 +139,16 @@ class Team(Framework.TestCase):
self.assertEqual(self.team.permission, "admin")
self.assertEqual(self.team.privacy, "secret")
def testGetTeams(self):
nested_teams = self.team.get_teams()
self.assertListKeyEqual(
nested_teams,
lambda t: t.name,
['DummyTeam1', 'DummyTeam2', 'DummyTeam3']
)
parent = nested_teams[0].parent
self.assertEqual(self.team.name, parent.name)
self.assertEqual(self.team.id, parent.id)
def testDelete(self):
self.team.delete()