Permalink
Browse files

py2.7 compatability and update docs about cache, cope with no jpeg

  • Loading branch information...
1 parent 561709e commit 0a5a39e69f8af0464456782d66482c27311dda76 @andymckay andymckay committed Sep 20, 2011
@@ -14,6 +14,7 @@
from mock import Mock, patch
from nose.tools import eq_
+from nose import SkipTest
from pyquery import PyQuery as pq
from PIL import Image
import waffle
@@ -1442,6 +1443,9 @@ def test_img_wrongtype(self):
eq_(r_json['errors'], ['Images must be either PNG or JPG.'])
def test_success(self):
+ if not hasattr(Image.core, 'jpeg_encoder'):
+ raise SkipTest
+
data = self.get_dict()
header_url, footer_url = self.get_img_urls()
@@ -3011,7 +3011,6 @@ def test_fileupload_ascii_post(self):
r = self.client.post(self.url, {'upload': data})
# If this is broke, we'll get a traceback.
eq_(r.status_code, 302)
- test_fileupload_ascii_post.py27unicode = True
@attr('validator')
def test_fileupload_validation(self):
View
@@ -15,6 +15,7 @@
from django.db.models import Count
from django.shortcuts import get_object_or_404, redirect
from django.utils.http import urlquote
+from django.utils.encoding import smart_unicode
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_view_exempt
@@ -1029,7 +1030,8 @@ def ajax_upload_image(request, upload_type):
upload_preview.seek(0)
upload_hash = uuid.uuid4().hex
- loc = path.path(settings.TMP_PATH) / upload_type / upload_hash
+ loc = (path.path(smart_unicode(settings.TMP_PATH))
+ / upload_type / upload_hash)
if not loc.dirname().exists():
loc.dirname().makedirs()
View
@@ -16,7 +16,7 @@
from django.db import models
from django.dispatch import receiver
from django.template.defaultfilters import slugify
-from django.utils.encoding import smart_str
+from django.utils.encoding import smart_str, smart_unicode
import commonware
import path
@@ -124,7 +124,7 @@ def get_url_path(self, src, addon=None):
@classmethod
def from_upload(cls, upload, version, platform, parse_data={}):
f = cls(version=version, platform=platform)
- upload.path = path.path(nfd_str(upload.path))
+ upload.path = path.path(smart_unicode(nfd_str(upload.path)))
f.filename = f.generate_filename(extension=upload.path.ext or '.xpi')
f.size = int(max(1, round(upload.path.size / 1024, 0))) # Kilobytes.
f.jetpack_version = cls.get_jetpack_version(upload.path)
@@ -555,7 +555,7 @@ def add_file(self, chunks, filename, size):
loc = path.path(settings.ADDONS_PATH) / 'temp' / uuid.uuid4().hex
if not loc.dirname().exists():
loc.dirname().makedirs()
- ext = path.path(filename).ext
+ ext = path.path(smart_unicode(filename)).ext
if ext in EXTENSIONS:
loc += ext
log.info('UPLOAD: %r (%s bytes) to %r' % (filename, size, loc))
@@ -474,7 +474,6 @@ def test_ascii_names(self):
fu = FileUpload.from_post('', u'\u05d0\u05d5\u05e1\u05e3.xpi', 0)
assert 'xpi' in fu.name
- test_ascii_names.py27unicode = True
class TestFileFromUpload(UploadTest):
@@ -548,7 +547,6 @@ def test_utf8(self):
self.version.addon.name = u'jéts!'
f = File.from_upload(upload, self.version, self.platform)
eq_(f.filename, u'jets-0.1-mac.xpi')
- test_utf8.py27unicode = True
def test_size(self):
upload = self.upload('extension')
@@ -15,11 +15,19 @@
# You want one of the caching backends. Dummy won't do any caching, locmem is
# cleared every time you restart the server, and memcached is what we run in
# production.
-# CACHE_BACKEND = 'caching.backends.memcached://localhost:11211?timeout=500'
-CACHE_BACKEND = 'caching.backends.locmem://'
-# Some cache is required for CSRF to work. Dummy will allow some functionality,
-# but won't allow you to login.
-# CACHE_BACKEND = 'dummy://'
+#CACHES = {
+# 'default': {
+# 'BACKEND': 'django.core.cache.backends.memcached.Memcached',
+# 'LOCATION': 'localhost:11211',
+# }
+#}
+CACHES = {
+ 'default': {
+ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+ 'LOCATION': 'zamboni',
+ }
+}
+# Caching is required for CSRF to work, please do not use the dummy cache.
DATABASES = {
'default': {

0 comments on commit 0a5a39e

Please sign in to comment.