Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita03fd6d

Browse files
committed
Rename GitHub#update_user to GitHub#update_me
GitHub#update_me only uses one API request now. User#update has beenremoved. Removed old tests. Add new unit test.Closessigmavirus24#319
1 parentcc8248f commita03fd6d

File tree

5 files changed

+33
-74
lines changed

5 files changed

+33
-74
lines changed

‎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__importunicode_literals
1010

11+
importjson
12+
1113
from .authsimportAuthorization
1214
from .decoratorsimport (requires_auth,requires_basic_auth,
1315
requires_app_credentials)
@@ -1452,7 +1454,7 @@ def unfollow(self, username):
14521454

14531455
@requires_auth
14541456
defunstar(self,username,repo):
1455-
"""Unstartousername/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
returnresp
14661468

14671469
@requires_auth
1468-
defupdate_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+
defupdate_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-
returnuser.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+
returnTrue
1493+
returnFalse
14861494

14871495
defuser(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 .reposimportRepository
402402
url=self._build_url('subscriptions',base_url=self._api)
403403
returnself._iter(int(number),url,Repository,etag=etag)
404-
405-
@requires_auth
406-
defupdate(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-
ifjson:
427-
self._update_attributes(json)
428-
returnTrue
429-
returnFalse

‎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
assertself.g.unstar('sigmavirus24','github3.py')
185185
self.mock_assertions()
186186

187-
deftest_update_user(self):
188-
self.login()
189-
args= ('Ian Cordasco','example@mail.com','www.blog.com','company',
190-
'loc',True,'bio')
191-
192-
withmock.patch.object(github3.github.GitHub,'user')asuser:
193-
withmock.patch.object(github3.users.User,'update')asupd:
194-
user.return_value=github3.users.User(load('user'),self.g)
195-
upd.return_value=True
196-
assertself.g.update_user(*args)
197-
assertuser.called
198-
assertupd.called
199-
upd.assert_called_with(*args)
200-
201187
deftest_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
assertself.user.is_following('kennethreitz')
189189
self.mock_assertions()
190190

191-
deftest_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-
assertself.user.update(**self.conf['data'])
208-
self.mock_assertions()
209-
210-
self.response('',404)
211-
assertself.user.update(**self.conf['data'])isFalse
212-
213191
deftest_equality(self):
214192
u=github3.users.User(load('user'))
215193
assertself.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+
deftest_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
deftest_user(self):
266279
"""Test that a user can retrieve information about any user."""
267280
self.instance.user('username')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp