44
55from datetime import datetime , timedelta
66from github3 import exceptions , GitHubError
7- from github3 .models import GitHubCore , GitHubObject
7+ from github3 .models import GitHubCore
88from unittest import TestCase
99from . 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-
3121class 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-
8248class 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