-
-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[s3] fix saving files with string content (#911)
* Add alternate .venv to gitignore * Add moto as test dependency. * Add ReadBytesWrapper utility class for wrapping a file-like object. This makes .read() always return bytes. If .read() returns a string, it will be encoded to bytes before being returned. The encoding to use can be specified, otherwise will use the .encoding property of the original file, otherwise will use utf-8. * Fix issue #708: Make _save() wrap content in a ReadBytesWrapper. This correctly handles file-like-objects that are open in text/string mode by converting to strings returned by read() to bytes, which is what upload_fileobj() requires. This is done before gzip compressing, so also removed force_bytes() call in _compress_content(). * Add tests for saving both File/ContentFile with string/bytes. Add these tests in a new test class that uses moto. Remove old test for saving ContentFile Move test for detecting content-type to this new class. Add some more tests around this. Fix tests that fail because settings.AWS_STORAGE_BUCKET_NAME is now defined. Fix tests that fail because content is always wrapped. Fix test for gzipped file since that now only takes bytes. * tweaks * add close to ReadBytesWrapper * add readable to ReadBytesWrapper --------- Co-authored-by: Josh Schneier <josh.schneier@gmail.com>
- Loading branch information
1 parent
89ca5bc
commit 19a15c2
Showing
8 changed files
with
230 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ __pycache__ | |
.vscode/ | ||
.pytest_cache/ | ||
venv/ | ||
.venv/ | ||
|
||
dist/ | ||
docs/_build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
��� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.