Ejemplo n.º 1
0
    def test_update_search_ctr(self, search_ctr):
        """Verify the cron job inserts the right rows."""
        clicks_kind = MetricKindFactory(code=SEARCH_CLICKS_METRIC_CODE)
        MetricKindFactory(code=SEARCH_SEARCHES_METRIC_CODE)
        search_ctr.return_value = {'2013-06-06': 42.123456789,
                                   '2013-06-07': 13.7654321,
                                   '2013-06-08': 99.55555}

        call_command('update_search_ctr_metric')

        metrics = Metric.objects.filter(kind=clicks_kind).order_by('start')
        eq_(3, len(metrics))
        eq_(421, metrics[0].value)
        eq_(138, metrics[1].value)
        eq_(date(2013, 6, 8), metrics[2].start)
Ejemplo n.º 2
0
    def test_exit_survey_results(self):
        """Test the exist survey results API call."""
        # Create the metrics
        kind = MetricKindFactory(code=EXIT_SURVEY_YES_CODE)
        MetricFactory(kind=kind, start=date.today(), end=date.today(), value=1337)
        kind = MetricKindFactory(code=EXIT_SURVEY_NO_CODE)
        MetricFactory(kind=kind, start=date.today(), end=date.today(), value=42)
        kind = MetricKindFactory(code=EXIT_SURVEY_DONT_KNOW_CODE)
        MetricFactory(kind=kind, start=date.today(), end=date.today(), value=777)

        # Verify the results returned from the API
        r = self._get_api_result("api.kpi.exit-survey")
        eq_(r["objects"][0]["yes"], 1337)
        eq_(r["objects"][0]["no"], 42)
        eq_(r["objects"][0]["dont_know"], 777)
Ejemplo n.º 3
0
    def test_l10n_coverage(self):
        """Test l10n coverage API call."""
        # Create the metrics
        kind = MetricKindFactory(code=L10N_METRIC_CODE)
        MetricFactory(kind=kind, start=date.today(), end=date.today(), value=56)

        # The l10n coverage should be 56%.
        r = self._get_api_result("api.kpi.l10n-coverage")
        eq_(r["objects"][0]["coverage"], 56)
Ejemplo n.º 4
0
    def test_visitors(self):
        """Test unique visitors API call."""
        # Create the metric.
        kind = MetricKindFactory(code=VISITORS_METRIC_CODE)
        MetricFactory(kind=kind, start=date.today(), end=date.today(), value=42)

        # There should be 42 visitors.
        r = self._get_api_result("api.kpi.visitors")
        eq_(r["objects"][0]["visitors"], 42)
Ejemplo n.º 5
0
    def test_update_visitors_cron(self, visitors):
        """Verify the cron job inserts the right rows."""
        visitor_kind = MetricKindFactory(code=VISITORS_METRIC_CODE)
        visitors.return_value = {"2012-01-13": 42, "2012-01-14": 193, "2012-01-15": 33}

        call_command("update_visitors_metric")

        metrics = Metric.objects.filter(kind=visitor_kind).order_by("start")
        eq_(3, len(metrics))
        eq_(42, metrics[0].value)
        eq_(193, metrics[1].value)
        eq_(date(2012, 1, 15), metrics[2].start)
Ejemplo n.º 6
0
    def test_process_exit_surveys(self, requests):
        """Verify the metrics inserted by process_exit_surveys cron job."""
        requests.get.return_value.content = SURVEY_GIZMO_EXIT_SURVEY_RESPONSE

        # Create the kinds.
        yes_kind = MetricKindFactory(code=EXIT_SURVEY_YES_CODE)
        no_kind = MetricKindFactory(code=EXIT_SURVEY_NO_CODE)
        dunno_kind = MetricKindFactory(code=EXIT_SURVEY_DONT_KNOW_CODE)
        two_days_back = date.today() - timedelta(days=2)

        # Add a metric for 2 days ago so only 1 new day is collected.
        MetricFactory(kind=yes_kind, start=two_days_back)

        # Collect and process.
        _process_exit_survey_results()

        # Verify.
        eq_(4, Metric.objects.count())
        eq_(2, Metric.objects.filter(kind=yes_kind)[1].value)
        eq_(1, Metric.objects.get(kind=no_kind).value)
        eq_(1, Metric.objects.get(kind=dunno_kind).value)
Ejemplo n.º 7
0
    def test_update_visitors_cron(self, visitors):
        """Verify the cron job inserts the right rows."""
        visitor_kind = MetricKindFactory(code=VISITORS_METRIC_CODE)
        visitors.return_value = {
            '2012-01-13': 42,
            '2012-01-14': 193,
            '2012-01-15': 33
        }

        update_visitors_metric()

        metrics = Metric.objects.filter(kind=visitor_kind).order_by('start')
        eq_(3, len(metrics))
        eq_(42, metrics[0].value)
        eq_(193, metrics[1].value)
        eq_(date(2012, 1, 15), metrics[2].start)
Ejemplo n.º 8
0
    def test_update_l10n_metric_cron(self, visitors_by_locale, _get_top_docs):
        """Verify the cron job creates the correct metric."""
        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)
        call_command('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()
        call_command('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()
        call_command('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()
        call_command('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()
        call_command('update_l10n_metric')
        metrics = Metric.objects.filter(kind=l10n_kind)
        eq_(1, len(metrics))
        eq_(50, metrics[0].value)
Ejemplo n.º 9
0
 def _make_contributor_metric_kinds(self):
     MetricKindFactory(code=AOA_CONTRIBUTORS_METRIC_CODE)
     MetricKindFactory(code=KB_ENUS_CONTRIBUTORS_METRIC_CODE)
     MetricKindFactory(code=KB_L10N_CONTRIBUTORS_METRIC_CODE)
     MetricKindFactory(code=SUPPORT_FORUM_CONTRIBUTORS_METRIC_CODE)
Ejemplo n.º 10
0
 def _make_elastic_metric_kinds(self):
     click_kind = MetricKindFactory(
         code='search clickthroughs:elastic:clicks')
     search_kind = MetricKindFactory(
         code='search clickthroughs:elastic:searches')
     return click_kind, search_kind