def test_delete_rendering(self): """Make sure the cached HTML updates when deleting the current rev.""" unapproved = RevisionFactory(is_approved=False) d = unapproved.document approved = ApprovedRevisionFactory(document=d, content='booyah') assert 'booyah' in d.content_parsed # Delete the current rev. Since there are no other approved revs, the # document's HTML should fall back to "". approved.delete() eq_('', d.content_parsed) # Now delete the final revision. It still shouldn't crash. unapproved.delete() eq_('', d.content_parsed)
def test_delete(self): """Make sure deleting the latest localizable revision doesn't delete the document but instead sets its latest localizable revision to the previous one. Making sure current_revision does the same is covered in the test_delete_current_revision template test. """ r1 = ApprovedRevisionFactory(is_ready_for_localization=True) d = r1.document r2 = ApprovedRevisionFactory(document=d, is_ready_for_localization=True) # Deleting r2 should make the latest fall back to r1: r2.delete() eq_(r1, Document.objects.get(pk=d.pk).latest_localizable_revision) # And deleting r1 should fall back to None: r1.delete() eq_(None, Document.objects.get(pk=d.pk).latest_localizable_revision)
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)
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)