Ejemplo n.º 1
0
    def test_not_counting_outdated(self):
        """Out-of-date translations shouldn't count as "done".

        "Out-of-date" can mean either moderately or majorly out of date. The
        only thing we don't care about is typo-level outdatedness.

        """
        t = translated_revision(is_approved=True, save=True)
        overview = overview_rows('de')
        eq_(1, overview['most-visited']['numerator'])
        eq_(1, overview['all']['numerator'])

        # Update the parent with a typo-level revision:
        revision(document=t.document.parent,
                 significance=TYPO_SIGNIFICANCE,
                 is_approved=True,
                 is_ready_for_localization=True,
                 save=True)
        # Assert it still shows up in the numerators:
        overview = overview_rows('de')
        eq_(1, overview['most-visited']['numerator'])
        eq_(1, overview['all']['numerator'])

        # Update the parent with a medium-level revision:
        revision(document=t.document.parent,
                 significance=MEDIUM_SIGNIFICANCE,
                 is_approved=True,
                 is_ready_for_localization=True,
                 save=True)
        # Assert it no longer shows up in the numerators:
        overview = overview_rows('de')
        eq_(0, overview['all']['numerator'])
        eq_(0, overview['most-visited']['numerator'])
Ejemplo n.º 2
0
    def test_not_counting_outdated(self):
        """Out-of-date translations shouldn't count as "done".

        "Out-of-date" can mean either moderately or majorly out of date. The
        only thing we don't care about is typo-level outdatedness.

        """
        t = translated_revision(is_approved=True, save=True)
        overview = overview_rows('de')
        eq_(1, overview['most-visited']['numerator'])
        eq_(1, overview['all']['numerator'])

        # Update the parent with a typo-level revision:
        revision(document=t.document.parent,
                 significance=TYPO_SIGNIFICANCE,
                 is_approved=True,
                 is_ready_for_localization=True,
                 save=True)
        # Assert it still shows up in the numerators:
        overview = overview_rows('de')
        eq_(1, overview['most-visited']['numerator'])
        eq_(1, overview['all']['numerator'])

        # Update the parent with a medium-level revision:
        revision(document=t.document.parent,
                 significance=MEDIUM_SIGNIFICANCE,
                 is_approved=True,
                 is_ready_for_localization=True,
                 save=True)
        # Assert it no longer shows up in the numerators:
        overview = overview_rows('de')
        eq_(0, overview['all']['numerator'])
        eq_(0, overview['most-visited']['numerator'])
Ejemplo n.º 3
0
    def test_by_product(self):
        """Test the product filtering of the overview."""
        p = product(title='Firefox', slug='firefox', save=True)
        t = translated_revision(is_approved=True, save=True)

        eq_(0, overview_rows('de', product=p)['all']['numerator'])
        eq_(0, overview_rows('de', product=p)['all']['denominator'])

        t.document.parent.products.add(p)

        eq_(1, overview_rows('de', product=p)['all']['numerator'])
        eq_(1, overview_rows('de', product=p)['all']['denominator'])
Ejemplo n.º 4
0
    def test_not_counting_how_to_contribute(self):
        """Articles with the How to contribute category should not be counted.
        """
        t = translated_revision(is_approved=True, save=True)
        overview = overview_rows('de')
        eq_(1, overview['most-visited']['numerator'])

        # Update the parent with the How To Contribute category
        d = t.document.parent
        d.category = HOW_TO_CONTRIBUTE_CATEGORY
        d.save()

        overview = overview_rows('de')
        eq_(0, overview['most-visited']['numerator'])
