8000 Raise exception for instance_or_null · goodwillcoding/github3.py@1322fc8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1322fc8

Browse files
Raise exception for instance_or_null
When the wrong data type is passed to the method, like a list or string, an exception is returned. Instead, we should be raising the exception. I added a single unit test, which asserts that an error is raised. Fixes sigmavirus24#628 and sigmavirus24#627.
1 parent 008cb11 commit 1322fc8

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

github3/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _instance_or_null(self, instance_class, json):
143143
if json is None:
144144
return NullObject(instance_class.__name__)
145145
if not isinstance(json, dict):
146-
return exceptions.UnprocessableResponseBody(
146+
raise exceptions.UnprocessableResponseBody(
147147
"GitHub's API returned a body that could not be handled", json
148148
)
149149
try:

tests/unit/test_models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ def test_from_json(self):
107107
github_core = GitHubCore.from_json('{}')
108108
assert isinstance(github_core, GitHubCore)
109109

110+
def test_instance_or_null(self):
111+
"""Verify method raises exception when json is not a dict."""
112+
with pytest.raises(exceptions.UnprocessableResponseBody):
113+
self.instance._instance_or_null(GitHubCore, [])
114+
110115
def test_json(self):
111116
"""Verify JSON information is retrieved correctly."""
112117
response = requests.Response()

0 commit comments

Comments
 (0)
0