Exemplo n.º 1
0
    def test_update_l10n_metric_cron(self):
        """Verify the cron job creates the correct metric."""
        l10n_kind = metric_kind(code=L10N_METRIC_CODE, save=True)

        # Create the en-US document with an approved revision.
        doc = document(save=True)
        rev = revision(
            document=doc,
            is_approved=True,
            save=True)

        time.sleep(1)

        # Create an es translation
        es_doc = document(parent=doc, locale='es', save=True)
        revision(
            document=es_doc,
            is_approved=True,
            based_on=rev,
            save=True)

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

        # Update the en-US document
        rev2 = revision(
            document=doc,
            is_approved=True,
            save=True)

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

        time.sleep(1)

        # Create a pt-BR translation
        ptBR_doc = document(parent=doc, locale='pt-BR', save=True)
        revision(
            document=ptBR_doc,
            is_approved=True,
            based_on=rev,
            save=True)

        # Run it and verify results.
        # Value should be 50%
        update_l10n_metric()
        metrics = Metric.objects.filter(kind=l10n_kind)
        eq_(1, len(metrics))
        eq_(50, metrics[0].value)
Exemplo n.º 2
0
    def test_visitors(self):
        """Test unique visitors API call."""
        # Create the metric.
        kind = metric_kind(code=VISITORS_METRIC_CODE, save=True)
        metric(kind=kind, start=date.today(), end=date.today(), value=42,
               save=True)

        # There should be 42 visitors.
        r = self._get_api_result('kpi_visitors')
        eq_(r['objects'][0]['visitors'], 42)
Exemplo n.º 3
0
    def test_l10n_coverage(self):
        """Test l10n coverage API call."""
        # Create the metrics
        kind = metric_kind(code=L10N_METRIC_CODE, save=True)
        metric(kind=kind, start=date.today(), end=date.today(), value=56,
               save=True)

        # The l10n coverage should be 56%.
        r = self._get_api_result('kpi_l10n_coverage')
        eq_(r['objects'][0]['coverage'], 56)
Exemplo n.º 4
0
    def test_l10n_coverage(self):
        """Test l10n coverage API call."""
        # Create the metrics
        kind = metric_kind(code=L10N_METRIC_CODE, save=True)
        metric(kind=kind, start=date.today(), end=date.today(), value=56,
               save=True)

        # The l10n coverage should be 56%.
        r = self._get_api_result('kpi_l10n_coverage')
        eq_(r['objects'][0]['coverage'], 56)
Exemplo n.º 5
0
    def test_visitors(self):
        """Test unique visitors API call."""
        # Create the metric.
        kind = metric_kind(code=VISITORS_METRIC_CODE, save=True)
        metric(kind=kind, start=date.today(), end=date.today(), value=42,
               save=True)

        # There should be 42 visitors.
        r = self._get_api_result('kpi_visitors')
        eq_(r['objects'][0]['visitors'], 42)
Exemplo n.º 6
0
    def test_update_visitors_cron(self, visits):
        """Verify the cron job inserts the right rows."""
        visitor_kind = metric_kind(code=VISITORS_METRIC_CODE, save=True)
        visits.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, 01, 15), metrics[2].start)
Exemplo n.º 7
0
    def test_update_visitors_cron(self, visits):
        """Verify the cron job inserts the right rows."""
        visitor_kind = metric_kind(code=VISITORS_METRIC_CODE, save=True)
        visits.return_value = {'2012-01-13': 42,
                               '2012-01-14': 193,
                               '2012-01-15': 33}

        update_visitors_metric()

        metrics = Metric.objects.filter(kind=visitor_kind)
        eq_(3, len(metrics))
        eq_(42, metrics[0].value)
        eq_(193, metrics[1].value)
        eq_(date(2012, 01, 15), metrics[2].start)
Exemplo n.º 8
0
    def test_visitors(self):
        """Test unique visitors API call."""
        # Create a reply
        kind = metric_kind(code=VISITORS_METRIC_CODE, save=True)
        metric(kind=kind, start=date.today(), end=date.today(), value=42,
               save=True)

        # There should be only one active contributor.
        url = reverse('api_dispatch_list',
                      kwargs={'resource_name': 'kpi_visitors',
                              'api_name': 'v1'})

        response = self.client.get(url + '?format=json')
        eq_(200, response.status_code)
        r = json.loads(response.content)
        eq_(r['objects'][0]['visitors'], 42)
Exemplo n.º 9
0
    def test_update_l10n_metric_cron(self, visits_by_locale, _get_top_docs):
        """Verify the cron job creates the correct metric."""
        l10n_kind = metric_kind(code=L10N_METRIC_CODE, save=True)

        # Create the en-US document with an approved revision.
        doc = document(save=True)
        rev = revision(
            document=doc,
            is_approved=True,
            is_ready_for_localization=True,
            save=True)

        # Create an es translation that is up to date.
        es_doc = document(parent=doc, locale='es', save=True)
        revision(
            document=es_doc,
            is_approved=True,
            based_on=rev,
            save=True)

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

        # Mock some calls.
        visits_by_locale.return_value = {
            'en-US': 100,
            'de': 20,
            'es': 10,
            'fr': 10,
        }
        _get_top_docs.return_value = [doc]

        # Run it and verify results. Values sould be 25% (1/1 * 10/40).
        update_l10n_metric()
        metrics = Metric.objects.filter(kind=l10n_kind)
        eq_(1, len(metrics))
        eq_(25, metrics[0].value)
