diff options
author | 2011-11-14 00:46:46 +0100 | |
---|---|---|
committer | 2011-11-14 00:47:24 +0100 | |
commit | 0664d60525f03ba5cbeee080b3d69a4f79bd249a (patch) | |
tree | 57016551b9a78823423df61f9d6ee3d5499765be /github3/tests | |
parent | Added user and limit in all User handler methods (diff) | |
download | python-github3-0664d60525f03ba5cbeee080b3d69a4f79bd249a.tar.xz python-github3-0664d60525f03ba5cbeee080b3d69a4f79bd249a.zip |
Complete anonymous User handler test
Diffstat (limited to 'github3/tests')
-rw-r--r-- | github3/tests/fixtures.py | 71 | ||||
-rw-r--r-- | github3/tests/user_handler_test.py | 84 |
2 files changed, 149 insertions, 6 deletions
diff --git a/github3/tests/fixtures.py b/github3/tests/fixtures.py index fdbc3fb..469b00a 100644 --- a/github3/tests/fixtures.py +++ b/github3/tests/fixtures.py @@ -22,12 +22,13 @@ GET_USER = { "type": "User" } -GET_LINK = '<https://api.github.com/gists/public?page=2>; rel="next", <https://api.github.com/gists/public?page=5>; rel="last"' +GET_LINK = '<https://api.github.com/gists/public?page=2>; rel="next", \ +<https://api.github.com/gists/public?page=5>; rel="last"' GET_RESOURCES = [ {'login': 'octocat'}, {'login': 'octocat'} ] -GET_FOLLOWERS = [ +GET_SHORT_USERS = [ { "login": "octocat", "id": 1, @@ -41,3 +42,69 @@ GET_FOLLOWERS = [ "url": "https://api.github.com/users/octocat" }, ] +GET_SHORT_ORGS = [ + { + "login": "github", + "id": 1, + "url": "https://api.github.com/orgs/1", + "avatar_url": "https://github.com/images/error/octocat_happy.gif" + } +] + +GET_SHORT_REPOS = [ + { + "url": "https://api.github.com/repos/octocat/Hello-World", + "html_url": "https://github.com/octocat/Hello-World", + "clone_url": "https://github.com/octocat/Hello-World.git", + "git_url": "git://github.com/octocat/Hello-World.git", + "ssh_url": "git@github.com:octocat/Hello-World.git", + "svn_url": "https://svn.github.com/octocat/Hello-World", + "owner": { + "login": "octocat", + "id": 1, + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "url": "https://api.github.com/users/octocat" + }, + "name": "Hello-World", + "description": "This your first repo!", + "homepage": "https://github.com", + "language": None, + "private": False, + "fork": False, + "forks": 9, + "watchers": 80, + "size": 108, + "master_branch": "master", + "open_issues": 0, + "pushed_at": "2011-01-26T19:06:43Z", + "created_at": "2011-01-26T19:01:12Z" + } +] +GET_SHORT_GISTS = [ + { + "url": "https://api.github.com/gists/1", + "id": "1", + "description": "description of gist", + "public": True, + "user": { + "login": "octocat", + "id": 1, + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "url": "https://api.github.com/users/octocat" + }, + "files": { + "ring.erl": { + "size": 932, + "filename": "ring.erl", + "raw_url": "https://gist.github.com/raw/365370/8c4d2d43d178df\ + 44f4c03a7f2ac0ff512853564e/ring.erl", + "content": "contents of gist" + } + }, + "comments": 0, + "html_url": "https://gist.github.com/1", + "git_pull_url": "git://gist.github.com/1.git", + "git_push_url": "git@gist.github.com:1.git", + "created_at": "2010-04-14T02:15:15Z" + } +] diff --git a/github3/tests/user_handler_test.py b/github3/tests/user_handler_test.py index 9eb3708..ef57925 100644 --- a/github3/tests/user_handler_test.py +++ b/github3/tests/user_handler_test.py @@ -5,10 +5,17 @@ from unittest import TestCase from mock import Mock, patch from github3 import api from fixtures import * -from github3.models.user import User, AuthUser +from github3.models import User, AuthUser, Repo, Gist, Org from github3.exceptions import * +class TestAuthUserHandler(TestCase): + """ Test private api about user logged """ + + def setUp(self): + pass + + class TestUserHandler(TestCase): """ Test public api about users """ @@ -51,8 +58,77 @@ class TestUserHandler(TestCase): @patch.object(api.Github, '_request') def test_get_followers(self, request): response = request.return_value - response.headers = {'link': GET_LINK} # 5 pages - response.content = self.gh._parser.dumps(GET_FOLLOWERS) + response.headers = {'link': GET_LINK} + response.content = self.gh._parser.dumps(GET_SHORT_USERS) # 2 users followers = list(self.handler.get_followers('test')) + request.assert_called_with('GET', 'users/test/followers', page=5) self.assertIsInstance(followers[0], User) - pass + self.assertEquals(len(followers), 10) + followers = list(self.handler.get_followers('test', limit=2)) + self.assertEquals(len(followers), 2) + self.assertEquals(followers[0].login, 'octocat') + + @patch.object(api.Github, '_request') + def test_get_following(self, request): + response = request.return_value + response.headers = {'link': GET_LINK} + response.content = self.gh._parser.dumps(GET_SHORT_USERS) # 2 users + following = list(self.handler.get_following('test')) + request.assert_called_with('GET', 'users/test/following', page=5) + self.assertIsInstance(following[0], User) + self.assertEquals(len(following), 10) + following = list(self.handler.get_following('test', limit=2)) + self.assertEquals(len(following), 2) + + @patch.object(api.Github, '_request') + def test_get_repos(self, request): + response = request.return_value + response.headers = {'link': GET_LINK} + response.content = self.gh._parser.dumps(GET_SHORT_REPOS) # 1 repo + repos = list(self.handler.get_repos('test')) + request.assert_called_with('GET', 'users/test/repos', page=5) + self.assertIsInstance(repos[0], Repo) + self.assertEquals(len(repos), 5) + repos = list(self.handler.get_repos('test', limit=2)) + self.assertEquals(len(repos), 2) + self.assertIsInstance(repos[0].owner, User) + + @patch.object(api.Github, '_request') + def test_get_watched(self, request): + response = request.return_value + response.headers = {'link': GET_LINK} + response.content = self.gh._parser.dumps(GET_SHORT_REPOS) # 1 repo + watched = list(self.handler.get_watched('test')) + request.assert_called_with('GET', 'users/test/watched', page=5) + self.assertIsInstance(watched[0], Repo) + self.assertEquals(len(watched), 5) + watched = list(self.handler.get_watched('test', limit=2)) + self.assertEquals(len(watched), 2) + + @patch.object(api.Github, '_request') + def test_get_orgs(self, request): + response = request.return_value + response.headers = {'link': GET_LINK} + response.content = self.gh._parser.dumps(GET_SHORT_ORGS) # 1 repo + orgs = list(self.handler.get_orgs('test')) + request.assert_called_with('GET', 'users/test/orgs', page=5) + self.assertIsInstance(orgs[0], Org) + self.assertEquals(len(orgs), 5) + orgs = list(self.handler.get_orgs('test', limit=2)) + self.assertEquals(len(orgs), 2) + self.assertEquals(orgs[0].login, 'github') + + @patch.object(api.Github, '_request') + def test_get_gists(self, request): + response = request.return_value + response.headers = {'link': GET_LINK} + response.content = self.gh._parser.dumps(GET_SHORT_GISTS) # 1 repo + gists = list(self.handler.get_gists('test')) + request.assert_called_with('GET', 'users/test/gists', page=5) + self.assertIsInstance(gists[0], Gist) + self.assertEquals(len(gists), 5) + gists = list(self.handler.get_gists('test', limit=2)) + self.assertEquals(len(gists), 2) + self.assertIsInstance(gists[0].files, dict) + from github3.models.gists import File + self.assertIsInstance(gists[0].files['ring.erl'], File) |