Ejemplo n.º 5
0
    def test_all_articles_doesnt_have_30_40_50(self):
        """Make sure All Articles doesn't have 30, 40, and 50 articles"""
        t = translated_revision(is_approved=True, save=True)
        # It shows up in All when it's a normal doc:
        eq_(1, overview_rows('de')['all']['numerator'])
        eq_(1, overview_rows('de')['all']['denominator'])

        # ...but not when it's a navigation article:
        t.document.parent.title = t.document.title = 'thing'
        t.document.parent.category = t.document.category = 50
        t.document.parent.save()
        t.document.save()
        eq_(0, overview_rows('de')['all']['numerator'])
        eq_(0, overview_rows('de')['all']['denominator'])

        # ...or administration:
        t.document.parent.category = t.document.category = 40
        t.document.parent.save()
        t.document.save()
        eq_(0, overview_rows('de')['all']['numerator'])
        eq_(0, overview_rows('de')['all']['denominator'])

        # ...or how to contribute:
        t.document.parent.category = t.document.category = 30
        t.document.parent.save()
        t.document.save()
        eq_(0, overview_rows('de')['all']['numerator'])
        eq_(0, overview_rows('de')['all']['denominator'])
Ejemplo n.º 6
0
    def test_all_articles_doesnt_have_30_40_50(self):
        """Make sure All Articles doesn't have 30, 40, and 50 articles"""
        t = translated_revision(is_approved=True, save=True)
        # It shows up in All when it's a normal doc:
        eq_(1, overview_rows('de')['all']['numerator'])
        eq_(1, overview_rows('de')['all']['denominator'])

        # ...but not when it's a navigation article:
        t.document.parent.title = t.document.title = 'thing'
        t.document.parent.category = t.document.category = 50
        t.document.parent.save()
        t.document.save()
        eq_(0, overview_rows('de')['all']['numerator'])
        eq_(0, overview_rows('de')['all']['denominator'])

        # ...or administration:
        t.document.parent.category = t.document.category = 40
        t.document.parent.save()
        t.document.save()
        eq_(0, overview_rows('de')['all']['numerator'])
        eq_(0, overview_rows('de')['all']['denominator'])

        # ...or how to contribute:
        t.document.parent.category = t.document.category = 30
        t.document.parent.save()
        t.document.save()
        eq_(0, overview_rows('de')['all']['numerator'])
        eq_(0, overview_rows('de')['all']['denominator'])
Ejemplo n.º 7
0
    def test_not_counting_how_to_contribute(self):
        """Articles with the How to contribute category should not be counted.
        """
        t = translated_revision(is_approved=True, save=True)
        overview = overview_rows('de')
        eq_(1, overview['most-visited']['numerator'])

        # Update the parent with the How To Contribute category
        d = t.document.parent
        d.category = HOW_TO_CONTRIBUTE_CATEGORY
        d.save()

        overview = overview_rows('de')
        eq_(0, overview['most-visited']['numerator'])
Ejemplo n.º 8
0
    def test_templates_and_docs_disjunct(self):
        """Make sure templates aren't included in the All Articles count."""
        t = translated_revision(is_approved=True, save=True)
        # It shows up in All when it's a normal doc:
        eq_(1, overview_rows('de')['all']['numerator'])
        eq_(1, overview_rows('de')['all']['denominator'])

        t.document.parent.title = t.document.title = 'Template:thing'
        t.document.parent.is_template = t.document.is_template = True
        t.document.parent.save()
        t.document.save()
        # ...but not when it's a template:
        eq_(0, overview_rows('de')['all']['numerator'])
        eq_(0, overview_rows('de')['all']['denominator'])
Ejemplo n.º 9
0
 def test_not_counting_untranslated(self):
     """Translations with no approved revisions shouldn't count as done.
     """
     t = translated_revision(is_approved=False, save=True)
     overview = overview_rows('de')
     eq_(0, overview['most-visited']['numerator'])
     eq_(0, overview['all']['numerator'])
Ejemplo n.º 10
0
    def test_counting_unready_docs(self):
        """Docs without a ready-for-l10n rev shouldn't count in total."""
        # Make a doc with an approved but not-ready-for-l10n rev:
        r = revision(document=document(title='smoo',
                                       is_localizable=True,
                                       save=True),
                     is_ready_for_localization=False,
                     is_approved=True,
                     save=True)

        # It shouldn't show up in the total:
        eq_(0, overview_rows('de')['all']['denominator'])

        r.is_ready_for_localization = True
        r.save()
        eq_(1, overview_rows('de')['all']['denominator'])
