10000 Removed GitHubObject from models by itsmemattchung · Pull Request #577 · sigmavirus24/github3.py · GitHub
[go: up one dir, main page]

Skip to content

Removed GitHubObject from models #577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 20 additions & 31 deletions github3/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,26 @@
__logs__ = getLogger(__package__)


class GitHubObject(object):
"""The :class:`GitHubObject <GitHubObject>` object. A basic class to be
subclassed by GitHubCore and other classes that would otherwise subclass
object."""
def __init__(self, json):
super(GitHubObject, self).__init__()
class GitHubCore(object):

"""The base object for all objects that require a session.

The :class:`GitHubCore <GitHubCore>` object provides some
basic attributes and methods to other sub-classes that are very useful to
have.
"""

def __init__(self, json, session=None):
if hasattr(session, 'session'):
# i.e. session is actually a GitHubCore instance
session = session.session
elif session is None:
session = GitHubSession()
self.session = session

# set a sane default
self._github_url = 'https://api.github.com'

if json is not None:
self.etag = json.pop('ETag', None)
self.last_modified = json.pop('Last-Modified', None)
Expand Down Expand Up @@ -87,9 +101,6 @@ def _strptime(self, time_str):
return dt.replace(tzinfo=UTC())
return None

def _repr(self):
return '<github3-object at 0x{0:x}>'.format(id(self))

def __repr__(self):
repr_string = self._repr()
if is_py2:
Expand All @@ -115,28 +126,6 @@ def __ne__(self, other):
def __hash__(self):
return hash(self._uniq)


class GitHubCore(GitHubObject):

"""The base object for all objects that require a session.

The :class:`GitHubCore <GitHubCore>` object provides some
basic attributes and methods to other sub-classes that are very useful to
have.
"""

def __init__(self, json, session=None):
if hasattr(session, 'session'):
# i.e. session is actually a GitHubCore instance
session = session.session
elif session is None:
session = GitHubSession()
self.session = session

# set a sane default
self._github_url = 'https://api.github.com'
super(GitHubCore, self).__init__(json)

def _repr(self):
return '<github3-core at 0x{0:x}>'.format(id(self))

Expand Down
Empty file added github3/models/githubcore.py
Empty file.
53 changes: 17 additions & 36 deletions tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from datetime import datetime, timedelta
from github3 import exceptions, GitHubError
from github3.models import GitHubCore, GitHubObject
from github3.models import GitHubCore
from unittest import TestCase
from . import helper

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


class MyGetAttrTestClass(GitHubObject):
"""Subclass for testing getattr on GitHubObject."""

def __init__(self, example_data, session=None):
super(MyGetAttrTestClass, self).__init__(example_data)

def _update_attributes(self, json_data):
self.fake_attr = json_data.get('fake_attr')


class TestGitHubError(TestCase):
"""Test methods on GitHubError class."""

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


class TestGitHubObject(helper.UnitHelper):
"""Test methods on GitHubObject class."""

described_class = MyGetAttrTestClass
example_data = {
'fake_attr': 'foo',
'another_fake_attr': 'bar'
}

def test_from_json(self):
"""Verify that method returns GitHubObject from json."""
github_object = GitHubObject.from_json('{}')
assert isinstance(github_object, GitHubObject)

def test_exposes_attributes(self):
"""Verify JSON attributes are exposed even if not explicitly set."""
assert self.instance.another_fake_attr == 'bar'

def test_missingattribute(self):
"""Test AttributeError is raised when attribute is not in JSON."""
with pytest.raises(AttributeError):
self.instance.missingattribute


class TestGitHubCore(helper.UnitHelper):

described_class = MyTestRefreshClass
Expand All @@ -90,7 +56,8 @@ class TestGitHubCore(helper.UnitHelper):
example_data = {
'url': url,
'last_modified': last_modified,
'etag': etag
'etag': etag,
'fake_attr': 'foo',
}

def test_boolean(self):
Expand Down Expand Up @@ -130,6 +97,15 @@ def test_boolean_empty_response(self):

assert boolean is False

def test_exposes_attributes(self):
"""Verify JSON attributes are exposed even if not explicitly set."""
assert self.instance.fake_attr == 'foo'

def test_from_json(self):
"""Verify that method returns GitHubObject from json."""
github_core = GitHubCore.from_json('{}')
assert isinstance(github_core, GitHubCore)

def test_json(self):
"""Verify JSON information is retrieved correctly."""
response = requests.Response()
Expand All @@ -150,6 +126,11 @@ def test_json_status_code_does_not_match(self):
json = self.instance._json(response, 200)
assert json is None

def test_missingattribute(self):
"""Test AttributeError is raised when attribute is not in JSON."""
with pytest.raises(AttributeError):
self.instance.missingattribute

def test_refresh(self):
"""Verify the request of refreshing an object."""
instance = self.instance.refresh()
Expand Down
0