This repository has been archived by the owner on Mar 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix and re-include file upload tests
It is important that we test this functionality
- Loading branch information
1 parent
62069e0
commit d5b865e
Showing
8 changed files
with
97 additions
and
55 deletions.
There are no files selected for viewing
Binary file not shown.
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
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 |
---|---|---|
@@ -1,13 +1,49 @@ | ||
from cStringIO import StringIO | ||
import io | ||
import os | ||
import unittest | ||
import werkzeug.datastructures | ||
from backdrop.write.uploaded_file import UploadedFile | ||
|
||
|
||
class FileUploadTestCase(unittest.TestCase): | ||
def _file_storage_wrapper(self, contents, filename="test", content_type=None, content_length=None): | ||
stream = io.StringIO(initial_value=unicode(contents)) | ||
def _file_storage_wrapper(self, contents, server_filename='/tmp/uploaded_file', | ||
browser_filename='browser_filename.txt', content_type=None, content_length=None): | ||
with open(server_filename, 'w') as f: | ||
f.write(contents) | ||
g = open(server_filename, 'r') | ||
|
||
storage = werkzeug.datastructures \ | ||
.FileStorage(stream=stream, filename = filename, | ||
.FileStorage(stream=g, | ||
filename=browser_filename, | ||
content_type=content_type, | ||
content_length=content_length) | ||
return storage | ||
|
||
def _uploaded_file_wrapper(self, contents=None, fixture_name=None): | ||
if len([i for i in [contents, fixture_name] if i is not None]) != 1: | ||
raise TypeError("Takes one of contents or fixture_name argument") | ||
|
||
if contents is not None: | ||
server_filename = '/tmp/file.txt' | ||
file_storage = self._file_storage_wrapper( | ||
contents=contents, | ||
server_filename=server_filename) | ||
|
||
upload = UploadedFile( | ||
file_storage, | ||
server_filename | ||
) | ||
return upload | ||
|
||
elif fixture_name is not None: | ||
full_filename = fixture_path = os.path.join('features', 'fixtures', fixture_name) | ||
with open(full_filename, 'rb') as f: | ||
file_storage = self._file_storage_wrapper( | ||
contents=f.read(), | ||
server_filename=full_filename) | ||
upload = UploadedFile( | ||
file_storage, | ||
full_filename # server filename | ||
) | ||
return upload |
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