From eacabb2fb917911b50452addc1dab03231bb1cbb Mon Sep 17 00:00:00 2001 From: Gilad Shefer Date: Sun, 12 Jan 2020 02:17:54 +0200 Subject: [PATCH] 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 --- github/Team.py | 25 +++++++++++++++++++++++++ tests/ReplayData/Team.testGetTeams.txt | 11 +++++++++++ tests/Team.py | 12 ++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tests/ReplayData/Team.testGetTeams.txt diff --git a/github/Team.py b/github/Team.py index 047438fa..10798167 100644 --- a/github/Team.py +++ b/github/Team.py @@ -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 `_ + :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 `_ @@ -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"] + ) diff --git a/tests/ReplayData/Team.testGetTeams.txt b/tests/ReplayData/Team.testGetTeams.txt new file mode 100644 index 00000000..80c7804a --- /dev/null +++ b/tests/ReplayData/Team.testGetTeams.txt @@ -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}}] + diff --git a/tests/Team.py b/tests/Team.py index 208156af..b0932441 100644 --- a/tests/Team.py +++ b/tests/Team.py @@ -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()