Skip to content

Commit e6bdca1

Browse files
authored
Merge pull request #1091 from pallavisharma1210/cancel_invite
cancel and failed invitation
2 parents e650c1d + ed0330c commit e6bdca1

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

src/github3/orgs.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,27 @@ def invite(
922922
json = self._json(self._post(url, data=data, headers=headers), 200)
923923
return self._instance_or_null(Invitation, json)
924924

925+
@requires_auth
926+
def cancel_invite(self, invitee_id):
927+
"""Cancel the invitation using ``invitee_id``
928+
of the user from the organization.
929+
930+
:param int invitee_id:
931+
the identifier for the user being invited, to cancel its invitation
932+
:returns: bool
933+
"""
934+
url = self._build_url("invitations", invitee_id, base_url=self._api)
935+
return self._boolean(self._delete(url), 204, 404)
936+
937+
@requires_auth
938+
def failed_invitations(self):
939+
"""List failed organization invitations.
940+
941+
:returns: bool
942+
"""
943+
url = self._build_url("failed_invitations", base_url=self._api)
944+
return self._json(self._get(url), 200, 404)
945+
925946
def is_member(self, username):
926947
"""Check if the user named ``username`` is a member.
927948
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"recorded_with": "betamax/0.8.0",
3+
"http_interactions": [
4+
{
5+
"recorded_at": "2017-03-21T16:39:14",
6+
"request": {
7+
"method": "GET", "uri": "https://api.github.com/orgs/Thunderbird-client", "headers": {"Content-Type": "application/json", "Connection": "keep-alive", "Accept": "application/vnd.github.v3.full+json", "Accept-Encoding": "gzip, deflate", "User-Agent": "github3.py/1.0.0a4", "Accept-Charset": "utf-8", "Authorization": "token <AUTH_TOKEN>"}, "body": {"encoding": "utf-8", "string": ""}
8+
},
9+
"response": {
10+
"url": "https://api.github.com/orgs/Thunderbird-client", "status": {"code": 200, "message": "OK"}, "headers": {"X-GitHub-Media-Type": "github.v3; param=full; format=json", "Content-Security-Policy": "default-src 'none'", "Content-Type": "application/json; charset=utf-8", "Date": "Tue, 21 Mar 2017 16:39:14 GMT", "X-Frame-Options": "deny", "X-RateLimit-Reset": "1490116788", "Content-Encoding": "gzip", "ETag": "W/\"9327ef192018f8123429af874422d1e5\"", "Status": "200 OK", "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", "X-Content-Type-Options": "nosniff", "Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "Server": "GitHub.com", "Transfer-Encoding": "chunked", "Cache-Control": "private, max-age=60, s-maxage=60", "Access-Control-Allow-Origin": "*", "X-RateLimit-Limit": "5000", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "X-OAuth-Scopes": "admin:org, user", "X-GitHub-Request-Id": "9825:323F:302A695:3CA2459:58D15732", "X-Served-By": "7efb7ae49588ef0269c6a1c1bd3721d9", "X-RateLimit-Remaining": "4988", "X-XSS-Protection": "1; mode=block", "Last-Modified": "Mon, 07 Nov 2016 20:37:20 GMT"}, "body": {"encoding": "utf-8", "base64_string": "H4sIAAAAAAAAA6VTy07DQAz8l71CSZpAq0ZC8AdcOHGJnMRNLPalfbSCqv+Ok7SltHAJh0i7I3syHs/uhDQtaVGI1y7qBl1FrpnVklAHcSuoEUWW5xl/q1sRneTCLgTriyQBS3cthS5Wd7VRiXGtT34lcWiNL6c0J0Mr68AN65nIMfYySWfM+0SOobX3w/uIEznGXiZRqCp0E1kOzbtkPOyZz8ZKUl3+i/Ynxzk7bCCAu1zfAPr8EIDo0dVGB17SkIWYHEPztHnMWWKDvnZkAxmOmo5SnlSPGy7SE9CSD170wNpIabbs1NmNdDvcuqDkhaazLP4aw9ohBGxKCBziLJ0vZvP5LF2+ZmmRPxT32RvrjLb5s2ZZZGlfEz4sMsOLa0HTJwwzMWoCyNI6Ymew/J7KbDX/8xo/It/jNuTfy+ihZXaesObpoTIOgjk4UJGUPH+JCmh4iFvSeKPM5wwaRfqZT1wB/Qb6VEhgr3dCg+rlrh0io95CzdfVcvGwyO5X/Kivpa2ZhTV7toutz7hpPKX7/RfdAAHYLwQAAA==", "string": ""}
11+
}
12+
},
13+
{
14+
"recorded_at": "2017-03-21T16:39:15",
15+
"request": {
16+
"method": "DELETE", "uri": "https://api.github.com/orgs/Thunderbird-client/invitations/123", "headers": {"Content-Type": "application/json", "Connection": "keep-alive", "Accept": "application/vnd.github.v3.full+json", "Content-Length": "0", "Accept-Encoding": "gzip, deflate", "User-Agent": "github3.py/1.0.0a4", "Accept-Charset": "utf-8", "Authorization": "token <AUTH_TOKEN>"}, "body": {"encoding": "utf-8", "string": ""}
17+
},
18+
"response": {
19+
"url": "https://api.github.com/orgs/Thunderbird-client/invitations/123", "status": {"code": 204, "message": "No Content"}, "headers": {"X-GitHub-Media-Type": "github.v3; param=full; format=json", "Content-Security-Policy": "default-src 'none'", "Access-Control-Allow-Origin": "*", "X-Content-Type-Options": "nosniff", "Date": "Tue, 21 Mar 2017 16:39:15 GMT", "X-OAuth-Scopes": "admin:org, user", "Status": "204 No Content", "X-XSS-Protection": "1; mode=block", "X-Served-By": "318e55760cf7cdb40e61175a4d36cd32", "X-Accepted-OAuth-Scopes": "admin:org, repo", "X-RateLimit-Limit": "5000", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "X-GitHub-Request-Id": "9825:323F:302A6AF:3CA2474:58D15732", "X-Frame-Options": "deny", "Server": "GitHub.com", "X-RateLimit-Remaining": "4987", "Vary": "Accept-Encoding", "X-RateLimit-Reset": "1490116788"}, "body": {"encoding": null, "string": ""}
20+
}
21+
}
22+
]
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"recorded_with": "betamax/0.8.0",
3+
"http_interactions": [
4+
{
5+
"response": {
6+
"body": {"string": "", "base64_string": "H4sIAAAAAAAAA51TTW+DMAz9LznTkUELJdK0/YNddtoFGcho1JBE+Wi1Vf3vcwpd6bQLuwXbz/Z7z5yI1L1QhJFBfwkpwR9JQkRHWFlVOS3LhAQrMb3z3jiWpmDEQy/8LjQPrR5SbXuXzqGWG+3qBZj0gsCh/MCVXwYdIYjdab1fBr0gIlXnAl8GHSGIHfjQcLsMPGFO6fg4YxsTGina+j/d7qHzpnAAD/a3EZege5wcDI7bViuPul/MDOlk+vPhKcfFOu5aK4wXOh4IBhQMfHxhuQH1SZgKUiakwSsaE1K3cAPwAUS8nhvL0W1Gf2j3wnlHYuBDS6mPKOjsSyjsi7mdH+QvMrMrnB9gazl43tXgcW5GH9crWqyy4o0WLNuyvHrHXYLp7mo2K1qucvpGK7besCyLNf7TRK6vtgclvkZOGNUeZG2sQCV5PZHJtwnRR4VD/0hcQzeenXD7OjjosX9W0e1mmyWkRfLQaAteTwI0+Dsi/fqqoZLiZSIa3YqSSkBjTldbPiznGHUGWuxclcWmyNZVhXX360apsTeu61AqVDvHyPSk5/M3PlgqfhMEAAA=", "encoding": "utf-8"}, "headers": {"X-Served-By": "e724c57ebb9961c772a91e2dd7421c8d", "X-RateLimit-Limit": "5000", "Content-Encoding": "gzip", "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", "Cache-Control": "private, max-age=60, s-maxage=60", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "X-Content-Type-Options": "nosniff", "X-RateLimit-Reset": "1490116788", "Content-Security-Policy": "default-src 'none'", "Access-Control-Allow-Origin": "*", "X-XSS-Protection": "1; mode=block", "X-GitHub-Request-Id": "B6A7:323D:CFAD10:1082F65:58D152A4", "X-OAuth-Scopes": "admin:org, user", "Transfer-Encoding": "chunked", "X-Frame-Options": "deny", "X-GitHub-Media-Type": "github.v3; param=full; format=json", "Content-Type": "application/json; charset=utf-8", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "ETag": "W/\"13e22d95456e27168f64042420bed565\"", "Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "Server": "GitHub.com", "Status": "200 OK", "Date": "Tue, 21 Mar 2017 16:19:48 GMT", "Last-Modified": "Thu, 30 Jul 2015 09:45:22 GMT", "X-RateLimit-Remaining": "4999"}, "url": "https://api.github.com/orgs/mozillatw", "status": {"message": "OK", "code": 200}
7+
},
8+
"recorded_at": "2017-03-21T16:19:48",
9+
"request": {
10+
"uri": "https://api.github.com/orgs/mozillatw", "body": {"string": "", "encoding": "utf-8"}, "headers": {"Connection": "keep-alive", "Content-Type": "application/json", "Accept-Encoding": "gzip, deflate", "Accept-Charset": "utf-8", "User-Agent": "github3.py/1.0.0a4", "Authorization": "token <AUTH_TOKEN>", "Accept": "application/vnd.github.v3.full+json"}, "method": "GET"
11+
}
12+
},
13+
{
14+
"response": {
15+
"body": {"string": "[{ \"id\": 1, \"login\": \"monalisa\", \"node_id\": \"MDQ6VXNlcjE=\", \"email\": \"[email protected]\", \"role\": \"direct_member\", \"created_at\": \"2016-11-30T06:46:10-08:00\", \"failed_at\": \"\", \"failed_reason\": \"\", \"inviter\": { \"login\": \"other_user\", \"id\": 1, \"node_id\": \"MDQ6VXNlcjE=\", \"avatar_url\": \"https://github.com/images/error/other_user_happy.gif\", \"gravatar_id\": \"\", \"url\": \"https://api.github.com/users/other_user\", \"html_url\": \"https://github.com/other_user\", \"followers_url\": \"https://api.github.com/users/other_user/followers\", \"following_url\": \"https://api.github.com/users/other_user/following{/other_user}\", \"gists_url\": \"https://api.github.com/users/other_user/gists{/gist_id}\", \"starred_url\": \"https://api.github.com/users/other_user/starred{/owner}{/repo}\", \"subscriptions_url\": \"https://api.github.com/users/other_user/subscriptions\", \"organizations_url\": \"https://api.github.com/users/other_user/orgs\", \"repos_url\": \"https://api.github.com/users/other_user/repos\", \"events_url\": \"https://api.github.com/users/other_user/events{/privacy}\", \"received_events_url\": \"https://api.github.com/users/other_user/received_events\", \"type\": \"User\", \"site_admin\": false}, \"team_count\": 2, \"invitation_teams_url\": \"https://api.github.com/organizations/2/invitations/1/teams\"}]", "base64_string": "H4sIAAAAAAAAA5WT0WqDMBSG3yXXbaO1nW1gjLFX2K7GkFRP9UBMJImWTvruO1FpmRdjXinJ+b7ze2I+e4YFE8kujfbHFVOmRM0Ee1VSv1Wgt1G8YysGtUTFhG6VWjFrFFBJgRZyn9VQn8BSTW5Beigy6WkzcOs4Xm/T9/gg9qlIDuvoIKKIClF36AkR/b2dA9SKGtNmCHPcpk8RpZGd9NJmraXerPK+cYLzcdElmxJ91Z5aBzY32oP2m9zUvOUT/tI9JyQs7WQJZkYLM1uDk2ikyeb4I07lazXrP7Ydqh91Z6OUuRA7D/uHnt8hSjW+oy6XCwjqufEV0KQo/i18NDq/KMoA9Dw8MiyCwtHkLR3n/8fFJ4TCXDTl6LmFxgyu9uRyi41HoxfF+gWSyNhSavyWi0UEOuJDoEUBBoBA6Oj/WkSORM8bi53Mr2EMdF8AO5rpctsMJZm/NuEWftCJhwnTjcpkUYfLe5bKwe329QN+p6NL2wMAAA==", "encoding": "utf-8"}, "headers": {"X-Served-By": "b535085e7f4d6e3423e016e684de0829", "X-RateLimit-Limit": "5000", "Content-Encoding": "gzip", "X-Accepted-OAuth-Scopes": "admin:org, repo", "Cache-Control": "private, max-age=60, s-maxage=60", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "X-Content-Type-Options": "nosniff", "X-RateLimit-Reset": "1490116788", "Content-Security-Policy": "default-src 'none'", "Access-Control-Allow-Origin": "*", "X-XSS-Protection": "1; mode=block", "X-GitHub-Request-Id": "B6A7:323D:CFAD1F:1082F76:58D152A4", "X-OAuth-Scopes": "admin:org, user", "Transfer-Encoding": "chunked", "X-Frame-Options": "deny", "X-GitHub-Media-Type": "github.korra-preview", "Content-Type": "application/json; charset=utf-8", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "ETag": "W/\"208eae13ff28e142bb5e32a4d0fdfb55\"", "Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "Server": "GitHub.com", "Status": "200 OK", "Date": "Tue, 21 Mar 2017 16:19:48 GMT", "X-RateLimit-Remaining": "4998"}, "url": "https://api.github.com/orgs/mozillatw/failed_invitations", "status": {"message": "OK", "code": 200}
16+
},
17+
"recorded_at": "2017-03-21T16:19:48",
18+
"request": {
19+
"uri": "https://api.github.com/orgs/mozillatw/failed_invitations", "body": {"string": "", "encoding": "utf-8"}, "headers": {"Connection": "keep-alive", "Content-Type": "application/json", "Accept-Encoding": "gzip, deflate", "Accept-Charset": "utf-8", "User-Agent": "github3.py/1.0.0a4", "Authorization": "token <AUTH_TOKEN>", "Accept": "application/vnd.github.korra-preview"}, "method": "GET"
20+
}
21+
}
22+
]
23+
}

tests/integration/test_orgs.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,20 @@ def test_invite(self):
352352
[team.id], invitee_id=2354350, role="direct_member"
353353
)
354354

355+
def test_cancel_invite(self):
356+
"""Show that a user can cancel invitation of github."""
357+
cassette_name = self.cassette_name("cancel_invite")
358+
with self.recorder.use_cassette(cassette_name):
359+
o = self.get_organization("Thunderbird-client", auth_needed=True)
360+
assert o.cancel_invite("123")
361+
362+
def test_failed_invitations(self):
363+
"""Get list of failed invitations."""
364+
cassette_name = self.cassette_name("failed_invitations")
365+
with self.recorder.use_cassette(cassette_name):
366+
o = self.get_organization("mozillatw", auth_needed=True)
367+
assert o.failed_invitations()
368+
355369
def test_membership(self):
356370
"""Show that a user can obtain the membership status."""
357371
cassette_name = self.cassette_name("membership")

tests/unit/test_orgs.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,20 @@ def test_invite(self):
270270
headers=headers,
271271
)
272272

273+
def test_cancel_invite(self):
274+
"""Show that one can cancel a invitation in an organization."""
275+
self.instance.cancel_invite("123")
276+
277+
self.delete_called_with(url_for("invitations/123"))
278+
279+
def test_failed_invitations(self):
280+
"""Get all the failed invitation in an organization."""
281+
self.instance.failed_invitations()
282+
283+
self.session.get.assert_called_once_with(
284+
url_for("failed_invitations")
285+
)
286+
273287
def test_invite_requires_valid_role(self):
274288
"""Validate our validation of roles."""
275289
with pytest.raises(ValueError):
@@ -384,6 +398,16 @@ def test_invite(self):
384398
with pytest.raises(GitHubError):
385399
self.instance.invite()
386400

401+
def test_cancel_invite(self):
402+
"""Show that cancelling invitation requires authentication."""
403+
with pytest.raises(GitHubError):
404+
self.instance.cancel_invite()
405+
406+
def test_failed_invitations(self):
407+
"""Show that getting failed invitations requires authentication."""
408+
with pytest.raises(GitHubError):
409+
self.instance.failed_invitations()
410+
387411
def test_membership_for(self):
388412
"""Show that inviting a member requires authentication."""
389413
with pytest.raises(GitHubError):

0 commit comments

Comments
 (0)