Skip to content

Commit 6c90596

Browse files
author
ekmartin
committed
Default Contents.decoded and .content to None
1 parent 47487d0 commit 6c90596

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

github3/repos/contents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _update_attributes(self, content):
5353

5454
# content, base64 encoded and decoded
5555
#: Base64-encoded content of the file.
56-
self.content = content.get('content', '')
56+
self.content = content.get('content')
5757

5858
#: Decoded content of the file as a bytes object. If we try to decode
5959
#: to character set for you, we might encounter an exception which
@@ -62,7 +62,7 @@ def _update_attributes(self, content):
6262
#: with the character set you wish to use, e.g.,
6363
#: ``content.decoded.decode('utf-8')``.
6464
#: .. versionchanged:: 0.5.2
65-
self.decoded = b''
65+
self.decoded = self.content
6666
if self.encoding == 'base64' and self.content:
6767
self.decoded = b64decode(self.content.encode())
6868

tests/integration/test_repos_repo.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,17 @@ def test_directory_contents(self):
200200
assert content.name == filename
201201
assert isinstance(content, github3.repos.contents.Contents)
202202

203+
def test_directory_contents_content(self):
204+
"""Tests the content/decoded attributes of a directory's file content"""
205+
cassette_name = self.cassette_name('directory_contents')
206+
with self.recorder.use_cassette(cassette_name):
207+
repository = self.gh.repository('sigmavirus24', 'github3.py')
208+
contents = repository.directory_contents('github3/search/')
209+
210+
for (filename, content) in contents:
211+
assert content.content is None
212+
assert content.decoded is None
213+
203214
def test_events(self):
204215
"""Test that a user can iterate over the events from a repository."""
205216
cassette_name = self.cassette_name('events')
@@ -221,6 +232,16 @@ def test_file_contents(self):
221232

222233
assert isinstance(contents, github3.repos.contents.Contents)
223234

235+
def test_file_contents_content(self):
236+
"""Tests that the content and decoded attributes of a file is set"""
237+
cassette_name = self.cassette_name('file_contents')
238+
with self.recorder.use_cassette(cassette_name):
239+
repository = self.gh.repository('sigmavirus24', 'github3.py')
240+
contents = repository.file_contents('github3/repos/repo.py')
241+
242+
assert contents.content is not None
243+
assert contents.decoded is not None
244+
224245
def test_forks(self):
225246
"""Test that a user can iterate over the forks of a repository."""
226247
cassette_name = self.cassette_name('forks')

0 commit comments

Comments
 (0)