diff options
-rw-r--r-- | github3/api.py | 29 | ||||
-rw-r--r-- | github3/handlers/__init__.py | 2 | ||||
-rw-r--r-- | github3/handlers/gists.py | 3 | ||||
-rw-r--r-- | github3/handlers/users.py (renamed from github3/handlers/user.py) | 0 | ||||
-rw-r--r-- | github3/tests/base_test.py | 29 | ||||
-rw-r--r-- | github3/tests/gist_tests.py (renamed from tests/gist_tests.py) | 6 | ||||
-rw-r--r-- | run_tests.sh | 1 |
7 files changed, 64 insertions, 6 deletions
diff --git a/github3/api.py b/github3/api.py index b7435ff..e9eebb5 100644 --- a/github3/api.py +++ b/github3/api.py @@ -6,6 +6,7 @@ import requests import json from errors import GithubError +from handlers import users, gists RESOURCES_PER_PAGE = 100 @@ -126,4 +127,30 @@ class GithubCore(object): return response class Github(GithubCore): - pass + """ Library enter """ + + def __init__(self, *args): + super(Github, self).__init__() + self.authenticated = False + auth = len(args) + if auth == 2: # Basic auth + self.session.auth = tuple(map(str,args)) + self.authenticated = True + elif auth == 1: # Token oauth + raise NotImplementedError + elif auth > 2: + raise TypeError("user, password or token") + + @property + def users(self): + if self.authenticated: + return users.AuthUser(self) + else: + return users.User(self) + + @property + def gists(self): + if self.authenticated: + return gists.AuthGist(self) + else: + return gists.Gist(self) diff --git a/github3/handlers/__init__.py b/github3/handlers/__init__.py index e69de29..3ac5fdc 100644 --- a/github3/handlers/__init__.py +++ b/github3/handlers/__init__.py @@ -0,0 +1,2 @@ +import users +import gists diff --git a/github3/handlers/gists.py b/github3/handlers/gists.py index 15f215c..fa961b2 100644 --- a/github3/handlers/gists.py +++ b/github3/handlers/gists.py @@ -20,6 +20,9 @@ class Gist(Handler): return self._get_resource(gist_id, model=models.Gist) + +class AuthGist(Gist): + def create_gist(self, description, public=True, files={}): """ Create a gist """ data = {'description': description, diff --git a/github3/handlers/user.py b/github3/handlers/users.py index fb893b4..fb893b4 100644 --- a/github3/handlers/user.py +++ b/github3/handlers/users.py diff --git a/github3/tests/base_test.py b/github3/tests/base_test.py new file mode 100644 index 0000000..59d474a --- /dev/null +++ b/github3/tests/base_test.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from unittest import TestCase +import github3 +from github3 import api +from github3 import handlers + + +class TestGetHandlers(TestCase): + + def setUp(self): + self.anom_gh = api.Github() + self.auth_gh = api.Github('test', 'password') + + def test_get_user(self): + anom_user = self.anom_gh.users + auth_user = self.auth_gh.users + + self.assertEquals(isinstance(anom_user, handlers.users.User), True) + self.assertEquals(isinstance(auth_user, handlers.users.AuthUser), True) + + def test_get_gists(self): + anom_gists = self.anom_gh.gists + auth_gists = self.auth_gh.gists + + self.assertEquals(isinstance(anom_gists, handlers.gists.Gist), True) + self.assertEquals( + isinstance(auth_gists, handlers.gists.AuthGist), True) diff --git a/tests/gist_tests.py b/github3/tests/gist_tests.py index 7e31066..1218772 100644 --- a/tests/gist_tests.py +++ b/github3/tests/gist_tests.py @@ -23,7 +23,7 @@ class GistsTestCase(unittest.TestCase): g = github3.api.Github() g.session.auth = ('testuser', 'password') u = github3.handlers.user.AuthUser(g) - gists = github3.handlers.gists.Gist(g) + gists = github3.handlers.gists.AuthGist(g) OpenerDirector = MagicMock(name='OpenerDirector') opener = OpenerDirector.return_value response = opener.open.return_value @@ -96,7 +96,3 @@ class GistHandlerTestCase(unittest.TestCase): u'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef') self.assertEqual(h.user.__dict__, gist.user.__dict__) self.assertEqual(h.version, u'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef') - - -if __name__ == '__main__': - unittest.main() diff --git a/run_tests.sh b/run_tests.sh new file mode 100644 index 0000000..5b110e5 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1 @@ +nosetests |