Skip to content

Commit

Permalink
fixes bug 1119378 - Upgrade to Django 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Jan 15, 2015
1 parent ba6a09a commit a70d778
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 19 deletions.
10 changes: 6 additions & 4 deletions requirements.txt
Expand Up @@ -127,16 +127,18 @@ https://github.com/BradRuderman/pyhs2/archive/48d22aff9d23db1221ad913670aaad90a7
sasl==0.1.3

# things needed specifically for the webapp
# sha256: R85QXFBGw4gXgovuJTtyVocvhsQ0DbGvaYy4VI26oNI
Django==1.5.9

# sha256: zu6D_0xPoUYSif4HpYeehEAIn63eFQ1AdTaRzdjJQsE
# sha256: VOtZznhUAcfR_e7SRe_OWX6Q-BHWog9rXGkxwASdY6Y
Django==1.6.10
# sha256: 1BuH0etCTRi6Lb5zMTHp2HPnCcwR63PaJIw07sHV7W4
django-browserid==0.10.1
# sha256: akF58qKszaKyc7_Ybeb3AkzuIDBDzJp8BA_nswa74SA
fancy-tag==0.2.0
# sha256: uDA8a2lQGB1uEg_sdygAueYurQsQAD6-utf81kFmE9g
https://github.com/mozilla/django-session-csrf/archive/f00ad91.zip#egg=django-session-csrf
# sha256: ezt0vf24BIR-7Lxcap02St7FFYx-HlyK-dgjh88iYMg
https://github.com/mozilla/funfactory/archive/6b797bb.zip#egg=funfactory
# sha256: UvCV-GFHuwtfYjva-VJVLReOu8XqyI2RsvWR09IsO4A
funfactory==2.3.0
# sha256: B-lA57jFsdXYf3h9luYXt_gbsep2FZ4ZIvPHvzt0Y4Y
https://github.com/jbalogh/test-utils/archive/4ae9327.zip#egg=test-utils
# sha256: o71QUd0X6dUOip8tNiUI6C1wYwEP3AbV4HzjYI54D-Y
Expand Down
1 change: 1 addition & 0 deletions socorro/external/postgresql/service_base.py
Expand Up @@ -89,6 +89,7 @@ def query(
)
return result
except psycopg2.Error, x:
raise
self.config.logger.error(
error_message if error_message else str(x),
exc_info=True
Expand Down
10 changes: 5 additions & 5 deletions webapp-django/crashstats/api/views.py
Expand Up @@ -99,9 +99,9 @@ class APIWhitelistError(Exception):
class MultipleStringField(forms.TypedMultipleChoiceField):
"""Field that do not validate if the field values are in self.choices"""

def to_python(self, value):
"""Override checking method"""
return map(self.coerce, value)
# def to_python(self, value):
# """Override checking method"""
# return map(self.coerce, value)

def validate(self, value):
"""Nothing to do here"""
Expand Down Expand Up @@ -249,7 +249,7 @@ def model_wrapper(request, model_name):
return http.HttpResponse(
message,
status=error_code,
mimetype='application/json; charset=UTF-8'
content_type='application/json; charset=UTF-8'
)
except ValueError:
# The error from the middleware was not a JSON error.
Expand All @@ -265,7 +265,7 @@ def model_wrapper(request, model_name):
return http.HttpResponse(
reason,
status=424,
mimetype='text/plain'
content_type='text/plain'
)
raise
except ValueError as e:
Expand Down
3 changes: 1 addition & 2 deletions webapp-django/crashstats/crashstats/models.py
Expand Up @@ -18,7 +18,6 @@
from django.conf import settings
from django.core.cache import cache
from django.utils.encoding import iri_to_uri
from django.utils.hashcompat import md5_constructor
from django.template.defaultfilters import slugify

from crashstats import scrubber
Expand Down Expand Up @@ -305,7 +304,7 @@ def fetch(
data=data,
params=params,
).prepare()
cache_key = md5_constructor(iri_to_uri(req.url)).hexdigest()
cache_key = hashlib.md5(iri_to_uri(req.url)).hexdigest()

if not refresh_cache:
result = cache.get(cache_key)
Expand Down
12 changes: 11 additions & 1 deletion webapp-django/crashstats/crashstats/tests/test_models.py
Expand Up @@ -1638,6 +1638,17 @@ def mocked_get(**options):
""")
rget.side_effect = mocked_get

# Because we're mock patching time.time, it becomes impossible
# to do something like `some_time > time.time()` which is exactly
# what the django.core.cache.backends.locmem.LocMemCache class
# does inside its get() method.
# So we need to hijack that mock specifically for the "less than"
# operator.
def mocked_time_lt(other):
return False

mocked_time().__lt__.side_effect = mocked_time_lt

assert not self._get_cached_file(self.tempdir)

# the first time, we rely on the mocket request.get
Expand All @@ -1650,7 +1661,6 @@ def mocked_get(**options):
assert 'hits' in json.loads(open(json_file).read())

# if we now loose the memcache/locmem
from django.core.cache import cache
cache.clear()

info = api.get()
Expand Down
5 changes: 3 additions & 2 deletions webapp-django/crashstats/crashstats/tests/test_views.py
Expand Up @@ -524,8 +524,9 @@ class TestViews(BaseTestViews):
def test_contribute_json(self):
response = self.client.get('/contribute.json')
eq_(response.status_code, 200)
# should be valid JSON
ok_(json.loads(response.content))
# Should be valid JSON, but it's a streaming content because
# it comes from django.views.static.serve
ok_(json.loads(''.join(response.streaming_content)))
eq_(response['Content-Type'], 'application/json')

@mock.patch('requests.get')
Expand Down
9 changes: 5 additions & 4 deletions webapp-django/crashstats/crashstats/views.py
Expand Up @@ -35,7 +35,7 @@ def robots_txt(request):
return http.HttpResponse(
'User-agent: *\n'
'%s: /' % ('Allow' if settings.ENGAGE_ROBOTS else 'Disallow'),
mimetype='text/plain',
content_type='text/plain',
)


Expand All @@ -49,7 +49,8 @@ def favicon_ico(request):
this up and running.
"""
filename = os.path.join(settings.STATIC_ROOT, 'img', 'favicon.ico')
return http.HttpResponse(open(filename).read(), mimetype='image/x-icon')
with open(filename) as f:
return http.HttpResponse(f.read(), content_type='image/x-icon')


def has_builds(product, versions):
Expand Down Expand Up @@ -546,7 +547,7 @@ def topcrasher(request, product=None, versions=None, date_range_type=None,


def _render_topcrasher_csv(request, context, product):
response = http.HttpResponse(mimetype='text/csv', content_type='text/csv')
response = http.HttpResponse(content_type='text/csv')
filedate = datetime.datetime.utcnow().strftime('%Y-%m-%d')
response['Content-Disposition'] = ('attachment; filename="%s_%s_%s.csv"' %
(product, context['version'], filedate))
Expand Down Expand Up @@ -764,7 +765,7 @@ def daily(request, default_context=None):

def _render_daily_csv(request, data, product, versions, platforms, os_names,
form_selection):
response = http.HttpResponse(mimetype='text/csv', content_type='text/csv')
response = http.HttpResponse('text/csv', content_type='text/csv')
title = 'ADI_' + product + '_' + '_'.join(versions) + '_' + form_selection
response['Content-Disposition'] = (
'attachment; filename="%s.csv"' % title
Expand Down
2 changes: 1 addition & 1 deletion webapp-django/crashstats/tokens/middleware.py
Expand Up @@ -12,7 +12,7 @@ def json_forbidden_response(msg):
body = json.dumps({'error': msg})
return http.HttpResponseForbidden(
body + '\n',
mimetype='application/json; charset=UTF-8'
content_type='application/json; charset=UTF-8'
)


Expand Down

0 comments on commit a70d778

Please sign in to comment.