'Test the cron job that updates l10n coverage metrics.'

def test_update_l10n_coverage_metrics(self):

    p = ProductFactory(visible=True)
    revisions = RevisionFactory.create_batch(20, is_approved=True, is_ready_for_localization=True, document__products=[p], document__locale='en-US')
    r1 = revisions[0]
    r2 = revisions[1]
    d = DocumentFactory(parent=r1.document, locale='es')
    ApprovedRevisionFactory(document=d, based_on=r1)
    d = DocumentFactory(parent=r1.document, locale='de')
    ApprovedRevisionFactory(document=d, based_on=r1)
    d = DocumentFactory(parent=r2.document, locale='de')
    ApprovedRevisionFactory(document=d, based_on=r2)
    for r in revisions:
        d = DocumentFactory(parent=r.document, locale='ru')
        RevisionFactory(document=d, based_on=r, is_approved=True)
    update_l10n_coverage_metrics()
    eq_(6, WikiMetric.objects.filter(locale='es').count())
    eq_(5.0, WikiMetric.objects.get(locale='es', product=p, code=L10N_TOP20_CODE).value)
    eq_(5.0, WikiMetric.objects.get(locale='es', product=p, code=L10N_TOP100_CODE).value)
    eq_(5.0, WikiMetric.objects.get(locale='es', product=p, code=L10N_ALL_CODE).value)
    eq_(5.0, WikiMetric.objects.get(locale='es', product=None, code=L10N_TOP20_CODE).value)
    eq_(5.0, WikiMetric.objects.get(locale='es', product=None, code=L10N_TOP100_CODE).value)
    eq_(5.0, WikiMetric.objects.get(locale='es', product=None, code=L10N_ALL_CODE).value)
    eq_(6, WikiMetric.objects.filter(locale='de').count())
    eq_(10.0, WikiMetric.objects.get(locale='de', product=p, code=L10N_TOP20_CODE).value)
    eq_(10.0, WikiMetric.objects.get(locale='de', product=None, code=L10N_TOP100_CODE).value)
    eq_(10.0, WikiMetric.objects.get(locale='de', product=p, code=L10N_ALL_CODE).value)
    eq_(10.0, WikiMetric.objects.get(locale='de', product=None, code=L10N_TOP20_CODE).value)
    eq_(10.0, WikiMetric.objects.get(locale='de', product=None, code=L10N_TOP100_CODE).value)
    eq_(10.0, WikiMetric.objects.get(locale='de', product=None, code=L10N_ALL_CODE).value)
    eq_(6, WikiMetric.objects.filter(locale='ru').count())
    eq_(100.0, WikiMetric.objects.get(locale='ru', product=p, code=L10N_TOP20_CODE).value)
    eq_(100.0, WikiMetric.objects.get(locale='ru', product=None, code=L10N_TOP100_CODE).value)
    eq_(100.0, WikiMetric.objects.get(locale='ru', product=p, code=L10N_ALL_CODE).value)
    eq_(100.0, WikiMetric.objects.get(locale='ru', product=None, code=L10N_TOP20_CODE).value)
    eq_(100.0, WikiMetric.objects.get(locale='ru', product=None, code=L10N_TOP100_CODE).value)
    eq_(100.0, WikiMetric.objects.get(locale='ru', product=None, code=L10N_ALL_CODE).value)
    eq_(6, WikiMetric.objects.filter(locale='it').count())
    eq_(0.0, WikiMetric.objects.get(locale='it', product=p, code=L10N_TOP20_CODE).value)
    eq_(0.0, WikiMetric.objects.get(locale='it', product=None, code=L10N_TOP100_CODE).value)
    eq_(0.0, WikiMetric.objects.get(locale='it', product=p, code=L10N_ALL_CODE).value)
    eq_(0.0, WikiMetric.objects.get(locale='it', product=None, code=L10N_TOP20_CODE).value)
    eq_(0.0, WikiMetric.objects.get(locale='it', product=None, code=L10N_TOP100_CODE).value)
    eq_(0.0, WikiMetric.objects.get(locale='it', product=None, code=L10N_ALL_CODE).value)
