@patch.object(kitsune.kpi.cron, '_get_top_docs')
    @patch.object(googleanalytics, 'visitors_by_locale')
    def test_update_l10n_metric_cron(self, visitors_by_locale, _get_top_docs):
        l10n_kind = MetricKindFactory(code=L10N_METRIC_CODE)

        # Create the en-US document with an approved revision.
        doc = DocumentFactory()
        rev = ApprovedRevisionFactory(
            document=doc,
            significance=MEDIUM_SIGNIFICANCE,
            is_ready_for_localization=True)

        # Create an es translation that is up to date.
        es_doc = DocumentFactory(parent=doc, locale='es')
        ApprovedRevisionFactory(document=es_doc, based_on=rev)

        # Create a de translation without revisions.
        DocumentFactory(parent=doc, locale='de')

        # Mock some calls.
        visitors_by_locale.return_value = {
            'en-US': 50,
            'de': 20,
            'es': 25,
            'fr': 5,
        }
        _get_top_docs.return_value = [doc]

        # Run it and verify results.
        # Value should be 75% (1/1 * 25/100 + 1/1 * 50/100)
        update_l10n_metric()
        metrics = Metric.objects.filter(kind=l10n_kind)
        eq_(1, len(metrics))
        eq_(75, metrics[0].value)

        # Create a new revision with TYPO_SIGNIFICANCE. It shouldn't
        # affect the results.
        ApprovedRevisionFactory(
            document=doc,
            significance=TYPO_SIGNIFICANCE,
            is_ready_for_localization=True)
        Metric.objects.all().delete()
        update_l10n_metric()
        metrics = Metric.objects.filter(kind=l10n_kind)
        eq_(1, len(metrics))
        eq_(75, metrics[0].value)

        # Create a new revision with MEDIUM_SIGNIFICANCE. The coverage
        # should now be 62% (0.5/1 * 25/100 + 1/1 * 50/100)
        m1 = ApprovedRevisionFactory(
            document=doc,
            significance=MEDIUM_SIGNIFICANCE,
            is_ready_for_localization=True)
        Metric.objects.all().delete()
        update_l10n_metric()
        metrics = Metric.objects.filter(kind=l10n_kind)
        eq_(1, len(metrics))
        eq_(62, metrics[0].value)

        # And another new revision with MEDIUM_SIGNIFICANCE makes the
        # coverage 50% (1/1 * 50/100).
        m2 = ApprovedRevisionFactory(
            document=doc,
            significance=MEDIUM_SIGNIFICANCE,
            is_ready_for_localization=True)
        Metric.objects.all().delete()
        update_l10n_metric()
        metrics = Metric.objects.filter(kind=l10n_kind)
        eq_(1, len(metrics))
        eq_(50, metrics[0].value)

        # If we remove the two MEDIUM_SIGNIFICANCE revisions and add a
        # MAJOR_SIGNIFICANCE revision, the coverage is 50% as well.
        m1.delete()
        m2.delete()
        ApprovedRevisionFactory(
            document=doc,
            significance=MAJOR_SIGNIFICANCE,
            is_ready_for_localization=True)
        Metric.objects.all().delete()
        update_l10n_metric()
        metrics = Metric.objects.filter(kind=l10n_kind)
        eq_(1, len(metrics))
        eq_(50, metrics[0].value)
Do default xmlstream.send, but put obj[id] to _pending response dict
dataset/ETHPy150Open mozilla/kitsune/kitsune/kpi/tests/test_cron.py/CronJobTests.test_update_l10n_metric_cron--crossover with--dataset/ETHPy150Open selfsk/nodeset.core/src/nodeset/core/pubsub/agent.py/XmlStreamJabber.send