8000 Make session required for GitHubCore classes · sigmavirus24/github3.py@59d3762 · GitHub
[go: up one dir, main page]

Skip to content

Commit 59d3762

Browse files
committed
Make session required for GitHubCore classes
We want the session to always be there. This change makes it required and updates the various places that broke. Fixes: 771 Signed-off-by: Jesse Keating <omgjlk@github.com>
1 parent 11ec3fb commit 59d3762

16 files changed

+59
-34
lines changed

github3/events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ def _update_attributes(self, event):
119119
event = copy.deepcopy(event)
120120

121121
#: :class:`User <github3.users.User>` object representing the actor.
122-
self.actor = self._class_attribute(event, 'actor', EventUser)
122+
self.actor = self._class_attribute(event, 'actor', EventUser, self)
123123
#: datetime object representing when the event was created.
124124
self.created_at = self._strptime_attribute(event, 'created_at')
125125

126126
#: Unique id of the event
127127
self.id = self._get_attribute(event, 'id')
128128

129129
#: List all possible types of Events
130-
self.org = self._class_attribute(event, 'org', EventOrganization)
130+
self.org = self._class_attribute(event, 'org', EventOrganization, self)
131131

132132
#: Event type https://developer.github.com/v3/activity/events/types/
133133
self.type = self._get_attribute(event, 'type')

github3/git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _update_attributes(self, ref):
108108
self.ref = self._get_attribute(ref, 'ref')
109109

110110
#: :class:`GitObject <GitObject>` the reference points to
111-
self.object = self._class_attribute(ref, 'object', GitObject)
111+
self.object = self._class_attribute(ref, 'object', GitObject, self)
112112

113113
def _repr(self):
114114
return '<Reference [{0}]>'.format(self.ref)
@@ -173,7 +173,7 @@ def _update_attributes(self, tag):
173173
self.tagger = self._get_attribute(tag, 'tagger')
174174

175175
#: :class:`GitObject <GitObject>` for the tag
176-
self.object = self._class_attribute(tag, 'object', GitObject)
176+
self.object = self._class_attribute(tag, 'object', GitObject, self)
177177

178178
def _repr(self):
179179
return '<Tag [{0}]>'.format(self.tag)

github3/github.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .repos import repo
2424
from .search import (CodeSearchResult, IssueSearchResult,
2525
RepositorySearchResult, UserSearchResult)
26+
from .session import GitHubSession
2627
from .structs import SearchIterator
2728
from . import users
2829
from .notifications import Thread
@@ -57,7 +58,8 @@ class GitHub(GitHubCore):
5758
"""
5859

5960
def __init__(self, username='', password='', token=''):
60-
super(GitHub, self).__init__({})
61+
session = GitHubSession()
62+
super(GitHub, self).__init__({}, session)
6163
if token:
6264
self.login(username, token=token)
6365
elif username and password:
@@ -1795,7 +1797,8 @@ class GitHubStatus(GitHubCore):
17951797
return the JSON objects returned by the API.
17961798
"""
17971799
def __init__(self):
1798-
super(GitHubStatus, self).__init__({})
1800+
session = GitHubSession()
1801+
super(GitHubStatus, self).__init__({}, session)
17991802
self.session.base_url = 'https://status.github.com'
18001803

18011804
def _repr(self):

