8000 Merge pull request #323 from sigmavirus24/bug/319 · adrianmoisey/github3.py@a08c0dc · GitHub
[go: up one dir, main page]

Skip to content

Commit a08c0dc

Browse files
committed
Merge pull request sigmavirus24#323 from sigmavirus24/bug/319
Rename GitHub#update_user to GitHub#update_me
2 parents cc8248f + 0c88710 commit a08c0dc

File tree

8 files changed

+46
-74
lines changed

8 files changed

+46
-74
lines changed

LATEST_VERSION_NOTES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ Old name New name
170170

171171
- ``GitHub#me`` which retrieves the authenticated user's information
172172

173+
- ``GitHub#update_user`` has been renamed to ``GitHub#update_me`` and only
174+
uses 1 API call now. It was renamed to reflect the addition of
175+
``GitHub#me``.
176+
173177
- The legacy watching API has been removed:
174178

175179
- ``GitHub#subscribe``

github3/github.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"""
99
from __future__ import unicode_literals
1010

11+
import json
12+
1113
from .auths import Authorization
1214
from .decorators import (requires_auth, requires_basic_auth,
1315
requires_app_credentials)
@@ -1452,7 +1454,7 @@ def unfollow(self, username):
14521454

14531455
@requires_auth
14541456
def unstar(self, username, repo):
1455-
"""Unstar to username/repo
1457+
"""Unstar username/repo.
14561458
14571459
:param str username: (required), owner of the repo
14581460
:param str repo: (required), name of the repo
@@ -1465,24 +1467,30 @@ def unstar(self, username, repo):
14651467
return resp
14661468

14671469
@requires_auth
1468-
def update_user(self, name=None, email=None, blog=None,
1469-
company=None, location=None, hireable=False, bio=None):
1470-
"""If authenticated as this user, update the information with
1471-
the information provided in the parameters. All parameters are
1472-
optional.
1470+
def update_me(self, name=None, email=None, blog=None, company=None,
1471+
location=None, hireable=False, bio=None):
1472+
"""Update the profile of the authenticated user.
14731473
14741474
:param str name: e.g., 'John Smith', not login name
14751475
:param str email: e.g., 'john.smith@example.com'
14761476
:param str blog: e.g., 'http://www.example.com/jsmith/blog'
1477-
:param str company: company name
1478-
:param str location: where you are located
1477+
:param str company:
1478+
:param str location:
14791479
:param bool hireable: defaults to False
14801480
:param str bio: GitHub flavored markdown
1481-
:returns: bool
1481+
:returns: whether the operation was successful or not
1482+
:rtype: bool
14821483
"""
1483-
user = self.user()
1484-
return user.update(name, email, blog, company, location, hireable,
1485-
bio)
1484+
user = {'name': name, 'email': email, 'blog': blog,
1485+
'company': company, 'location': location,
1486+
'hireable': hireable, 'bio': bio}
1487+
self._remove_none(user)
1488+
url = self._build_url('user')
1489+
_json = self._json(self._patch(url, data=json.dumps(user)), 200)
1490+
if _json:
1491+
self._update_attributes(_json)
1492+
return True
1493+
return False
14861494

