Add invitee and inviter to Invitation (#1156)

Invitations contain information about the user they are for, and
which user invited them, so export that too.

During invesigating attmepting to test the new attributes of Invitation,
it was discovered that there are no code paths to fetch them, so add
AuthenticatedUser.get_invitations(). The test added can do double duty.
This commit is contained in:
Steve Kowalik
2019-07-02 10:59:04 +08:00
committed by Wan Liuyang
parent edab176b5d
commit 0f2beaca83
4 changed files with 51 additions and 0 deletions
+12
View File
@@ -1155,6 +1155,18 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
input={}
)
def get_invitations(self):
"""
:calls: `GET /user/repository_invitations`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Invitation.Invitation`
"""
return github.PaginatedList.PaginatedList(
github.Invitation.Invitation,
self._requester,
"/user/repository_invitations",
None,
)
def create_migration(self, repos, lock_repositories=github.GithubObject.NotSet, exclude_attachments=github.GithubObject.NotSet):
"""
:calls: `POST /user/migrations`_
+22
View File
@@ -61,6 +61,22 @@ class Invitation(github.GithubObject.CompletableGithubObject):
self._completeIfNotSet(self._created_at)
return self._created_at.value
@property
def invitee(self):
"""
:type: NamedUser
"""
self._completeIfNotSet(self._invitee)
return self._invitee.value
@property
def inviter(self):
"""
:type: NamedUser
"""
self._completeIfNotSet(self._inviter)
return self._inviter.value
@property
def url(self):
"""
@@ -89,6 +105,8 @@ class Invitation(github.GithubObject.CompletableGithubObject):
self._id = github.GithubObject.NotSet
self._permissions = github.GithubObject.NotSet
self._created_at = github.GithubObject.NotSet
self._invitee = github.GithubObject.NotSet
self._inviter = github.GithubObject.NotSet
self._url = github.GithubObject.NotSet
self._html_url = github.GithubObject.NotSet
self._repository = github.GithubObject.NotSet
@@ -98,6 +116,10 @@ class Invitation(github.GithubObject.CompletableGithubObject):
self._assignee = self._makeClassAttribute(github.Repository.Repository, attributes["repository"])
if "created_at" in attributes: # pragma no branch
self._closed_at = self._makeDatetimeAttribute(attributes["created_at"])
if "invitee" in attributes: # pragma no branch
self._invitee = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["invitee"])
if "inviter" in attributes: # pragma no branch
self._inviter = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["inviter"])
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
+7
View File
@@ -253,6 +253,13 @@ class AuthenticatedUser(Framework.TestCase):
def testAcceptInvitation(self):
self.assertEqual(self.user.accept_invitation(4294886), None)
def testGetInvitations(self):
invitation = self.user.get_invitations()[0]
self.assertEqual(invitation.id, 17285388)
self.assertEqual(invitation.permissions, "write")
self.assertEqual(invitation.invitee.login, "foobar-test1")
self.assertEqual(invitation.inviter.login, "jacquev6")
def testCreateMigration(self):
self.assertTrue(isinstance(self.user.create_migration(["sample-repo"]), github.Migration.Migration))
File diff suppressed because one or more lines are too long