def test_correct_ready_for_localization_if_insignificant(self): """Revision.clean() must clear is_ready_for_l10n if the rev is of typo-level significance.""" r = ApprovedRevisionFactory( is_ready_for_localization=True, significance=TYPO_SIGNIFICANCE) r.clean() assert not r.is_ready_for_localization
def test_direct_recursion(self): """Make sure direct recursion is caught on the very first nesting.""" d = TemplateDocumentFactory(title=TEMPLATE_TITLE_PREFIX + 'Boo') # Twice so the second revision sees content identical to itself: ApprovedRevisionFactory.create_batch( 2, document=d, content='Fine [[{}Boo]] Fellows'.format(TEMPLATE_TITLE_PREFIX)) recursion_message = RECURSION_MESSAGE % (TEMPLATE_TITLE_PREFIX + 'Boo') expected = '<p>Fine %s Fellows\n</p>' % recursion_message eq_(expected, d.content_parsed)
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: d = DocumentFactory(is_localizable=True) r = ApprovedRevisionFactory(document=d, is_ready_for_localization=False) # It shouldn't show up in the total: eq_(0, l10n_overview_rows('de')['all']['denominator']) r.is_ready_for_localization = True r.save() eq_(1, l10n_overview_rows('de')['all']['denominator'])
def test_counting_unready_templates(self): """Templates without a ready-for-l10n rev don't count""" # Make a template with an approved but not-ready-for-l10n rev: d = TemplateDocumentFactory(is_localizable=True) r = ApprovedRevisionFactory(document=d, is_ready_for_localization=False) # It shouldn't show up in the total: eq_(0, l10n_overview_rows("de")["templates"]["denominator"]) r.is_ready_for_localization = True r.save() eq_(1, l10n_overview_rows("de")["templates"]["denominator"])
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 setUp(self): today = datetime.today() self.start_of_first_week = today - timedelta(days=today.weekday(), weeks=12) revisions = ApprovedRevisionFactory.create_batch(3, created=self.start_of_first_week) reviewer = UserFactory() ApprovedRevisionFactory(reviewer=reviewer, created=self.start_of_first_week) ApprovedRevisionFactory(creator=revisions[1].creator, reviewer=reviewer, created=self.start_of_first_week + timedelta(weeks=1, days=2)) ApprovedRevisionFactory(created=self.start_of_first_week + timedelta(weeks=1, days=1)) for r in revisions: lr = ApprovedRevisionFactory(created=self.start_of_first_week + timedelta(days=1), document__locale='es') ApprovedRevisionFactory(created=self.start_of_first_week + timedelta(weeks=2, days=1), creator=lr.creator, document__locale='es') answers = AnswerFactory.create_batch( 7, created=self.start_of_first_week + timedelta(weeks=1, days=2)) AnswerFactory(question=answers[2].question, creator=answers[2].question.creator, created=self.start_of_first_week + timedelta(weeks=1, days=2)) for a in answers[:2]: AnswerFactory(creator=a.creator, created=self.start_of_first_week + timedelta(weeks=2, days=5)) replies = ReplyFactory.create_batch(2, created=self.start_of_first_week) for r in replies: ReplyFactory(user=r.user, created=self.start_of_first_week + timedelta(weeks=2)) call_command('cohort_analysis')
def test_document_listing(self): """Verify /products/<product slug>/<topic slug> renders articles.""" # Create a topic and product. p = ProductFactory() t1 = TopicFactory(product=p) # Create 3 documents with the topic and product and one without. ApprovedRevisionFactory.create_batch(3, document__products=[p], document__topics=[t1]) ApprovedRevisionFactory() self.refresh() # GET the page and verify the content. url = reverse('products.documents', args=[p.slug, t1.slug]) r = self.client.get(url, follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_(3, len(doc('#document-list > ul > li'))) eq_(p.slug, doc('#support-search input[name=product]').attr['value'])
def test_for_in_template(self): """Verify that {for}'s render correctly in template.""" d = TemplateDocumentFactory(title=TEMPLATE_TITLE_PREFIX + 'for') ApprovedRevisionFactory( document=d, content='{for win}windows{/for}{for mac}mac{/for}') p = WikiParser() content = p.parse('[[{}for]]'.format(TEMPLATE_TITLE_PREFIX)) eq_( '<p><span class="for" data-for="win">windows</span>' '<span class="for" data-for="mac">mac</span>\n\n</p>', content)
def create_documents(self, locale): """Create a document in English and a translated document for the locale""" en = settings.WIKI_DEFAULT_LANGUAGE en_content = 'This article is in English' trans_content = 'This article is translated into %slocale' % locale # Create an English article and a translation for the locale en_doc = DocumentFactory(locale=en) ApprovedRevisionFactory(document=en_doc, content=en_content, is_ready_for_localization=True) trans_doc = DocumentFactory(parent=en_doc, locale=locale) # Create a new revision of the localized document trans_rev = ApprovedRevisionFactory(document=trans_doc, content=trans_content) # Make the created revision the current one for the localized document trans_doc.current_revision = trans_rev trans_doc.save() # Return both the English version and the localized version of the document return en_doc, trans_doc
def facets_setUp(self): # Create products self.desktop = ProductFactory(slug='firefox') self.mobile = ProductFactory(slug='mobile') # Create topics self.general_d = TopicFactory(product=self.desktop, slug='general') self.bookmarks_d = TopicFactory(product=self.desktop, slug='bookmarks') self.sync_d = TopicFactory(product=self.desktop, slug='sync') self.general_m = TopicFactory(product=self.mobile, slug='general') self.bookmarks_m = TopicFactory(product=self.mobile, slug='bookmarks') self.sync_m = TopicFactory(product=self.mobile, slug='sync') # Set up documents. doc1 = DocumentFactory(products=[self.desktop], topics=[self.general_d, self.bookmarks_d]) ApprovedRevisionFactory(document=doc1) doc2 = DocumentFactory( products=[self.desktop, self.mobile], topics=[self.bookmarks_d, self.bookmarks_m, self.sync_d, self.sync_m]) ApprovedRevisionFactory(document=doc2) # An archived article shouldn't show up doc3 = DocumentFactory( is_archived=True, products=[self.desktop], topics=[self.general_d, self.bookmarks_d]) ApprovedRevisionFactory(document=doc3) # A template article shouldn't show up either doc4 = TemplateDocumentFactory( products=[self.desktop], topics=[self.general_d, self.bookmarks_d]) ApprovedRevisionFactory(document=doc4) # An article without current revision should be "invisible" # to everything. doc5 = DocumentFactory( products=[self.desktop, self.mobile], topics=[self.general_d, self.bookmarks_d, self.sync_d, self.general_m, self.bookmarks_m, self.sync_m]) RevisionFactory(is_approved=False, document=doc5)
def test_first_rev(self): """If an article's first revision is approved, show the article. This also conveniently tests that documents with no latest_localizable_revision are not necessarily excluded. """ r = ApprovedRevisionFactory(reviewed=datetime.now(), is_ready_for_localization=False, significance=None) eq_([r.document.title], self.titles())
def test_template_locale(self): """Localized template is returned.""" py_doc, p = doc_parse_markup('English content', '[[Template:test]]') parent = TemplateDocumentFactory() d = TemplateDocumentFactory(parent=parent, title=TEMPLATE_TITLE_PREFIX + 'test', locale='fr') ApprovedRevisionFactory(content='French Content', document=d) eq_(py_doc.text(), 'English content') py_doc = pq(p.parse('[[T:test]]', locale='fr')) eq_(py_doc.text(), 'French Content')
def test_visit_count_from_analytics(self, _build_request, close_old_connections): """Verify stored visit counts from mocked analytics data. It has some nasty non-ASCII chars in it. """ execute = _build_request.return_value.get.return_value.execute execute.return_value = PAGEVIEWS_BY_DOCUMENT_RESPONSE d1 = ApprovedRevisionFactory(document__slug="hellỗ").document d2 = ApprovedRevisionFactory(document__slug="there").document WikiDocumentVisits.reload_period_from_analytics(LAST_7_DAYS) eq_(2, WikiDocumentVisits.objects.count()) wdv1 = WikiDocumentVisits.objects.get(document=d1) eq_(27, wdv1.visits) eq_(LAST_7_DAYS, wdv1.period) wdv2 = WikiDocumentVisits.objects.get(document=d2) eq_(LAST_7_DAYS, wdv2.period)
def test_template_locale(self): """Localized template is returned.""" py_doc, p = doc_parse_markup("English content", "[[Template:test]]") parent = TemplateDocumentFactory() d = TemplateDocumentFactory( parent=parent, title=TEMPLATE_TITLE_PREFIX + "test", locale="fr" ) ApprovedRevisionFactory(content="French Content", document=d) eq_(py_doc.text(), "English content") py_doc = pq(p.parse("[[T:test]]", locale="fr")) eq_(py_doc.text(), "French Content")
def test_document_listing(self): """Verify /products/<product slug>/<topic slug> renders articles.""" # Create a topic and product. p = ProductFactory() t1 = TopicFactory(product=p) # Create 3 documents with the topic and product and one without. ApprovedRevisionFactory.create_batch(3, document__products=[p], document__topics=[t1]) ApprovedRevisionFactory() self.refresh() # GET the page and verify the content. url = reverse("products.documents", args=[p.slug, t1.slug]) r = self.client.get(url, follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_(3, len(doc("#document-list > ul > li"))) eq_(p.slug, doc("#support-search input[name=product]").attr["value"])
def test_video_modal(self): """Video modal defaults for plcaeholder and text.""" v = VideoFactory() replacement = ('<img class="video-thumbnail" src="%s"/>' % v.thumbnail_url_if_set()) d = ApprovedRevisionFactory(content='[[V:%s|modal]]' % v.title).document doc = pq(d.html) eq_(v.title, doc('.video-modal')[0].attrib['title']) eq_(1, doc('.video video').length) eq_(replacement, doc('.video-placeholder').html().strip()) eq_('video modal-trigger', doc('div.video').attr('class'))
def test_unready_for_l10n(self): """Test status for article that is not ready for l10n""" locale = settings.WIKI_DEFAULT_LANGUAGE d = TemplateDocumentFactory() RevisionFactory(document=d, is_ready_for_localization=True) ApprovedRevisionFactory( document=d, is_ready_for_localization=False, significance=MAJOR_SIGNIFICANCE) row = self.row(locale=locale) eq_(row['title'], d.title) eq_(str(row['status']), 'Changes Not Ready For Localization')
def test_by_product(self): """Test the product filtering of the readout.""" p = ProductFactory(title='Firefox', slug='firefox') d = TemplateDocumentFactory() ApprovedRevisionFactory(document=d, is_ready_for_localization=True) # There shouldn't be any rows yet. eq_(0, len(self.rows(product=p))) # Add the product to the document, and verify it shows up. d.products.add(p) eq_(self.row(product=p)['title'], d.title)
def test_video_modal(self): """Video modal defaults for plcaeholder and text.""" v = VideoFactory() replacement = '<img class="video-thumbnail" src="%s"/>' % v.thumbnail_url_if_set( ) d = ApprovedRevisionFactory(content="[[V:%s|modal]]" % v.title).document doc = pq(d.html) eq_(v.title, doc(".video-modal")[0].attrib["title"]) eq_(1, doc(".video video").length) eq_(replacement, doc(".video-placeholder").html().strip()) eq_("video modal-trigger", doc("div.video").attr("class"))
def test_ready_for_l10n_updates_doc(self): """Approving and marking ready a rev should update the doc's ref.""" # Ready a rev in a new doc: ready_1 = ApprovedRevisionFactory(is_ready_for_localization=True) eq_(ready_1, ready_1.document.latest_localizable_revision) # Add an unready revision that we can ready later: unready = RevisionFactory(document=ready_1.document, is_approved=False, is_ready_for_localization=False) # Ready a rev in a doc that already has a ready revision: ready_2 = ApprovedRevisionFactory(document=ready_1.document, is_ready_for_localization=True) eq_(ready_2, ready_2.document.latest_localizable_revision) # Ready the older rev. It should not become the latest_localizable. unready.is_ready_for_localization = True unready.is_approved = True unready.save() eq_(ready_2, ready_2.document.latest_localizable_revision)
def test_document_listing_order(self): """Verify documents are sorted by display_order and number of helpful votes.""" # Create topic, product and documents. p = ProductFactory() t = TopicFactory(product=p) docs = [] # FIXME: Can't we do this with create_batch and build the document # in the approvedrevisionfactory for i in range(3): doc = DocumentFactory(products=[p], topics=[t]) ApprovedRevisionFactory(document=doc) docs.append(doc) # Add a lower display order to the second document. It should be first now. docs[1].display_order = 0 docs[1].save() self.refresh() url = reverse("products.documents", args=[p.slug, t.slug]) r = self.client.get(url, follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_( doc("#document-list > ul > li:first-child > a").text(), docs[1].title) # Add a helpful vote to the third document. It should be second now. rev = docs[2].current_revision HelpfulVoteFactory(revision=rev, helpful=True) docs[2].save() # Votes don't trigger a reindex. self.refresh() cache.clear() # documents_for() is cached url = reverse("products.documents", args=[p.slug, t.slug]) r = self.client.get(url, follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_( doc("#document-list > ul > li:nth-child(2) > a").text(), docs[2].title) # Add 2 helpful votes the first document. It should be second now. rev = docs[0].current_revision HelpfulVoteFactory(revision=rev, helpful=True) HelpfulVoteFactory(revision=rev, helpful=True) docs[0].save() # Votes don't trigger a reindex. self.refresh() cache.clear() # documents_for() is cached r = self.client.get(url, follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_( doc("#document-list > ul > li:nth-child(2) > a").text(), docs[0].title)
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 = TranslatedRevisionFactory(document__locale="de", is_approved=True) overview = l10n_overview_rows("de") eq_(1, overview["top-20"]["numerator"]) eq_(1, overview["top-50"]["numerator"]) eq_(1, overview["top-100"]["numerator"]) eq_(1, overview["all"]["numerator"]) # Update the parent with a typo-level revision: ApprovedRevisionFactory( document=t.document.parent, significance=TYPO_SIGNIFICANCE, is_ready_for_localization=True, ) # Assert it still shows up in the numerators: overview = l10n_overview_rows("de") eq_(1, overview["top-20"]["numerator"]) eq_(1, overview["top-50"]["numerator"]) eq_(1, overview["top-100"]["numerator"]) eq_(1, overview["all"]["numerator"]) # Update the parent with a medium-level revision: ApprovedRevisionFactory( document=t.document.parent, significance=MEDIUM_SIGNIFICANCE, is_ready_for_localization=True, ) # Assert it no longer shows up in the numerators: overview = l10n_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"])
def test_l10n_badge(self): """Verify the L10n Badge is awarded properly.""" # Create the user and badge. year = date.today().year u = UserFactory() b = BadgeFactory( slug=WIKI_BADGES['l10n-badge']['slug'].format(year=year), title=WIKI_BADGES['l10n-badge']['title'].format(year=year), description=WIKI_BADGES['l10n-badge']['description'].format(year=year)) # Create 9 approved es revisions. d = DocumentFactory(locale='es') ApprovedRevisionFactory.create_batch(9, creator=u, document=d) # User should NOT have the badge yet assert not b.is_awarded_to(u) # Create 1 more approved es revision. RevisionFactory(creator=u, document=d, is_approved=True) # User should have the badge now assert b.is_awarded_to(u)
def test_by_product(self): """Test the product filtering of the readout.""" p = ProductFactory(title="Firefox", slug="firefox") d = DocumentFactory(title="Foo", category=CANNED_RESPONSES_CATEGORY) ApprovedRevisionFactory(document=d, is_ready_for_localization=True) # There shouldn't be any rows yet. eq_(0, len(self.rows(product=p))) # Add the product to the document, and verify it shows up. d.products.add(p) eq_(1, len(self.rows(product=p))) eq_(self.row(product=p)["title"], d.title)
def test_by_product(self): """Test the product filtering of the readout.""" locale = settings.WIKI_DEFAULT_LANGUAGE p = ProductFactory(title='Firefox', slug='firefox') d = DocumentFactory() ApprovedRevisionFactory(document=d) # There shouldn't be any rows yet. eq_(0, len(self.rows(locale=locale, product=p))) # Add the product to the document, and verify it shows up. d.products.add(p) eq_(self.row(locale=locale, product=p)['title'], d.title)
def test_consider_max_significance(self): """Use max significance for determining change significance When determining how significantly an article has changed since translation, use the max significance of the approved revisions, not just that of the latest ready-to-localize one. """ translation = TranslatedRevisionFactory(document__locale="de", is_approved=True) ApprovedRevisionFactory( document=translation.document.parent, is_ready_for_localization=False, # should still count significance=MAJOR_SIGNIFICANCE, ) ApprovedRevisionFactory( document=translation.document.parent, is_ready_for_localization=True, significance=MEDIUM_SIGNIFICANCE, ) row = self.row() eq_(row["title"], translation.document.title) eq_(str(row["status"]), "Immediate Update Needed")
def test_ready_for_l10n(self): d = DocumentFactory() r = RevisionFactory(document=d) d.current_revision = r d.save() data = kb_overview_rows() eq_(1, len(data)) eq_(False, data[0]['ready_for_l10n']) ApprovedRevisionFactory(document=d, is_ready_for_localization=True) data = kb_overview_rows() eq_(True, data[0]['ready_for_l10n'])
def test_page_invalid(self): """Ensure non-integer param doesn't throw exception.""" doc = DocumentFactory( title="How to fix your audio", locale="en-US", category=10, tags="desktop" ) ApprovedRevisionFactory(document=doc) self.refresh() response = self.client.get( reverse("search"), {"q": "audio", "format": "json", "page": "invalid"} ) eq_(200, response.status_code) eq_(1, json.loads(response.content)["total"])
def test_french(self): # Create English parent document en_d = DocumentFactory() ApprovedRevisionFactory(document=en_d) # Create the French document fr_d = DocumentFactory(parent=en_d, title="A doc", locale="fr") obj = get_object_fallback(Document, "A doc", "fr", "!") eq_(fr_d, obj) # Also works when English exists DocumentFactory(title="A doc") obj = get_object_fallback(Document, "A doc", "fr", "!") eq_(fr_d, obj)
def test_retitling(self): """When the title of an article is edited, a redirect is made.""" # Not testing slug changes separately; the model tests cover those plus # slug+title changes. If title changes work in the view, the rest # should also. new_title = "Some New Title" r = ApprovedRevisionFactory() d = r.document old_title = d.title data = new_document_data() data.update({"title": new_title, "slug": d.slug, "form": "doc"}) self.client.post(reverse("wiki.edit_document", args=[d.slug]), data) eq_(new_title, Document.objects.get(id=d.id).title) assert Document.objects.get(title=old_title).redirect_url()
def test_kb_badge(self): """Verify the KB Badge is awarded properly.""" # Create the user and badge. year = date.today().year u = UserFactory() b = BadgeFactory( slug=WIKI_BADGES['kb-badge']['slug'].format(year=year), title=WIKI_BADGES['kb-badge']['title'].format(year=year), description=WIKI_BADGES['kb-badge']['description'].format(year=year)) # Create 9 approved en-US revisions. d = DocumentFactory(locale=settings.WIKI_DEFAULT_LANGUAGE) ApprovedRevisionFactory.create_batch(settings.BADGE_LIMIT_L10N_KB - 1, creator=u, document=d) # User should NOT have the badge yet assert not b.is_awarded_to(u) # Create 1 more approved en-US revision. RevisionFactory(creator=u, document=d, is_approved=True) # User should have the badge now assert b.is_awarded_to(u)
def test_old_revisions(self): """Bug 862436. Updating old revisions could cause bad WLH data.""" d1 = DocumentFactory(title="D1") RevisionFactory(document=d1, content="", is_approved=True) d2 = DocumentFactory(title="D2") RevisionFactory(document=d2, content="", is_approved=True) # Make D3, then make a revision that links to D1, then a # revision that links to D2. Only the link to D2 should count. d3 = DocumentFactory(title="D3") r3_old = ApprovedRevisionFactory(document=d3, content="[[D1]]") ApprovedRevisionFactory(document=d3, content="[[D2]]") # This could cause stale data r3_old.content_parsed # D1 is not linked to in any current revisions. eq_(len(d1.links_to()), 0) eq_(len(d1.links_from()), 0) eq_(len(d2.links_to()), 1) eq_(len(d2.links_from()), 0) eq_(len(d3.links_to()), 0) eq_(len(d3.links_from()), 1)
def test_l10n_badge(self): """Verify the L10n Badge is awarded properly.""" # Create the user and badge. year = date.today().year u = UserFactory() b = BadgeFactory( slug=WIKI_BADGES['l10n-badge']['slug'].format(year=year), title=WIKI_BADGES['l10n-badge']['title'].format(year=year), description=WIKI_BADGES['l10n-badge']['description'].format( year=year)) # Create 9 approved es revisions. d = DocumentFactory(locale='es') ApprovedRevisionFactory.create_batch(9, creator=u, document=d) # User should NOT have the badge yet assert not b.is_awarded_to(u) # Create 1 more approved es revision. RevisionFactory(creator=u, document=d, is_approved=True) # User should have the badge now assert b.is_awarded_to(u)
def test_translation_state(self): eng_doc = DocumentFactory(category=CANNED_RESPONSES_CATEGORY) eng_rev = ApprovedRevisionFactory(is_ready_for_localization=True, document=eng_doc) eq_('untranslated', self.row()['status_class']) # Now translate it, but don't approve de_doc = DocumentFactory(category=CANNED_RESPONSES_CATEGORY, parent=eng_doc, locale='de') de_rev = RevisionFactory( document=de_doc, based_on=eng_rev, is_approved=False, reviewed=None) eq_('review', self.row()['status_class']) # Approve it, so now every this is ok. de_rev.is_approved = True de_rev.save() eq_('ok', self.row()['status_class']) # Now update the parent, so it becomes minorly out of date ApprovedRevisionFactory( is_ready_for_localization=True, document=eng_doc, significance=MEDIUM_SIGNIFICANCE) eq_('update', self.row()['status_class']) # Now update the parent, so it becomes majorly out of date ApprovedRevisionFactory( is_ready_for_localization=True, document=eng_doc, significance=MAJOR_SIGNIFICANCE) eq_('out-of-date', self.row()['status_class'])
def _test_significance(self, significance, status): """ Assert that a translation out of date due to a `significance`-level update to the original article shows status `status`. """ translation = TranslatedRevisionFactory(document__locale='de', is_approved=True) ApprovedRevisionFactory( document=translation.document.parent, is_ready_for_localization=True, significance=significance) row = self.row() eq_(row['title'], translation.document.title) eq_(row['status'], status)
def test_revision_include_locale(self): """Include finds document in the correct locale.""" _, _, p = doc_rev_parser("English content", "Test title") # Parsing in English should find the French article doc = pq(p.parse("[[Include:Test title]]", locale="en-US")) eq_("English content", doc.text()) # The French article will include the English content as fallback. doc = pq(p.parse("[[I:Test title]]", locale="fr")) eq_("English content", doc.text()) # Create the French article, and test again parent_rev = RevisionFactory() d = DocumentFactory(parent=parent_rev.document, title="Test title", locale="fr") ApprovedRevisionFactory(document=d, content="French content") # Parsing in French should find the French article doc = pq(p.parse("[[Include:Test title]]", locale="fr")) eq_("French content", doc.text())
def test_redirect_nondefault_locales(self): title1 = 'title1' title2 = 'title2' redirect_to = ApprovedRevisionFactory(document__title=title1, document__locale='es', document=DocumentFactory( title=title1, locale='es')) redirector = RedirectRevisionFactory(target=redirect_to.document, document__title=title2, document__locale='es', is_approved=True) eq_(redirect_to.document.get_absolute_url(), redirector.document.redirect_url())
def test_correct_based_on_to_current_revision(self): """Assure Revision.clean() changes a bad based_on value to the English doc's current_revision when there is one.""" # Make English rev: en_rev = ApprovedRevisionFactory() # Make Deutsch translation: de_doc = DocumentFactory(parent=en_rev.document, locale='de') de_rev = RevisionFactory(document=de_doc) # Set based_on to some random, unrelated Document's rev: de_rev.based_on = RevisionFactory() # Try to recover: self.assertRaises(ValidationError, de_rev.clean) eq_(en_rev.document.current_revision, de_rev.based_on)
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_direct_recursion(self): """Make sure direct recursion is caught on the very first nesting.""" d = DocumentFactory(title='Boo') # Twice so the second revision sees content identical to itself: ApprovedRevisionFactory.create_batch(2, document=d, content='Fine [[Include:Boo]] Fellows') eq_('<p>Fine %s Fellows\n</p>' % (RECURSION_MESSAGE % 'Boo'), d.content_parsed)