Permalink
Browse files

check.py ALL THE THINGS, r=lonnen

  • Loading branch information...
1 parent 821cebc commit 93706e363c7fd87ca3822a10757936cb09879b8b @peterbe peterbe committed Oct 15, 2012
View
3 .pep8
@@ -0,0 +1,3 @@
+[pep8]
+# regarding E125, see https://github.com/jcrocholl/pep8/issues/126
+ignore=E125
View
@@ -83,5 +83,22 @@ but this is the basic command to run coverage tests on the
./manage.py test --cover-erase --with-coverage \
--cover-package=crashstats --cover-html
-
+
That'll create `./cover/index.html` for your viewing pleasures.
+
+
+Enable your pre-commit hook
+---------------------------
+
+Paste this into `.git/hooks/pre-commit`:
+
+ check.py | grep "\s" | grep -v 'unable to undefined names'
+ if [ "$?" -ne "1" ]
+ then
+ echo "Aborting commit. Fix above errors or do 'git commit --no-verify'."
+ exit 1
+ fi
+
+Then, make the file executable:
+
+ chmod +x .git/hooks/pre-commit
View
@@ -1,6 +1,6 @@
from django.conf import settings
from django.contrib import auth
-from django.shortcuts import redirect, render
+from django.shortcuts import redirect
from django.views.decorators.http import require_POST
from django.core.urlresolvers import reverse
from django.contrib import messages
@@ -88,9 +88,11 @@ def fetch(self, url, headers=None, method='get', data=None,
_clean_query(split.query))
if expect_json:
- cache_file = os.path.join(cache_file, '%s.json' % cache_key)
+ cache_file = os.path.join(cache_file,
+ '%s.json' % cache_key)
else:
- cache_file = os.path.join(cache_file, '%s.dump' % cache_key)
+ cache_file = os.path.join(cache_file,
+ '%s.dump' % cache_key)
if os.path.isfile(cache_file):
# but is it fresh enough?
@@ -255,7 +257,8 @@ def get(self, **kwargs):
# Operating systems can be specified for by version as
# well but, we only want to separate the results by OS
# if the selected, report type was by_os.
- if 'form_selection' in kwargs and kwargs.get('form_selection') == 'by_os':
+ if ('form_selection' in kwargs and
+ kwargs.get('form_selection') == 'by_os'):
params['separated_by'] = 'os'
url += '/separated_by/%(separated_by)s'
@@ -233,7 +233,8 @@ def mocked_get(**options):
date_range_type='build'
)
- for count, product_version in enumerate(sorted(response['hits'], reverse=True), start=1):
+ hits = sorted(response['hits'], reverse=True)
+ for count, product_version in enumerate(hits, start=1):
for day in sorted(response['hits'][product_version]):
product = response['hits'][product_version][day]['product']
@@ -249,7 +250,8 @@ def mocked_get(**options):
date_range_type='report'
)
- for count, product_version in enumerate(sorted(response['hits'], reverse=True), start=1):
+ hits = sorted(response['hits'], reverse=True)
+ for count, product_version in enumerate(hits, start=1):
for day in sorted(response['hits'][product_version]):
current_day = day
@@ -274,7 +276,6 @@ def mocked_get(**options):
ok_(response['hits'])
eq_(operating_system, 'lin')
-
@mock.patch('requests.get')
def test_crashtrends(self, rget):
api = models.CrashTrends()
@@ -428,7 +429,7 @@ def mocked_get(**options):
u'flash_version': u'11.3.300.250',
u'duplicates': [None, None, None],
u'url': u'http://example.com',
- u'report_day': u'2012-05-31',
+ u'report_day': u'2012-05-31',
u'plugin_signature': u'hang | ZwYieldExecution',
u'browser_hangid': u'30a712a4-6512-479d-9a0a-48b4d8c7ca13',
u'browser_signature': 'hang | mozilla::plugins::',
@@ -100,8 +100,13 @@ def tearDown(self):
@mock.patch('requests.get')
def test_handler500(self, rget):
- root_urlconf = __import__(settings.ROOT_URLCONF,
- globals(), locals(), ['urls'], -1)
+ root_urlconf = __import__(
+ settings.ROOT_URLCONF,
+ globals(),
+ locals(),
+ ['urls'],
+ -1
+ )
# ...so that we can access the 'handler500' defined in there
par, end = root_urlconf.handler500.rsplit('.', 1)
# ...which is an importable reference to the real handler500 function
@@ -253,8 +258,8 @@ def mocked_get(url, **options):
rget.side_effect = mocked_get
- # Test that in the event that no params are passed set_base_data will ensure
- # that the default product is used as a fallback.
+ # Test that in the event that no params are passed set_base_data will
+ # ensure that the default product is used as a fallback.
response = self.client.get(url)
eq_(response.status_code, 200)
@@ -448,7 +453,8 @@ def mocked_get(url, **options):
"currentRank": 0,
"previousRank": 1,
"first_report_exact": "2012-06-21T21:28:08",
- "versions": "2.0, 2.1, 3.0a2, 3.0b2, 3.1b1, 4.0a1, 4.0a2, 5.0a1",
+ "versions":
+ "2.0, 2.1, 3.0a2, 3.0b2, 3.1b1, 4.0a1, 4.0a2, 5.0a1",
"percentOfTotal": 0.24258064516128999,
"win_count": 56,
"changeInPercentOfTotal": 0.011139597126354983,
@@ -837,7 +843,8 @@ def mocked_get(url, **options):
"currentRank": 0,
"previousRank": 1,
"first_report_exact": "2012-06-21T21:28:08",
- "versions": "2.0, 2.1, 3.0a2, 3.0b2, 3.1b1, 4.0a1, 4.0a2, 5.0a1",
+ "versions":
+ "2.0, 2.1, 3.0a2, 3.0b2, 3.1b1, 4.0a1, 4.0a2, 5.0a1",
"percentOfTotal": 0.24258064516128999,
"win_count": 56,
"changeInPercentOfTotal": 0.011139597126354983,
@@ -892,12 +899,17 @@ def mocked_get(url, **options):
}
""")
if 'reports/hang' in url:
+ browser_signature = (
+ 'hang | mozilla::plugins::PPluginInstance'
+ 'Parent::CallNPP_HandleEvent(mozilla::plugins::NPRemoteEve'
+ 'nt const&, short*)'
+ )
return Response("""
{"currentPage": 1,
"endDate": "2012-06-01T00:00:00+00:00",
"hangReport": [{
"browser_hangid": "30a712a4-6512-479d-9a0a-48b4d8c7ca13",
- "browser_signature": "hang | mozilla::plugins::PPluginInstanceParent::CallNPP_HandleEvent(mozilla::plugins::NPRemoteEvent const&, short*)",
+ "browser_signature": "%s",
"duplicates": [
null,
null,
@@ -911,7 +923,7 @@ def mocked_get(url, **options):
}],
"totalCount": 1,
"totalPages": 1}
- """)
+ """ % browser_signature)
raise NotImplementedError(url)
@@ -11,7 +11,8 @@
perm_legacy_redirect = settings.PERMANENT_LEGACY_REDIRECTS
-urlpatterns = patterns('',
+urlpatterns = patterns(
+ '', # prefix
url('^home' + products + '$',
views.home,
name='crashstats.home'),
@@ -48,7 +49,8 @@
url('^builds' + products + '$',
views.builds,
name='crashstats.builds'),
- # note the deliberate omission of the ';' despite calling the regex variable 'versionS'
+ # note the deliberate omission of the ';' despite calling the regex
+ # variable 'versionS'
url('^builds' + products + '/versions/(?P<versions>[\w\.()]+)' + '$',
views.builds,
name='crashstats.builds'),
@@ -92,7 +94,9 @@
'query_string': True}),
url(r'^buginfo/bug', views.buginfo,
name='crashstats.buginfo'),
- url(r'^topcrasher/plot_signature/(?P<product>\w+)/(?P<versions>[;\w\.()]+)/(?P<start_date>[0-9]{4}-[0-9]{2}-[0-9]{2})/(?P<end_date>[0-9]{4}-[0-9]{2}-[0-9]{2})/(?P<signature>.*)',
+ url(r'^topcrasher/plot_signature/(?P<product>\w+)/(?P<versions>[;\w\.()]+)'
+ r'/(?P<start_date>[0-9]{4}-[0-9]{2}-[0-9]{2})/'
+ r'(?P<end_date>[0-9]{4}-[0-9]{2}-[0-9]{2})/(?P<signature>.*)',
views.plot_signature,
name='crashstats.plot_signature'),
url(r'^signature_summary/json_data$',
@@ -125,22 +129,30 @@
redirect_to, {'url': '/home/products/%(product)s',
'permanent': perm_legacy_redirect}),
url(r'^products/(?P<product>\w+)/versions/(?P<versions>[;\w\.()]+)/$',
- redirect_to, {'url': '/home/products/%(product)s/versions/%(versions)s',
- 'permanent': perm_legacy_redirect}),
- url(r'^products/(?P<product>\w+)/versions/(?P<versions>[;\w\.()]+)/builds$',
- redirect_to, {'url': '/builds/products/%(product)s',
- 'permanent': perm_legacy_redirect}),
+ redirect_to,
+ {'url': '/home/products/%(product)s/versions/%(versions)s',
+ 'permanent': perm_legacy_redirect}),
+ url(r'^products/(?P<product>\w+)/versions/(?P<versions>[;\w\.()]+)/'
+ r'builds$',
+ redirect_to,
+ {'url': '/builds/products/%(product)s',
+ 'permanent': perm_legacy_redirect}),
url(r'^hangreport/byversion/(?P<product>\w+)$',
- redirect_to, {'url': '/hangreport/products/%(product)s',
- 'permanent': perm_legacy_redirect}),
+ redirect_to,
+ {'url': '/hangreport/products/%(product)s',
+ 'permanent': perm_legacy_redirect}),
url(r'^hangreport/byversion/(?P<product>\w+)/(?P<versions>[;\w\.()]+)$',
- redirect_to, {'url': '/hangreport/products/%(product)s/versions/%(versions)s',
- 'permanent': perm_legacy_redirect}),
- url(r'^products/(?P<product>\w+)/versions/(?P<versions>[;\w\.()]+)/topchangers$',
- redirect_to, {'url': '/topchangers/products/%(product)s',
- 'permanent': perm_legacy_redirect}),
+ redirect_to,
+ {'url': '/hangreport/products/%(product)s/versions/%(versions)s',
+ 'permanent': perm_legacy_redirect}),
+ url(r'^products/(?P<product>\w+)/versions/(?P<versions>[;\w\.()]+)/'
+ r'topchangers$',
+ redirect_to,
+ {'url': '/topchangers/products/%(product)s',
+ 'permanent': perm_legacy_redirect}),
url(r'^topcrasher/byversion/(?P<product>\w+)/(?P<versions>[;\w\.()]+)$',
- redirect_to, {'url': '/topcrasher/products/%(product)s/versions/%(versions)s',
- 'permanent': perm_legacy_redirect}),
+ redirect_to,
+ {'url': '/topcrasher/products/%(product)s/versions/%(versions)s',
+ 'permanent': perm_legacy_redirect}),
)
@@ -30,8 +30,10 @@ def wrapper(*args, **kw):
if isinstance(response, http.HttpResponse):
return response
else:
- return http.HttpResponse(_json_clean(json.dumps(response)),
- content_type='application/json; charset=UTF-8')
+ return http.HttpResponse(
+ _json_clean(json.dumps(response)),
+ content_type='application/json; charset=UTF-8'
+ )
return wrapper
@@ -42,7 +44,8 @@ def _json_clean(value):
# in HTML, as it prevents </script> tags from prematurely terminating
# the javscript. Some json libraries do this escaping by default,
# although python's standard library does not, so we do it here.
- # http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped
+ # http://stackoverflow.com/questions/1580647/json-why-are-forward-slashe\
+ # s-escaped
return value.replace("</", "<\\/")
@@ -1164,9 +1164,7 @@ def signature_summary(request):
range_value = int(request.GET.get('range_value'))
# FIXME only support "days"
- range_unit = request.GET.get('range_unit')
signature = request.GET.get('signature')
- product_version = request.GET.get('version')
end_date = datetime.datetime.utcnow()
start_date = end_date - datetime.timedelta(days=range_value)
No changes.
No changes.
@@ -1,36 +0,0 @@
-{% extends "example_base.html" %}
-
-{% block content %}
-<h1>Bleach</h1>
-<p>(back to the <a href="{{ url('examples.home') }}">main page</a>)</p>
-
-<p>An example showing how to use Bleach library to do user input sanitization.</p>
-
-<p>For more information, check out the <a href="https://github.com/jsocol/bleach/">
- Bleach README</a>.</p>
-
-<p>Enter some possibly harmful text here, hit send, and see what Bleach does
-with it.</p>
-
-<form id="bleachform" method="post" action="">
- {{ csrf() }}
- <textarea name="bleachme">{{ bleachme if bleachme else '' }}</textarea>
- <p>(Allowed tags: <code>&lt;strong&gt;</code>, <code>&lt;em&gt;</code>)</p>
- <button type="submit">Bleach!</button>
-</form>
-
-{% if bleached %}
-<section id="bleached">
- <p>Bleached, this became:</p>
- <p>{{ bleached }}</p>
-</section>
-{% endif %}
-
-<p>Some things to try out:</p>
-<ul id="bleachable">
- <li><code>an &lt;script&gt;evil()&lt;/script&gt; example</code></li>
- <li><code>Hello &lt;strong&gt;world&lt;/strong&gt;!</code></li>
- <li><code>Check out &lt;a href="http://mozilla.org"&gt;mozilla.org&lt;/a&gt;</code></li>
- <li><code>Unbalanced &lt;em&gt;tag</code></li>
-</ul>
-{% endblock %}
@@ -1,30 +0,0 @@
-{% extends "example_base.html" %}
-
-{% block content %}
-<h1>
- <a href="/">{{ _('Hello world') }}</a>
-</h1>
-
-{# L10n: This is a localizer comment #}
-{% if request.MOBILE %}
- <p>{{ _('This is a <em>test view</em> for mobile browsers.') }}</p>
-{% else %}
- <p>{{ _('This is a <em>test view</em> for desktop browsers.') }}</p>
-{% endif %}
-<p>
- {% trans docs_url='http://playdoh.rtfd.org/' %}
- <a href="{{ docs_url }}">Learn you some Playdoh</a> and then go build
- something <strong>awesome</strong>.
- {% endtrans %}
-</p>
-<p>
- {% trans langs=LANGUAGES.items() %}
- Current locale: {{ LANG }}.<br>
- Available locales: {{ langs }}.
- {% endtrans %}
-</p>
-<p>Some more examples:</p>
-<ul>
- <li><a href="{{ url('examples.bleach') }}">Input sanitization with Bleach</a></li>
-</ul>
-{% endblock %}
@@ -1,9 +0,0 @@
-from django.conf.urls.defaults import *
-
-from . import views
-
-
-urlpatterns = patterns('',
- url(r'^$', views.home, name='examples.home'),
- url(r'^bleach/?$', views.bleach_test, name='examples.bleach'),
-)
Oops, something went wrong.

0 comments on commit 93706e3

Please sign in to comment.