github3/models.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ class GitHubCore(object):
3232
have.
3333
"""
3434

35-
def __init__(self, json, session=None):
35+
def __init__(self, json, session):
3636
if hasattr(session, 'session'):
3737
# i.e. session is actually a GitHubCore instance
3838
session = session.session
39-
elif session is None:
40-
session = GitHubSession()
4139
self.session = session
4240

4341
# set a sane default
@@ -165,14 +163,14 @@ def __repr__(self):
165163
return repr_string
166164

167165
@classmethod
168-
def from_dict(cls, json_dict):
166+
def from_dict(cls, json_dict, session):
169167
"""Return an instance of this class formed from ``json_dict``."""
170-
return cls(json_dict)
168+
return cls(json_dict, session)
171169

172170
@classmethod
173-
def from_json(cls, json):
171+
def from_json(cls, json, session):
174172
"""Return an instance of this class formed from ``json``."""
175-
return cls(loads(json))
173+
return cls(loads(json), session)
176174

177175
def __eq__(self, other):
178176
return self._uniq == other._uniq

github3/repos/pages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def _update_attributes(self, build):
3737
from .. import users
3838
#: :class:`User <github3.users.User>` representing who pushed the
3939
#: commit
40-
self.pusher = self._class_attribute(build, 'pusher', users.ShortUser)
40+
self.pusher = self._class_attribute(build, 'pusher', users.ShortUser,
41+
self)
4142

4243
#: SHA of the commit that triggered the build
4344
self.commit = self._get_attribute(build, 'commit')

github3/repos/status.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _update_attributes(self, status):
3131

3232
#: :class:`User <github3.users.User>` who created the object
3333
self.creator = self._class_attribute(
34-
status, 'creator', users.ShortUser
34+
status, 'creator', users.ShortUser, self
3535
)
3636

3737
#: Short description of the Status

tests/unit/helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def create_instance_of_described_class(self):
8585
instance = self.described_class(self.example_data,
8686
self.session)
8787
elif self.example_data and not self.session:
88-
instance = self.described_class(self.example_data)
88+
session = self.create_session_mock()
89+
instance = self.described_class(self.example_data, session)
8990

9091
else:
9192
instance = self.described_class()

tests/unit/test_events.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
get_gist_example_data = create_example_data_helper('gist_example')
1616
get_team_example_data = create_example_data_helper('team_example')
1717

18+
session = github3.session.GitHubSession()
19+
1820

1921
class TestEvent(UnitHelper):
2022

@@ -37,7 +39,7 @@ def test_org(self):
3739
json = self.instance.as_dict().copy()
3840
org = get_org_example_data()
3941
json['org'] = org
40-
event = github3.events.Event(json)
42+
event = github3.events.Event(json, session)
4143
assert isinstance(event.org, github3.events.EventOrganization)
4244

4345

tests/unit/test_gists.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
'https://api.github.com/gists/e20f1e6c9ca010cabc523a7356217f5a'
2323
)
2424

25+
session = github3.session.GitHubSession()
26+
2527

2628
class TestGist(helper.UnitHelper):
2729
"""Test regular Gist methods."""
@@ -200,7 +202,8 @@ class TestGistHistory(helper.UnitHelper):
200202
def test_equality(self):
201203
"""Show that two instances of a GistHistory are equal."""
202204
history = github3.gists.history.GistHistory(
203-
gist_history_example_data()
205+
gist_history_example_data(),
206+
session
204207
)
205208
assert self.instance == history
206209
history._uniq = 'foo'
@@ -222,7 +225,8 @@ class TestGistComment(helper.UnitHelper):
222225
def test_equality(self):
223226
"""Show that two instances of a GistComment are equal."""
224227
comment = github3.gists.comment.GistComment(
225-
gist_comment_example_data()
228+
gist_comment_example_data(),
229+
session
226230
)
227231
assert self.instance == comment
228232
comment._uniq = '1'

tests/unit/test_git.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
get_git_tag_example_data = create_example_data_helper('git_tag_example')
1515
get_reference_example_data = create_example_data_helper('reference_example')
1616

17+
session = github3.session.GitHubSession()
18+
1719

1820
class TestTree(UnitHelper):
1921
"""Tree unit test"""
@@ -23,12 +25,12 @@ class TestTree(UnitHelper):
2325

2426
def test_eq(self):
2527
"""Assert that two trees are equal."""
26-
tree = github3.git.Tree(get_example_data())
28+
tree = github3.git.Tree(get_example_data(), session)
2729
assert self.instance == tree
2830

2931
def test_ne(self):
3032
"""Assert that two trees are not equal."""
31-
tree = github3.git.Tree(get_example_data())
33+
tree = github3.git.Tree(get_example_data(), session)
3234
tree._json_data['truncated'] = True
3335
assert self.instance != tree
3436

0 commit comments

Comments
 (0)
0