Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactored file_storage tests to avoid depending on servers tests.

  • Loading branch information...
commit 7a65c95d42af421e036c5348f205128dd455a89c 1 parent 96c71d4
@aaugustin aaugustin authored
Showing with 18 additions and 7 deletions.
  1. +11 −7 tests/file_storage/tests.py
  2. +7 −0 tests/file_storage/urls.py
View
18 tests/file_storage/tests.py
@@ -7,6 +7,10 @@
import sys
import tempfile
import time
+try:
+ from urllib.request import urlopen
+except ImportError: # Python 2
+ from urllib2 import urlopen
import zlib
from datetime import datetime, timedelta
from io import BytesIO
@@ -22,12 +26,11 @@
from django.core.files.images import get_image_dimensions
from django.core.files.storage import FileSystemStorage, get_storage_class
from django.core.files.uploadedfile import UploadedFile
-from django.test import SimpleTestCase
+from django.test import LiveServerTestCase, SimpleTestCase
from django.utils import six
from django.utils import unittest
from django.utils._os import upath
from django.test.utils import override_settings
-from servers.tests import LiveServerBase
try:
from django.utils.image import Image
@@ -613,10 +616,13 @@ def test_noname_file_default_name(self):
def test_noname_file_get_size(self):
self.assertEqual(File(BytesIO(b'A file with no name')).size, 19)
-class FileLikeObjectTestCase(LiveServerBase):
+
+class FileLikeObjectTestCase(LiveServerTestCase):
"""
Test file-like objects (#15644).
"""
+ urls = 'file_storage.urls'
+
def setUp(self):
self.temp_dir = tempfile.mkdtemp()
self.storage = FileSystemStorage(location=self.temp_dir)
@@ -628,12 +634,10 @@ def test_urllib2_urlopen(self):
"""
Test the File storage API with a file like object coming from urllib2.urlopen()
"""
-
- file_like_object = self.urlopen('/example_view/')
+ file_like_object = urlopen(self.live_server_url + '/')
f = File(file_like_object)
stored_filename = self.storage.save("remote_file.html", f)
- remote_file = self.urlopen('/example_view/')
-
+ remote_file = urlopen(self.live_server_url + '/')
with self.storage.open(stored_filename) as stored_file:
self.assertEqual(stored_file.read(), remote_file.read())
View
7 tests/file_storage/urls.py
@@ -0,0 +1,7 @@
+from django.conf.urls import patterns, url
+from django.http import HttpResponse
+
+
+urlpatterns = patterns('',
+ url(r'^$', lambda req: HttpResponse('example view')),
+)
Please sign in to comment.
Something went wrong with that request. Please try again.