8000 Update JSON data in refresh() · goodwillcoding/github3.py@6290a69 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6290a69

Browse files
committed
Update JSON data in refresh()
Otherwise, only attributes handled in _update_attributes() are refreshed and new values from the response are not available.
1 parent f6948ac commit 6290a69

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

AUTHORS.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,6 @@ Contributors
127127

128128
- Matthew Krueger (@mlkrueger1987)
129129

130-
- Dejan Svetec (@dsvetec)
130+
- Dejan Svetec (@dsvetec)
131+
132+
- Billy Keyes (@bluekeyes)

github3/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ def refresh(self, conditional=False):
285285
headers = headers or None
286286
json = self._json(self._get(self._api, headers=headers), 200)
287287
if json is not None:
288+
self._json_data = json
288289
self._update_attributes(json)
289290
return self
290291

tests/unit/test_models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
import json
23
import pytest
34
import requests
45

@@ -184,6 +185,21 @@ def test_refresh_etag(self):
184185
headers=expected_headers,
185186
)
186187

188+
def test_refresh_json(self):
189+
"""Verify refreshing an object updates stored json data."""
190+
expected_data = {
191+
'changed_files': 4
192+
}
193+
response = requests.Response()
194+
response.status_code = 200
195+
response.raw = io.BytesIO(json.dumps(expected_data).encode('utf8'))
196+
self.session.get.return_value = response
197+
198+
self.instance.refresh()
199+
200+
assert 'changed_files' in self.instance.as_dict()
201+
assert self.instance.changed_files == 4
202+
187203
def test_strptime(self):
188204
"""Verify that method converts ISO 8601 formatted string."""
189205
dt = self.instance._strptime('2015-06-18T19:53:04Z')

0 commit comments

Comments
 (0)
0