Skip to content

Commit eb6b5e4

Browse files
committed
Init test enviroment
Also rename user handler module to 'users'
1 parent 457210d commit eb6b5e4

File tree

7 files changed

+64
-6
lines changed

7 files changed

+64
-6
lines changed

github3/api.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import requests
77
import json
88
from errors import GithubError
9+
from handlers import users, gists
910

1011
RESOURCES_PER_PAGE = 100
1112

@@ -126,4 +127,30 @@ def _request(self, verb, request, **kwargs):
126127
return response
127128

128129
class Github(GithubCore):
129-
pass
130+
""" Library enter """
131+
132+
def __init__(self, *args):
133+
super(Github, self).__init__()
134+
self.authenticated = False
135+
auth = len(args)
136+
if auth == 2: # Basic auth
137+
self.session.auth = tuple(map(str,args))
138+
self.authenticated = True
139+
elif auth == 1: # Token oauth
140+
raise NotImplementedError
141+
elif auth > 2:
142+
raise TypeError("user, password or token")
143+
144+
@property
145+
def users(self):
146+
if self.authenticated:
147+
return users.AuthUser(self)
148+
else:
149+
return users.User(self)
150+
151+
@property
152+
def gists(self):
153+
if self.authenticated:
154+
return gists.AuthGist(self)
155+
else:
156+
return gists.Gist(self)

github3/handlers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import users
2+
import gists

github3/handlers/gists.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def get(self, gist_id):
2020

2121
return self._get_resource(gist_id, model=models.Gist)
2222

23+
24+
class AuthGist(Gist):
25+
2326
def create_gist(self, description, public=True, files={}):
2427
""" Create a gist """
2528
data = {'description': description,

github3/tests/base_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
from unittest import TestCase
5+
import github3
6+
from github3 import api
7+
from github3 import handlers
8+
9+
10+
class TestGetHandlers(TestCase):
11+
12+
def setUp(self):
13+
self.anom_gh = api.Github()
14+
self.auth_gh = api.Github('test', 'password')
15+
16+
def test_get_user(self):
17+
anom_user = self.anom_gh.users
18+
auth_user = self.auth_gh.users
19+
20+
self.assertEquals(isinstance(anom_user, handlers.users.User), True)
21+
self.assertEquals(isinstance(auth_user, handlers.users.AuthUser), True)
22+
23+
def test_get_gists(self):
24+
anom_gists = self.anom_gh.gists
25+
auth_gists = self.auth_gh.gists
26+
27+
self.assertEquals(isinstance(anom_gists, handlers.gists.Gist), True)
28+
self.assertEquals(
29+
isinstance(auth_gists, handlers.gists.AuthGist), True)
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_create_gist(self):
2323
g = github3.api.Github()
2424
g.session.auth = ('testuser', 'password')
2525
u = github3.handlers.user.AuthUser(g)
26-
gists = github3.handlers.gists.Gist(g)
26+
gists = github3.handlers.gists.AuthGist(g)
2727
OpenerDirector = MagicMock(name='OpenerDirector')
2828
opener = OpenerDirector.return_value
2929
response = opener.open.return_value
@@ -96,7 +96,3 @@ def test_response_conversion(self):
9696
u'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
9797
self.assertEqual(h.user.__dict__, gist.user.__dict__)
9898
self.assertEqual(h.version, u'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
99-
100-
101-
if __name__ == '__main__':
102-
unittest.main()

run_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nosetests

0 commit comments

Comments
 (0)