Skip to content
Browse files

bug 767491, show warnings in signoff view, r=peterbe

  • Loading branch information...
1 parent faa12f5 commit 34cd1436bf48681c9c20a852f39aa0c28f5a727c @Pike Pike committed Jul 11, 2012
Showing with 110 additions and 2 deletions.
  1. +7 −2 apps/l10nstats/templatetags/run_filters.py
  2. +103 −0 apps/l10nstats/tests.py
View
9 apps/l10nstats/templatetags/run_filters.py
@@ -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:
View
103 apps/l10nstats/tests.py
@@ -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):
@@ -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.
Something went wrong with that request. Please try again.