Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Commit

Permalink
bug 767491, show warnings in signoff view, r=peterbe
Browse files Browse the repository at this point in the history
  • Loading branch information
Pike committed Jul 13, 2012
1 parent faa12f5 commit 34cd143
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 2 deletions.
9 changes: 7 additions & 2 deletions apps/l10nstats/templatetags/run_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ def showrun(run):
reverse('l10nstats.views.compare'))
missing = run.missing + run.missingInFiles
data = {'missing': missing}
for k in ('errors', 'total'):
for k in ('errors', 'warnings', 'total'):
data[k] = getattr(run, k)
datastr = ' '.join('data-%s="%d"' % (k, v) for k, v in data.iteritems())
def plural(msg, num):
# dirty plural hack
return num==1 and (msg % num) or ((msg + 's') % num)
cmp_segs = []
if run.errors:
cmp_segs.append('%d error(s)' % run.errors)
cmp_segs.append(plural('%d error', run.errors))
if missing:
cmp_segs.append('%d missing' % missing)
if run.warnings:
cmp_segs.append(plural('%d warning', run.warnings))
if run.obsolete:
cmp_segs.append('%d obsolete' % run.obsolete)
if not cmp_segs:
Expand Down
103 changes: 103 additions & 0 deletions apps/l10nstats/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

import datetime
from urlparse import urlparse
from test_utils import TestCase
from nose.tools import eq_, ok_
from django.http import QueryDict
from django.core.urlresolvers import reverse
from django.utils.safestring import SafeString
from apps.shipping.tests.test_views import ShippingTestCaseBase
from apps.life.models import Tree, Locale
from apps.mbdb.models import Build
from models import Run, Active
from templatetags.run_filters import showrun
from commons.tests.mixins import EmbedsTestCaseMixin
from html5lib import parseFragment


class L10nstatsTestCase(ShippingTestCaseBase, EmbedsTestCaseMixin):
Expand Down Expand Up @@ -102,3 +106,102 @@ def test_compare_with_invalid_id(self):
# and sane but unknown should be 404
response = self.client.get(url, {'run': 123})
eq_(response.status_code, 404)


class ShowRunTestCase(TestCase):

def test_errors(self):
r = Run(errors=3)
r.id = 1
rv = showrun(r)
ok_(isinstance(rv, SafeString))
frag = parseFragment(rv)
eq_(len(frag.childNodes), 1)
a = frag.childNodes[0]
eq_(a.attributes, {'data-errors': '3',
'data-total': '0',
'data-missing': '0',
'href': '/dashboard/compare?run=1',
'data-warnings': '0'})
text = a.childNodes[0].value
ok_('3' in text and 'error' in text)

def test_missing(self):
r = Run(missing=3)
r.id = 1
rv = showrun(r)
ok_(isinstance(rv, SafeString))
frag = parseFragment(rv)
eq_(len(frag.childNodes), 1)
a = frag.childNodes[0]
eq_(a.attributes, {'data-errors': '0',
'data-total': '0',
'data-missing': '3',
'href': '/dashboard/compare?run=1',
'data-warnings': '0'})
text = a.childNodes[0].value
ok_('3' in text and 'missing' in text)

def test_missingInFiles(self):
r = Run(missingInFiles=3)
r.id = 1
rv = showrun(r)
ok_(isinstance(rv, SafeString))
frag = parseFragment(rv)
eq_(len(frag.childNodes), 1)
a = frag.childNodes[0]
eq_(a.attributes, {'data-errors': '0',
'data-total': '0',
'data-missing': '3',
'href': '/dashboard/compare?run=1',
'data-warnings': '0'})
text = a.childNodes[0].value
ok_('3' in text and 'missing' in text)

def test_warnings(self):
r = Run(warnings=3)
r.id = 1
rv = showrun(r)
ok_(isinstance(rv, SafeString))
frag = parseFragment(rv)
eq_(len(frag.childNodes), 1)
a = frag.childNodes[0]
eq_(a.attributes, {'data-errors': '0',
'data-total': '0',
'data-missing': '0',
'href': '/dashboard/compare?run=1',
'data-warnings': '3'})
text = a.childNodes[0].value
ok_('3' in text and 'warning' in text)

def test_obsolete(self):
r = Run(obsolete=3)
r.id = 1
rv = showrun(r)
ok_(isinstance(rv, SafeString))
frag = parseFragment(rv)
eq_(len(frag.childNodes), 1)
a = frag.childNodes[0]
eq_(a.attributes, {'data-errors': '0',
'data-total': '0',
'data-missing': '0',
'href': '/dashboard/compare?run=1',
'data-warnings': '0'})
text = a.childNodes[0].value
ok_('3' in text and 'obsolete' in text)

def test_green(self):
r = Run()
r.id = 1
rv = showrun(r)
ok_(isinstance(rv, SafeString))
frag = parseFragment(rv)
eq_(len(frag.childNodes), 1)
a = frag.childNodes[0]
eq_(a.attributes, {'data-errors': '0',
'data-total': '0',
'data-missing': '0',
'href': '/dashboard/compare?run=1',
'data-warnings': '0'})
text = a.childNodes[0].value
ok_('green' in text)

0 comments on commit 34cd143

Please sign in to comment.