14871495
def user(self, username):
14881496
"""Returns a User object for the specified user name.

github3/users.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -401,29 +401,3 @@ def subscriptions(self, number=-1, etag=None):
401401
from .repos import Repository
402402
url = self._build_url('subscriptions', base_url=self._api)
403403
return self._iter(int(number), url, Repository, etag=etag)
404-
405-
@requires_auth
406-
def update(self, name=None, email=None, blog=None, company=None,
407-
location=None, hireable=False, bio=None):
408-
"""If authenticated as this user, update the information with
409-
the information provided in the parameters.
410-
411-
:param str name: e.g., 'John Smith', not login name
412-
:param str email: e.g., 'john.smith@example.com'
413-
:param str blog: e.g., 'http://www.example.com/jsmith/blog'
414-
:param str company:
415-
:param str location:
416-
:param bool hireable: defaults to False
417-
:param str bio: GitHub flavored markdown
418-
:returns: bool
419-
"""
420-
user = {'name': name, 'email': email, 'blog': blog,
421-
'company': company, 'location': location,
422-
'hireable': hireable, 'bio': bio}
423-
self._remove_none(user)
424-
url = self._build_url('user')
425-
json = self._json(self._patch(url, data=dumps(user)), 200)
426-
if json:
427-
self._update_attributes(json)
428-
return True
429-
return False

tests/cassettes/GitHub_update_me.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"request": {"uri": "https://api.github.com/user", "headers": {"User-Agent": "github3.py/1.0.0b1", "Accept-Charset": "utf-8", "Accept-Encoding": "gzip, deflate", "Content-Type": "application/json", "Connection": "keep-alive", "Authorization": "Basic <BASIC_AUTH>", "Content-Length": "51", "Accept": "application/vnd.github.v3.full+json"}, "body": {"string": "{\"name\": \"Ian \\\"RFC\\\" Cordasco\", \"hireable\": false}", "encoding": "utf-8"}, "method": "PATCH"}, "recorded_at": "2014-12-07T19:07:28", "response": {"headers": {"Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X- F438 RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding", "X-Content-Type-Options": "nosniff", "X-Served-By": "474556b853193c38f1b14328ce2d1b7d", "X-RateLimit-Limit": "5000", "Cache-Control": "private, max-age=60, s-maxage=60", "Content-Encoding": "gzip", "Access-Control-Allow-Credentials": "true", "X-XSS-Protection": "1; mode=block", "X-Frame-Options": "deny", "X-RateLimit-Remaining": "4903", "Content-Security-Policy": "default-src 'none'", "Content-Type": "application/json; charset=utf-8", "Transfer-Encoding": "chunked", "Server": "GitHub.com", "X-GitHub-Request-Id": "48A0CB84:0F94:AA27324:5484A570", "ETag": "\"2ea0b6d9ef9052507af7cc358dff71cb\"", "Access-Control-Allow-Origin": "*", "X-RateLimit-Reset": "1417979648", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "X-GitHub-Media-Type": "github.v3; param=full; format=json", "Status": "200 OK", "Date": "Sun, 07 Dec 2014 19:07:28 GMT"}, "body": {"base64_string": "H4sIAAAAAAAAA51UUWvbMBj8K0HPTq3YpgmGsUFh0Ie9lI7BKITPsuKIypaRZIfMZL99J9stqxmM5CmJcnc63afTwLSpVMNy5lRVU69s55KMRUyVLE8yvkt5xKgnT3bfWQ3c0fvW5XE8Lbq7SvljV3ROWmEaLxt/J0wdd/FE/tx/SqFW2VkjyDIsLLRaNetMZIi5eGHo6Gu9sDBtPVIW4IPR2pygsjT9v43idyZMTt9VU92oAuYQG3+UyA5HuoQglPPXmxpZQxw+9qoMOg4DsbK82tjMg61TA0dDbGVrRsGucMKq1ivTXG/wAxtqxlbUqF90mxrYDiLB2vVWRhbYssddvJ4+0Ya4taoncQ7RWCmk6hH2jZILPhT9uZXowXdcihC98nJPZR1qeCDtZMQaqgPgkZrVC3v6+vDCVg/GluSEAQEXvqXmDMATiVfXkpBYLdDkuZ+o5+l0QjEqrYqxH7+VmPjxCItQezFOB4xvVCpnmmj14zHkVpMKPUdlDwfywmgYq0z/Bc+D0kEMoKOykgoNj7PhQhmWN53WEWu7Qiuxn+aQ77bvK+MtZvn95q1Z6CfLN+n9X03Do4OfAuoegZOHkYRv+Jpn6w1/5lnOt3ma/ISFri0/YABI1nz7vEnzbJfzNGDGISLceeckyZC98aT3b//MLmEpFKJcruPxQzavqC9VOGy63WVJyF9rKowlb8IJAGo1IcnhbW4HK8NEpsnkKd8mHKB/0GZ/swt+ufwBPPRJpZAFAAA=", "encoding": "utf-8", "string": ""}, "url": "https://api.github.com/user", "status": {"code": 200, "message": "OK"}}}], "recorded_with": "betamax/0.4.1"}

tests/integration/test_github.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,14 @@ def test_search_repositories_with_text_match(self):
411411
assert isinstance(repos, github3.structs.SearchIterator)
412412
assert len(repo_result.text_matches) > 0
413413

414+
def test_update_me(self):
415+
"""Test the ability to update the current authenticated User."""
416+
cassette_name = self.cassette_name('update_me')
417+
self.basic_login()
418+
with self.recorder.use_cassette(cassette_name):
419+
assert self.gh.update_me(name='Ian "RFC" Cordasco') is True
420+
assert self.gh.update_me(name='Ian Cordasco') is True
421+
414422
def test_user(self):
415423
"""Test the ability to retrieve a User."""
416424
cassette_name = self.cassette_name('user')

tests/test_github.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,6 @@ def test_unstar(self):
184184
assert self.g.unstar('sigmavirus24', 'github3.py')
185185
self.mock_assertions()
186186

187-
def test_update_user(self):
188-
self.login()
189-
args = ('Ian Cordasco', 'example@mail.com', 'www.blog.com', 'company',
190-
'loc', True, 'bio')
191-
192-
with mock.patch.object(github3.github.GitHub, 'user') as user:
193-
with mock.patch.object(github3.users.User, 'update') as upd:
194-
user.return_value = github3.users.User(load('user'), self.g)
195-
upd.return_value = True
196-
assert self.g.update_user(*args)
197-
assert user.called
198-
assert upd.called
199-
upd.assert_called_with(*args)
200-
201187
def test_utf8_user(self):
202188
self.response('utf8_user')
203189
self.get('https://api.github.com/users/alejandrogomez')

tests/test_users.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,28 +188,6 @@ def test_is_following(self):
188188
assert self.user.is_following('kennethreitz')
189189
self.mock_assertions()
190190

191-
def test_update(self):
192-
self.response('user', 200)
193-
self.patch('https://api.github.com/user')
194-
self.conf = {
195-
'data': {
196-
'name': 'Ian Cordasco',
197-
'email': 'ian@cor.da.sc.o',
198-
'blog': 'http://example.com/blog',
199-
'hireable': True,
200-
}
201-
}
202-
203-
self.assertRaises(github3.GitHubError, self.user.update)
204-
205-
self.not_called()
206-
self.login()
207-
assert self.user.update(**self.conf['data'])
208-
self.mock_assertions()
209-
210-
self.response('', 404)
211-
assert self.user.update(**self.conf['data']) is False
212-
213191
def test_equality(self):
214192
u = github3.users.User(load('user'))
215193
assert self.user == u

tests/unit/test_github.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,19 @@ def test_can_login_without_two_factor_callback(self):
262262
self.instance.login('username', 'password')
263263
self.instance.login(token='token')
264264

265+
def test_update_me(self):
266+
"""Verify the request to update the authenticated user's profile."""
267+
self.instance.update_me(name='New name', email='email@example.com',
268+
blog='http://blog.example.com', company='Corp',
269+
location='here')
270+
271+
self.patch_called_with(
272+
url_for('user'),
273+
data={'name': 'New name', 'email': 'email@example.com',
274+
'blog': 'http://blog.example.com', 'company': 'Corp',
275+
'location': 'here', 'hireable': False}
276+
)
277+
265278
def test_user(self):
266279
"""Test that a user can retrieve information about any user."""
267280
self.instance.user('username')

0 commit comments

Comments
 (0)
0