8000 Add activate_membership method · sivakanth10/github3.py@3b15ba0 · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit 3b15ba0

Browse files
jacqueriesigmavirus24
authored andcommitted
Add activate_membership method
Adds a method to activate a pending organization membership, as described in https://git.io/fNEo9.
1 parent 1a96157 commit 3b15ba0

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/github3/github.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,28 @@ def _repr(self):
7070
return '<GitHub [{!r}]>'.format(self.session.auth)
7171
return '<Anonymous GitHub at 0x{0:x}>'.format(id(self))
7272

73+
@requires_auth
74+
def activate_membership(self, organization):
75+
"""Activate the membership to an organization.
76+
77+
:param organization:
78+
the organization or organization login for which to activate the
79+
membership
80+
:type organization:
81+
str
82+
:type organization:
83+
:class:`~github3.orgs.Organization`
84+
:returns:
85+
the activated membership
86+
:rtype:
87+
:class:`~github3.orgs.Membership`
88+
"""
89+
organization_name = getattr(organization, 'login', organization)
90+
url = self._build_url('user', 'memberships', 'orgs', organization_name)
91+
data = {'state': 'active'}
92+
_json = self._json(self._patch(url, data=json.dumps(data)), 200)
93+
return self._instance_or_null(orgs.Membership, _json)
94+
7395
@requires_auth
7496
def add_email_addresses(self, addresses=[]):
7597
"""Add the addresses to the authenticated user's account.

tests/unit/test_github.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ class TestGitHub(helper.UnitHelper):
1919
described_class = GitHub
2020
example_data = None
2121

22+
def test_activate_membership(self):
23+
self.instance.activate_membership('github3py')
24+
self.session.patch.assert_called_once_with(
25+
url_for('user/memberships/orgs/github3py'),
26+
data='{"state": "active"}'
27+
)
28+
2229
def test_add_email_addresses(self):
2330
"""Verify request to add email addresses for a user."""
2431
self.instance.add_email_addresses(['example1@example.com',
@@ -1285,6 +1292,10 @@ class TestGitHubRequiresAuthentication(
12851292
described_class = GitHub
12861293
example_data = None
12871294

1295+
def test_activate_membership(self):
1296+
"""Verify that activating a membership requires authentication."""
1297+
self.assert_requires_auth(self.instance.activate_membership)
1298+
12881299
def test_add_email_addresses(self):
12891300
"""Verify a user must be authenticated to add email addresses."""
12901301
self.assert_requires_auth(self.instance.add_email_addresses, [])

0 commit comments

Comments
 (0)
0