Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pomegranited committed Jul 4, 2017
1 parent bb88ed1 commit 3a9ec7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
17 changes: 7 additions & 10 deletions openassessment/fileupload/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import shutil
import tempfile
import urllib
from urlparse import urlparse

from django.conf import settings
Expand Down Expand Up @@ -370,8 +371,7 @@ def test_get_download_url_no_object(self, requests_get_mock):
@override_settings(
ORA2_FILEUPLOAD_BACKEND="django",
DEFAULT_FILE_STORAGE="django.core.files.storage.FileSystemStorage",
FILE_UPLOAD_STORAGE_PREFIX="submissions_attachments",
MEDIA_ROOT="/tmp",
FILE_UPLOAD_STORAGE_PREFIX="submissions",
)
@ddt.ddt
class TestFileUploadServiceWithDjangoStorageBackend(TestCase):
Expand Down Expand Up @@ -428,14 +428,10 @@ def test_upload_download(self, key):
response = self.client.put(upload_url, data=self.content.read(), content_type=self.content_type)
self.assertEqual(200, response.status_code)

# Download file
# Check updated download URL
download_url = self.backend.get_download_url(self.key)
self.assertIsNotNone(download_url)
print download_url
response = self.client.get(download_url)
self.assertEqual(200, response.status_code)
self.assertEqual(self.content_type, response.get('Content-Type'))
self.assertEqual(self.content, response.content)
encoded_key = urllib.quote(self.key.encode('utf-8'))
self.assertEqual(u"submissions/{}".format(encoded_key), download_url)

@ddt.data(u"noël.txt", "myfile.txt")
def test_remove(self, key):
Expand All @@ -455,7 +451,8 @@ def test_remove(self, key):

# File exists now
download_url = self.backend.get_download_url(self.key)
self.assertIsNotNone(download_url)
encoded_key = urllib.quote(self.key.encode('utf-8'))
self.assertEqual(u"submissions/{}".format(encoded_key), download_url)

# Remove file returns True now, and removes the file
self.assertTrue(self.backend.remove_file(self.key))
Expand Down
2 changes: 0 additions & 2 deletions openassessment/fileupload/views_django_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ def django_storage(request, key):
"""
Upload files using django storage backend.
"""
if isinstance(key, unicode):
key = key.encode("utf-8")
Backend().upload_file(key, request.body)
return HttpResponse()

0 comments on commit 3a9ec7e

Please sign in to comment.