Ejemplo n.º 11
0
 def test_not_counting_untranslated(self):
     """Translations with no approved revisions shouldn't count as done.
     """
     t = translated_revision(is_approved=False, save=True)
     overview = overview_rows('de')
     eq_(0, overview['most-visited']['numerator'])
     eq_(0, overview['all']['numerator'])
Ejemplo n.º 12
0
    def test_redirects_are_ignored(self):
        """Verify that redirects aren't counted in the overview."""
        t = translated_revision(is_approved=True, save=True)

        eq_(1, overview_rows('de')['all']['numerator'])

        # A redirect shouldn't affect any of the tests.
        revision(document=document(title='A redirect',
                                   is_localizable=True,
                                   is_template=True,
                                   save=True),
                 is_ready_for_localization=True,
                 is_approved=True,
                 content='REDIRECT [[An article]]',
                 save=True)

        eq_(1, overview_rows('de')['all']['numerator'])
Ejemplo n.º 13
0
    def test_redirects_are_ignored(self):
        """Verify that redirects aren't counted in the overview."""
        t = translated_revision(is_approved=True, save=True)

        eq_(1, overview_rows('de')['all']['numerator'])

        # A redirect shouldn't affect any of the tests.
        revision(document=document(title='A redirect',
                                   is_localizable=True,
                                   is_template=True,
                                   save=True),
                 is_ready_for_localization=True,
                 is_approved=True,
                 content='REDIRECT [[An article]]',
                 save=True)

        eq_(1, overview_rows('de')['all']['numerator'])
Ejemplo n.º 14
0
    def test_counting_unready_navigation(self):
        """Navigation articles without ready-for-l10n rev don't count"""
        # Make a navigation doc with an approved but not-ready-for-l10n rev:
        r = revision(document=document(title='smoo',
                                       category=50,
                                       is_localizable=True,
                                       is_template=False,
                                       save=True),
                     is_ready_for_localization=False,
                     is_approved=True,
                     save=True)

        # It shouldn't show up in the total:
        eq_(0, overview_rows('de')['navigation']['denominator'])

        r.is_ready_for_localization = True
        r.save()
        eq_(1, overview_rows('de')['navigation']['denominator'])
Ejemplo n.º 15
0
    def test_counting_unready_navigation(self):
        """Navigation articles without ready-for-l10n rev don't count"""
        # Make a navigation doc with an approved but not-ready-for-l10n rev:
        r = revision(document=document(title='smoo',
                                       category=50,
                                       is_localizable=True,
                                       is_template=False,
                                       save=True),
                     is_ready_for_localization=False,
                     is_approved=True,
                     save=True)

        # It shouldn't show up in the total:
        eq_(0, overview_rows('de')['navigation']['denominator'])

        r.is_ready_for_localization = True
        r.save()
        eq_(1, overview_rows('de')['navigation']['denominator'])
Ejemplo n.º 16
0
    def test_not_counting_templates(self):
        """Articles in the Templates category should not be counted.
        """
        t = translated_revision(is_approved=True, save=True)
        overview = overview_rows('de')
        eq_(1, overview['all']['numerator'])
        eq_(1, overview['top-20']['numerator'])
        eq_(1, overview['top-50']['numerator'])
        eq_(1, overview['top-100']['numerator'])

        # Update the parent and translation to be a template
        d = t.document.parent
        d.title = 'Template:Lorem Ipsum Dolor'
        d.save()
        t.document.title = 'Template:Lorem Ipsum Dolor'
        t.document.save()

        overview = overview_rows('de')
        eq_(0, overview['all']['numerator'])
        eq_(0, overview['top-20']['numerator'])
        eq_(0, overview['top-50']['numerator'])
        eq_(0, overview['top-100']['numerator'])
Ejemplo n.º 17
0
def localization(request):
    """Render aggregate data about articles in a non-default locale."""
    if request.LANGUAGE_CODE == settings.WIKI_DEFAULT_LANGUAGE:
        return HttpResponseRedirect(reverse("dashboards.contributors"))
    locales = Locale.objects.filter(locale=request.LANGUAGE_CODE)
    if locales:
        permission = user_can_announce(request.user, locales[0])
    else:
        permission = False

    product = _get_product(request)

    data = {"overview_rows": overview_rows(request.LANGUAGE_CODE, product=product), "user_can_announce": permission}
    return render_readouts(request, L10N_READOUTS, "localization.html", extra_data=data, product=product)