Exemplo n.º 10
0
 def _make_sphinx_metric_kinds(self):
     click_kind = metric_kind(code='search clickthroughs:sphinx:clicks',
                              save=True)
     search_kind = metric_kind(code='search clickthroughs:sphinx:searches',
                               save=True)
     return click_kind, search_kind
Exemplo n.º 11
0
 def _make_contributor_metric_kinds(self):
     metric_kind(code=AOA_CONTRIBUTORS_METRIC_CODE, save=True)
     metric_kind(code=KB_ENUS_CONTRIBUTORS_METRIC_CODE, save=True)
     metric_kind(code=KB_L10N_CONTRIBUTORS_METRIC_CODE, save=True)
     metric_kind(code=SUPPORT_FORUM_CONTRIBUTORS_METRIC_CODE, save=True)
Exemplo n.º 12
0
 def _make_elastic_metric_kinds(self):
     click_kind = metric_kind(code='search clickthroughs:elastic:clicks',
                              save=True)
     search_kind = metric_kind(code='search clickthroughs:elastic:searches',
                               save=True)
     return click_kind, search_kind
Exemplo n.º 13
0
    def test_update_l10n_metric_cron(self, visits_by_locale, _get_top_docs):
        """Verify the cron job creates the correct metric."""
        l10n_kind = metric_kind(code=L10N_METRIC_CODE, save=True)

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

        # Create an es translation that is up to date.
        es_doc = document(parent=doc, locale="es", save=True)
        revision(document=es_doc, is_approved=True, based_on=rev, save=True)

        # Create a de translation without revisions.
        document(parent=doc, locale="de", save=True)

        # Mock some calls.
        visits_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.
        revision(
            document=doc, significance=TYPO_SIGNIFICANCE, is_approved=True, is_ready_for_localization=True, save=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 = revision(
            document=doc, significance=MEDIUM_SIGNIFICANCE, is_approved=True, is_ready_for_localization=True, save=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 = revision(
            document=doc, significance=MEDIUM_SIGNIFICANCE, is_approved=True, is_ready_for_localization=True, save=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()
        revision(
            document=doc, significance=MAJOR_SIGNIFICANCE, is_approved=True, is_ready_for_localization=True, save=True
        )
        Metric.objects.all().delete()
        update_l10n_metric()
        metrics = Metric.objects.filter(kind=l10n_kind)
        eq_(1, len(metrics))
        eq_(50, metrics[0].value)
Exemplo n.º 14
0
 def _make_contributor_metric_kinds(self):
     metric_kind(code=AOA_CONTRIBUTORS_METRIC_CODE, save=True)
     metric_kind(code=KB_ENUS_CONTRIBUTORS_METRIC_CODE, save=True)
     metric_kind(code=KB_L10N_CONTRIBUTORS_METRIC_CODE, save=True)
     metric_kind(code=SUPPORT_FORUM_CONTRIBUTORS_METRIC_CODE, save=True)
Exemplo n.º 15
0
 def _make_elastic_metric_kinds(self):
     click_kind = metric_kind(code='search clickthroughs:elastic:clicks',
                              save=True)
     search_kind = metric_kind(code='search clickthroughs:elastic:searches',
                               save=True)
     return click_kind, search_kind
Exemplo n.º 16
0
    def test_update_l10n_metric_cron(self, visitors_by_locale, _get_top_docs):
        """Verify the cron job creates the correct metric."""
        l10n_kind = metric_kind(code=L10N_METRIC_CODE, save=True)

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

        # Create an es translation that is up to date.
        es_doc = document(parent=doc, locale='es', save=True)
        revision(document=es_doc, is_approved=True, based_on=rev, save=True)

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

        # 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.
        revision(document=doc,
                 significance=TYPO_SIGNIFICANCE,
                 is_approved=True,
                 is_ready_for_localization=True,
                 save=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 = revision(document=doc,
                      significance=MEDIUM_SIGNIFICANCE,
                      is_approved=True,
                      is_ready_for_localization=True,
                      save=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 = revision(document=doc,
                      significance=MEDIUM_SIGNIFICANCE,
                      is_approved=True,
                      is_ready_for_localization=True,
                      save=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()
        revision(document=doc,
                 significance=MAJOR_SIGNIFICANCE,
                 is_approved=True,
                 is_ready_for_localization=True,
                 save=True)
        Metric.objects.all().delete()
        update_l10n_metric()
        metrics = Metric.objects.filter(kind=l10n_kind)
        eq_(1, len(metrics))
        eq_(50, metrics[0].value)