'Test the cron job that updates active contributor metrics.'

def test_update_active_contributor_metrics(self):

    day = date(2013, 7, 31)
    last_month = date(2013, 6, 15)
    start_date = date(2013, 6, 1)
    before_start = date(2013, 5, 31)
    d = DocumentFactory(locale='en-US')
    u = UserFactory()
    RevisionFactory(document=d, created=last_month, is_approved=True, reviewer=u)
    RevisionFactory(document=d, creator=u, created=last_month)
    p = ProductFactory(visible=True)
    RevisionFactory(created=start_date, document__products=[p])
    RevisionFactory(document=d, created=before_start)
    RevisionFactory(document=d, created=day)
    d = DocumentFactory(locale='es')
    RevisionFactory(document=d, created=last_month, is_approved=True, reviewer=u)
    RevisionFactory(document=d, creator=u, created=last_month, reviewer=UserFactory())
    RevisionFactory(document=d, created=start_date)
    RevisionFactory(document=d, created=last_month)
    RevisionFactory(document=d, created=before_start)
    RevisionFactory(document=d, created=day)
    update_l10n_contributor_metrics(day)
    eq_(3.0, WikiMetric.objects.get(locale='en-US', product=None, date=start_date).value)
    eq_(1.0, WikiMetric.objects.get(locale='en-US', product=p, date=start_date).value)
    eq_(4.0, WikiMetric.objects.get(locale='es', product=None, date=start_date).value)
    eq_(0.0, WikiMetric.objects.get(locale='es', product=p, date=start_date).value)