Ejemplo n.º 18
0
def update_l10n_coverage_metrics():
    """Calculate and store the l10n metrics for each locale/product.

    The metrics are:
    * Percent localized of top 20 articles
    * Percent localized of all articles
    """
    today = date.today()

    # Loop through all locales.
    for locale in settings.SUMO_LANGUAGES:

        # Skip en-US, it is always 100% localized.
        if locale == settings.WIKI_DEFAULT_LANGUAGE:
            continue

        # Loop through all enabled products, including None (really All).
        for product in [None] + list(Product.objects.filter(visible=True)):

            # (Ab)use the overview_rows helper from the readouts.
            rows = overview_rows(locale=locale, product=product)

            # % of top 20 articles
            top20 = rows['most-visited']
            percent = 100.0 * float(top20['numerator']) / top20['denominator']
            WikiMetric.objects.create(
                code=L10N_TOP20_CODE,
                locale=locale,
                product=product,
                date=today,
                value=percent)

            # % of all articles
            all_ = rows['all']
            try:
                percent = 100.0 * float(all_['numerator']) / all_['denominator']
            except ZeroDivisionError:
                percent = 0.0

            WikiMetric.objects.create(
                code=L10N_ALL_CODE,
                locale=locale,
                product=product,
                date=today,
                value=percent)
Ejemplo n.º 19
0
def update_l10n_coverage_metrics():
    """Calculate and store the l10n metrics for each locale/product.

    The metrics are:
    * Percent localized of top 20 articles
    * Percent localized of all articles
    """
    today = date.today()

    # Loop through all locales.
    for locale in settings.SUMO_LANGUAGES:

        # Skip en-US, it is always 100% localized.
        if locale == settings.WIKI_DEFAULT_LANGUAGE:
            continue

        # Loop through all enabled products, including None (really All).
        for product in [None] + list(Product.objects.filter(visible=True)):

            # (Ab)use the overview_rows helper from the readouts.
            rows = overview_rows(locale=locale, product=product)

            # % of top 20 articles
            top20 = rows['most-visited']
            percent = 100.0 * float(top20['numerator']) / top20['denominator']
            WikiMetric.objects.create(code=L10N_TOP20_CODE,
                                      locale=locale,
                                      product=product,
                                      date=today,
                                      value=percent)

            # % of all articles
            all_ = rows['all']
            try:
                percent = 100.0 * float(
                    all_['numerator']) / all_['denominator']
            except ZeroDivisionError:
                percent = 0.0

            WikiMetric.objects.create(code=L10N_ALL_CODE,
                                      locale=locale,
                                      product=product,
                                      date=today,
                                      value=percent)
Ejemplo n.º 20
0
    def test_counting_unready_parents(self):
        """Translations with no ready revs don't count in numerator

        By dint of factoring, this also tests that templates whose
        parents....

        """
        parent_rev = revision(document=document(is_localizable=True,
                                                save=True),
                              is_approved=True,
                              is_ready_for_localization=False,
                              save=True)
        translation = document(parent=parent_rev.document,
                               locale='de',
                               is_localizable=False,
                               save=True)
        revision(document=translation,
                 is_approved=True,
                 based_on=parent_rev,
                 save=True)
        eq_(0, overview_rows('de')['all']['numerator'])
Ejemplo n.º 21
0
def localization(request):
    """Render aggregate data about articles in a non-default locale."""
    if request.LANGUAGE_CODE == settings.WIKI_DEFAULT_LANGUAGE:
        return HttpResponseRedirect(reverse('dashboards.contributors'))
    locales = Locale.objects.filter(locale=request.LANGUAGE_CODE)
    if locales:
        permission = user_can_announce(request.user, locales[0])
    else:
        permission = False

    product = _get_product(request)

    data = {
        'overview_rows': overview_rows(request.LANGUAGE_CODE, product=product),
        'user_can_announce': permission,
    }
    return render_readouts(request,
                           L10N_READOUTS,
                           'localization.html',
                           extra_data=data,
                           product=product)