Skip to content

Commit ce6736a

Browse files
committed
Start work towards sigmavirus24#16.
Also add tests for the stargazers/subscribers functions added yesterday.
1 parent c0e8cdd commit ce6736a

6 files changed

Lines changed: 238 additions & 125 deletions

File tree

github3/decorators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
from functools import wraps
1010
from requests.models import Response
1111

12-
try:
12+
try: # (No coverage)
1313
# python2
14-
from StringIO import StringIO
15-
except ImportError:
14+
from StringIO import StringIO # (No coverage)
15+
except ImportError: # (No coverage)
1616
# python3
17-
from io import BytesIO as StringIO
17+
from io import BytesIO as StringIO # (No coverage)
1818

1919

2020
def requires_auth(func):

github3/github.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ def star(self, login, repo):
688688
resp = self._boolean(self._put(url), 204, 404)
689689
return resp
690690

691+
@requires_auth
691692
def subscribe(self, login, repo):
692693
"""Subscribe to login/repo
693694
@@ -701,6 +702,7 @@ def subscribe(self, login, repo):
701702
resp = self._boolean(self._put(url), 204, 404)
702703
return resp
703704

705+
@requires_auth
704706
def unfollow(self, login):
705707
"""Make the authenticated user stop following login
706708
@@ -714,6 +716,7 @@ def unfollow(self, login):
714716
resp = self._boolean(self._delete(url), 204, 404)
715717
return resp
716718

719+
@requires_auth
717720
def unstar(self, login, repo):
718721
"""Unstar to login/repo
719722
@@ -727,6 +730,7 @@ def unstar(self, login, repo):
727730
resp = self._boolean(self._delete(url), 204, 404)
728731
return resp
729732

733+
@requires_auth
730734
def unsubscribe(self, login, repo):
731735
"""Unsubscribe to login/repo
732736

tests/base.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
import unittest
44
import github3
5-
from expecter import expect, add_expectation
5+
import expecter
66

77

88
class BaseTest(unittest.TestCase):
@@ -38,30 +38,48 @@ def assertAreNotNone(self, obj, *attrs):
3838
self.assertIsNotNone(getattr(obj, attr),
3939
'{0} is None'.format(attr))
4040

41+
def raisesGHE(self, func, *args, **kwargs):
42+
"""Assert that the function, when called, raises a GitHubError."""
43+
with expect.raises(github3.GitHubError):
44+
func(*args, **kwargs)
45+
4146
def expect_list_of_class(self, l, cls):
4247
for i in l:
4348
expect(i).isinstance(cls)
4449

4550

46-
def is_not_None(var):
47-
return var is not None
48-
51+
class CustomExpecter(expecter.expect):
52+
def is_not_None(self):
53+
assert self._actual is not None, (
54+
'Expected anything but None but got it.'
55+
)
4956

50-
def is_None(var):
51-
return var is None
57+
def is_None(self):
58+
assert self._actual is None, (
59+
'Expected None but got %s' % repr(self._actual)
60+
)
5261

62+
def is_True(self):
63+
assert self._actual is True, (
64+
'Expected True but got %s' % repr(self._actual)
65+
)
5366

54-
def is_True(var):
55-
return var is True
67+
def is_False(self):
68+
assert self._actual is False, (
69+
'Expected False but got %s' % repr(self._actual)
70+
)
5671

72+
def list_of(self, cls):
73+
expected = cls.__name__
74+
for actual in self._actual:
75+
actual_cls = actual.__class__.__name__
76+
assert isinstance(actual, cls), (
77+
'Expected instance of %s but got %s' % (expected,
78+
actual_cls)
79+
)
5780

58-
def is_False(var):
59-
return var is False
81+
expect = CustomExpecter
6082

61-
add_expectation(is_not_None)
62-
add_expectation(is_None)
63-
add_expectation(is_True)
64-
add_expectation(is_False)
6583

6684
if sys.version_info >= (3, 0):
6785
str_test = (str, bytes)

0 commit comments

Comments
 (0)