File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ def _update_attributes(self, content):
85
85
self .content = content .get ("content" )
86
86
self .encoding = content .get ("encoding" )
87
87
self .decoded = self .content
88
- if self .encoding == "base64" and self .content :
88
+ if self .encoding == "base64" and self .content is not None :
89
89
self .decoded = b64decode (self .content .encode ())
90
90
self .download_url = content ["download_url" ]
91
91
self .git_url = content ["git_url" ]
Original file line number Diff line number Diff line change @@ -582,6 +582,30 @@ def test_file_contents(self):
582
582
url_for ("contents/path/to/file.txt" ), params = {"ref" : "some-sha" }
583
583
)
584
584
585
+ def test_file_contents_works_for_empty_file (self ):
586
+ """Verify file_contents works for an empty file edge case."""
587
+ mock_response = unittest .mock .MagicMock (status_code = 200 )
588
+ mock_response .json .return_value = {
589
+ "content" : "" ,
590
+ "download_url" : "" ,
591
+ "encoding" : "base64" ,
592
+ "git_url" : "" ,
593
+ "html_url" : "" ,
594
+ "name" : "" ,
595
+ "path" : "" ,
596
+ "sha" : "" ,
597
+ "size" : "" ,
598
+ "type" : "" ,
599
+ "url" : "" ,
600
+ "_links" : "" ,
601
+ }
602
+ self .session .get .return_value = mock_response
603
+
604
+ file_contents = self .instance .file_contents (
605
+ "path/to/empty_file.txt" , ref = "some-sha"
606
+ )
607
+ assert file_contents .decoded == b""
608
+
585
609
def test_git_commit_required_sha (self ):
586
610
"""Verify the request for retrieving a git commit from a repository."""
587
611
self .instance .git_commit ("" )
You can’t perform that action at this time.
0 commit comments