aboutsummaryrefslogtreecommitdiffstats
path: root/github3
diff options
context:
space:
mode:
Diffstat (limited to 'github3')
-rw-r--r--github3/handlers/base.py2
-rw-r--r--github3/handlers/users.py5
-rw-r--r--github3/tests/fixtures.py36
-rw-r--r--github3/tests/user_handler_test.py34
4 files changed, 72 insertions, 5 deletions
diff --git a/github3/handlers/base.py b/github3/handlers/base.py
index c27b80c..0b3fa8a 100644
--- a/github3/handlers/base.py
+++ b/github3/handlers/base.py
@@ -15,7 +15,7 @@ class Handler(object):
def _prefix_resource(self, resource):
prefix = getattr(self, 'prefix', '')
- return '/'.join((prefix, resource)).strip('/')
+ return '/'.join((prefix, str(resource))).strip('/')
def _get_converter(self, **kwargs):
converter = kwargs.get(
diff --git a/github3/handlers/users.py b/github3/handlers/users.py
index 0b84107..84180b5 100644
--- a/github3/handlers/users.py
+++ b/github3/handlers/users.py
@@ -166,10 +166,9 @@ class AuthUser(User):
:param `user`: User model or username string
- NOTE: Maybe bug in API, return text/html. Waitingf for answer
"""
- parse_user = str(getattr(user, 'login', user))
+ parse_user = getattr(user, 'login', user)
return self._put('following/%s' % parse_user)
def unfollow(self, user):
@@ -179,7 +178,7 @@ class AuthUser(User):
:param `user`: User model or username string
"""
- parse_user = str(getattr(user, 'login', user))
+ parse_user = getattr(user, 'login', user)
return self._delete('following/%s' % parse_user)
def get_keys(self):
diff --git a/github3/tests/fixtures.py b/github3/tests/fixtures.py
index 02086f8..5f56753 100644
--- a/github3/tests/fixtures.py
+++ b/github3/tests/fixtures.py
@@ -117,3 +117,39 @@ GET_SHORT_GISTS = [
"created_at": "2010-04-14T02:15:15Z"
}
]
+GET_FULL_USER = {
+ "login": "octocat",
+ "id": 1,
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "gravatar_id": "somehexcode",
+ "url": "https://api.github.com/users/octocat",
+ "name": "monalisa octocat",
+ "company": "GitHub",
+ "blog": "https://github.com/blog",
+ "location": "San Francisco",
+ "email": "octocat@github.com",
+ "hireable": False,
+ "bio": "There once was...",
+ "public_repos": 2,
+ "public_gists": 1,
+ "followers": 20,
+ "following": 0,
+ "html_url": "https://github.com/octocat",
+ "created_at": "2008-01-14T04:33:35Z",
+ "type": "User",
+ "total_private_repos": 100,
+ "owned_private_repos": 100,
+ "private_gists": 81,
+ "disk_usage": 10000,
+ "collaborators": 8,
+ "plan": {
+ "name": "Medium",
+ "space": 400,
+ "collaborators": 10,
+ "private_repos": 20
+ }
+}
+GET_USER_EMAILS = [
+ "octocat@github.com",
+ "support@github.com"
+]
diff --git a/github3/tests/user_handler_test.py b/github3/tests/user_handler_test.py
index ef57925..b1fd0d0 100644
--- a/github3/tests/user_handler_test.py
+++ b/github3/tests/user_handler_test.py
@@ -13,8 +13,40 @@ class TestAuthUserHandler(TestCase):
""" Test private api about user logged """
def setUp(self):
- pass
+ self.gh = api.Github('test', 'pass')
+ self.handler = self.gh.users
+ @patch.object(api.Github, 'get')
+ def test_get(self, get):
+ get.return_value = GET_FULL_USER
+ user = self.handler.get()
+ self.assertIsInstance(user, AuthUser)
+ get.assert_called_with('user')
+ self.assertEquals(len(user), len(GET_FULL_USER))
+
+ @patch.object(api.Github, 'get')
+ def test_get_emails(self, get):
+ get.return_value = GET_USER_EMAILS
+ emails = self.handler.get_emails()
+ get.assert_called_with('user/emails')
+ self.assertEquals(emails, GET_USER_EMAILS)
+
+ @patch.object(api.Github, 'post')
+ def test_create_emails(self, post):
+ post.return_value = GET_USER_EMAILS
+ emails = self.handler.create_emails(*GET_USER_EMAILS)
+ post.assert_called_with('user/emails', data=GET_USER_EMAILS)
+ self.assertEquals(emails, GET_USER_EMAILS)
+
+ @patch.object(api.Github, 'delete')
+ def test_delete_emails(self, delete):
+ response = delete.return_value
+ response.return_value = ''
+ response.status_code = 204
+ emails = self.handler.delete_emails(*GET_USER_EMAILS)
+ delete.assert_called_with('user/emails', data=GET_USER_EMAILS,
+ method='delete')
+ self.assertTrue(emails)
class TestUserHandler(TestCase):
""" Test public api about users """