Skip to content

Commit 77067ee

Browse files
Removed GitHubObject from models
Moved existing tests under GitHubObject to GitHubCore
1 parent 447975a commit 77067ee

File tree

3 files changed

+37
-67
lines changed

3 files changed

+37
-67
lines changed

github3/models.py

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,26 @@
2323
__logs__ = getLogger(__package__)
2424

2525

26-
class GitHubObject(object):
27-
"""The :class:`GitHubObject <GitHubObject>` object. A basic class to be
28-
subclassed by GitHubCore and other classes that would otherwise subclass
29-
object."""
30-
def __init__(self, json):
31-
super(GitHubObject, self).__init__()
26+
class GitHubCore(object):
27+
28+
"""The base object for all objects that require a session.
29+
30+
The :class:`GitHubCore <GitHubCore>` object provides some
31+
basic attributes and methods to other sub-classes that are very useful to
32+
have.
33+
"""
34+
35+
def __init__(self, json, session=None):
36+
if hasattr(session, 'session'):
37+
# i.e. session is actually a GitHubCore instance
38+
session = session.session
39+
elif session is None:
40+
session = GitHubSession()
41+
self.session = session
42+
43+
# set a sane default
44+
self._github_url = 'https://api.github.com'
45+
3246
if json is not None:
3347
self.etag = json.pop('ETag', None)
3448
self.last_modified = json.pop('Last-Modified', None)
@@ -87,9 +101,6 @@ def _strptime(self, time_str):
87101
return dt.replace(tzinfo=UTC())
88102
return None
89103

90-
def _repr(self):
91-
return '<github3-object at 0x{0:x}>'.format(id(self))
92-
93104
def __repr__(self):
94105
repr_string = self._repr()
95106
if is_py2:
@@ -115,28 +126,6 @@ def __ne__(self, other):
115126
def __hash__(self):
116127
return hash(self._uniq)
117128

118-
119-
class GitHubCore(GitHubObject):
120-
121-
"""The base object for all objects that require a session.
122-
123-
The :class:`GitHubCore <GitHubCore>` object provides some
124-
basic attributes and methods to other sub-classes that are very useful to
125-
have.
126-
"""
127-
128-
def __init__(self, json, session=None):
129-
if hasattr(session, 'session'):
130-
# i.e. session is actually a GitHubCore instance
131-
session = session.session
132-
elif session is None:
133-
session = GitHubSession()
134-
self.session = session
135-
136-
# set a sane default
137-
self._github_url = 'https://api.github.com'
138-
super(GitHubCore, self).__init__(json)
139-
140129
def _repr(self):
141130
return '<github3-core at 0x{0:x}>'.format(id(self))
142131

github3/models/githubcore.py

Whitespace-only changes.

tests/unit/test_models.py

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from datetime import datetime, timedelta
66
from github3 import exceptions, GitHubError
7-
from github3.models import GitHubCore, GitHubObject
7+
from github3.models import GitHubCore
88
from unittest import TestCase
99
from . import helper
1010

@@ -18,16 +18,6 @@ def __init__(self, example_data, session=None):
1818
self.etag = example_data['etag']
1919

2020

21-
class MyGetAttrTestClass(GitHubObject):
22-
"""Subclass for testing getattr on GitHubObject."""
23-
24-
def __init__(self, example_data, session=None):
25-
super(MyGetAttrTestClass, self).__init__(example_data)
26-
27-
def _update_attributes(self, json_data):
28-
self.fake_attr = json_data.get('fake_attr')
29-
30-
3121
class TestGitHubError(TestCase):
3222
"""Test methods on GitHubError class."""
3323

@@ -55,30 +45,6 @@ def test_str(self):
5545
assert str(self.instance) == '400 m'
5646

5747

58-
class TestGitHubObject(helper.UnitHelper):
59-
"""Test methods on GitHubObject class."""
60-
61-
described_class = MyGetAttrTestClass
62-
example_data = {
63-
'fake_attr': 'foo',
64-
'another_fake_attr': 'bar'
65-
}
66-
67-
def test_from_json(self):
68-
"""Verify that method returns GitHubObject from json."""
69-
github_object = GitHubObject.from_json('{}')
70-
assert isinstance(github_object, GitHubObject)
71-
72-
def test_exposes_attributes(self):
73-
"""Verify JSON attributes are exposed even if not explicitly set."""
74-
assert self.instance.another_fake_attr == 'bar'
75-
76-
def test_missingattribute(self):
77-
"""Test AttributeError is raised when attribute is not in JSON."""
78-
with pytest.raises(AttributeError):
79-
self.instance.missingattribute
80-
81-
8248
class TestGitHubCore(helper.UnitHelper):
8349

8450
described_class = MyTestRefreshClass
@@ -90,7 +56,8 @@ class TestGitHubCore(helper.UnitHelper):
9056
example_data = {
9157
'url': url,
9258
'last_modified': last_modified,
93-
'etag': etag
59+
'etag': etag,
60+
'fake_attr': 'foo',
9461
}
9562

9663
def test_boolean(self):
@@ -130,6 +97,15 @@ def test_boolean_empty_response(self):
13097

13198
assert boolean is False
13299

100+
def test_exposes_attributes(self):
101+
"""Verify JSON attributes are exposed even if not explicitly set."""
102+
assert self.instance.fake_attr == 'foo'
103+
104+
def test_from_json(self):
105+
"""Verify that method returns GitHubObject from json."""
106+
github_core = GitHubCore.from_json('{}')
107+
assert isinstance(github_core, GitHubCore)
108+
133109
def test_json(self):
134110
"""Verify JSON information is retrieved correctly."""
135111
response = requests.Response()
@@ -150,6 +126,11 @@ def test_json_status_code_does_not_match(self):
150126
json = self.instance._json(response, 200)
151127
assert json is None
152128

129+
def test_missingattribute(self):
130+
"""Test AttributeError is raised when attribute is not in JSON."""
131+
with pytest.raises(AttributeError):
132+
self.instance.missingattribute
133+
153134
def test_refresh(self):
154135
"""Verify the request of refreshing an object."""
155136
instance = self.instance.refresh()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy