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_add_and_delete(self): """Adding a revision should add it to the index. Deleting should delete it. """ r = RevisionFactory() self.refresh() eq_(RevisionMetricsMappingType.search().count(), 1) r.delete() self.refresh() eq_(RevisionMetricsMappingType.search().count(), 0)
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_correct_based_on_to_none(self): """Assure Revision.clean() changes a bad based_on value to None when there is no current_revision of the English document.""" r1 = RevisionFactory() # Revision of some other unrelated Document r2 = RevisionFactory.build(based_on=r1) self.assertRaises(ValidationError, r2.clean) eq_(None, r2.based_on)
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_majorly_outdated(self): """Test the is_majorly_outdated method.""" trans = TranslatedRevisionFactory(is_approved=True) trans_doc = trans.document # Make sure a doc returns False if it has no parent: assert not trans_doc.parent.is_majorly_outdated() assert not trans_doc.is_majorly_outdated() # Add a parent revision of MAJOR significance: r = RevisionFactory(document=trans_doc.parent, significance=MAJOR_SIGNIFICANCE) assert not trans_doc.is_majorly_outdated() # Approve it: r.is_approved = True r.is_ready_for_localization = True r.save() assert trans_doc.is_majorly_outdated()
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_correct_ready_for_localization_if_unapproved(self): """Revision.clean() must clear is_ready_for_l10n if not is_approved.""" r = RevisionFactory.build(is_approved=False, is_ready_for_localization=True) r.clean() assert not r.is_ready_for_localization
def test_save_bad_based_on(self): """Saving a Revision with a bad based_on value raises an error.""" r1 = RevisionFactory() # Revision of some other unrelated Document r2 = RevisionFactory.build(based_on=r1) self.assertRaises(ProgrammingError, r2.save)
def test_unapproved_articles(self): eq_(0, len(kb_overview_rows())) RevisionFactory() eq_(1, len(kb_overview_rows()))
def setUp(self): super(JsonViewTests, self).setUp() d = DocumentFactory(title='an article title', slug='article-title') RevisionFactory(document=d, is_approved=True)
def test_no_approved_revs(self): """Articles with no approved revisions should not appear.""" RevisionFactory(is_approved=False, is_ready_for_localization=False, significance=MAJOR_SIGNIFICANCE) eq_([], self.titles())
def test_update_l10n_coverage_metrics(self): """Test the cron job that updates l10n coverage metrics.""" p = ProductFactory(visible=True) # Create en-US documents. revisions = RevisionFactory.create_batch( 20, is_approved=True, is_ready_for_localization=True, document__products=[p], document__locale='en-US') r1 = revisions[0] r2 = revisions[1] # Translate one to es. d = DocumentFactory(parent=r1.document, locale='es') ApprovedRevisionFactory(document=d, based_on=r1) # Translate two to de. d = DocumentFactory(parent=r1.document, locale='de') ApprovedRevisionFactory(document=d, based_on=r1) d = DocumentFactory(parent=r2.document, locale='de') ApprovedRevisionFactory(document=d, based_on=r2) # Translate all to ru. for r in revisions: d = DocumentFactory(parent=r.document, locale='ru') RevisionFactory(document=d, based_on=r, is_approved=True) # Call the cronjob update_l10n_coverage_metrics() # Verify es metrics. eq_(6, WikiMetric.objects.filter(locale='es').count()) eq_(5.0, WikiMetric.objects.get(locale='es', product=p, code=L10N_TOP20_CODE).value) eq_(5.0, WikiMetric.objects.get(locale='es', product=p, code=L10N_TOP100_CODE).value) eq_(5.0, WikiMetric.objects.get(locale='es', product=p, code=L10N_ALL_CODE).value) eq_(5.0, WikiMetric.objects.get(locale='es', product=None, code=L10N_TOP20_CODE).value) eq_(5.0, WikiMetric.objects.get(locale='es', product=None, code=L10N_TOP100_CODE).value) eq_(5.0, WikiMetric.objects.get(locale='es', product=None, code=L10N_ALL_CODE).value) # Verify de metrics. eq_(6, WikiMetric.objects.filter(locale='de').count()) eq_(10.0, WikiMetric.objects.get(locale='de', product=p, code=L10N_TOP20_CODE).value) eq_(10.0, WikiMetric.objects.get(locale='de', product=None, code=L10N_TOP100_CODE).value) eq_(10.0, WikiMetric.objects.get(locale='de', product=p, code=L10N_ALL_CODE).value) eq_(10.0, WikiMetric.objects.get(locale='de', product=None, code=L10N_TOP20_CODE).value) eq_(10.0, WikiMetric.objects.get(locale='de', product=None, code=L10N_TOP100_CODE).value) eq_(10.0, WikiMetric.objects.get(locale='de', product=None, code=L10N_ALL_CODE).value) # Verify ru metrics. eq_(6, WikiMetric.objects.filter(locale='ru').count()) eq_(100.0, WikiMetric.objects.get(locale='ru', product=p, code=L10N_TOP20_CODE).value) eq_(100.0, WikiMetric.objects.get(locale='ru', product=None, code=L10N_TOP100_CODE).value) eq_(100.0, WikiMetric.objects.get(locale='ru', product=p, code=L10N_ALL_CODE).value) eq_(100.0, WikiMetric.objects.get(locale='ru', product=None, code=L10N_TOP20_CODE).value) eq_(100.0, WikiMetric.objects.get(locale='ru', product=None, code=L10N_TOP100_CODE).value) eq_(100.0, WikiMetric.objects.get(locale='ru', product=None, code=L10N_ALL_CODE).value) # Verify it metrics. eq_(6, WikiMetric.objects.filter(locale='it').count()) eq_(0.0, WikiMetric.objects.get(locale='it', product=p, code=L10N_TOP20_CODE).value) eq_(0.0, WikiMetric.objects.get(locale='it', product=None, code=L10N_TOP100_CODE).value) eq_(0.0, WikiMetric.objects.get(locale='it', product=p, code=L10N_ALL_CODE).value) eq_(0.0, WikiMetric.objects.get(locale='it', product=None, code=L10N_TOP20_CODE).value) eq_(0.0, WikiMetric.objects.get(locale='it', product=None, code=L10N_TOP100_CODE).value) eq_(0.0, WikiMetric.objects.get(locale='it', product=None, code=L10N_ALL_CODE).value)
def test_only_rejected(self): """If there are only rejected revisions, return None.""" rejected = RevisionFactory(is_approved=False, reviewed=datetime.now()) eq_(None, rejected.document.localizable_or_latest_revision())
def test_update_active_contributor_metrics(self): """Test the command that updates active contributor metrics.""" day = date(2013, 7, 31) last_month = date(2013, 6, 15) start_date = date(2013, 6, 1) before_start = date(2013, 5, 31) # Create some revisions to test with: # 3 'en-US' contributors: d = DocumentFactory(locale="en-US") u = UserFactory() RevisionFactory(document=d, created=last_month, is_approved=True, reviewer=u) RevisionFactory(document=d, creator=u, created=last_month) p = ProductFactory(visible=True) RevisionFactory(created=start_date, document__products=[p]) # Add two that shouldn't count: RevisionFactory(document=d, created=before_start) RevisionFactory(document=d, created=day) # 4 'es' contributors: d = DocumentFactory(locale="es") RevisionFactory(document=d, created=last_month, is_approved=True, reviewer=u) RevisionFactory(document=d, creator=u, created=last_month, reviewer=UserFactory()) RevisionFactory(document=d, created=start_date) RevisionFactory(document=d, created=last_month) # Add two that shouldn't count: RevisionFactory(document=d, created=before_start) RevisionFactory(document=d, created=day) # Call the command. call_command("update_l10n_contributor_metrics", str(day)) eq_( 3.0, WikiMetric.objects.get(locale="en-US", product=None, date=start_date).value) eq_( 1.0, WikiMetric.objects.get(locale="en-US", product=p, date=start_date).value) eq_( 4.0, WikiMetric.objects.get(locale="es", product=None, date=start_date).value) eq_( 0.0, WikiMetric.objects.get(locale="es", product=p, date=start_date).value)
def _make_backdated_revision(backdate): return RevisionFactory(created=date.today() - timedelta(days=backdate))
def test_update_l10n_coverage_metrics(self): """Test the command that updates l10n coverage metrics.""" p = ProductFactory(visible=True) # Create en-US documents. revisions = RevisionFactory.create_batch( 20, is_approved=True, is_ready_for_localization=True, document__products=[p], document__locale="en-US", ) r1 = revisions[0] r2 = revisions[1] # Translate one to es. d = DocumentFactory(parent=r1.document, locale="es") ApprovedRevisionFactory(document=d, based_on=r1) # Translate two to de. d = DocumentFactory(parent=r1.document, locale="de") ApprovedRevisionFactory(document=d, based_on=r1) d = DocumentFactory(parent=r2.document, locale="de") ApprovedRevisionFactory(document=d, based_on=r2) # Translate all to ru. for r in revisions: d = DocumentFactory(parent=r.document, locale="ru") RevisionFactory(document=d, based_on=r, is_approved=True) # Call the management command call_command("update_l10n_coverage_metrics") # Verify es metrics. eq_(6, WikiMetric.objects.filter(locale="es").count()) eq_( 5.0, WikiMetric.objects.get(locale="es", product=p, code=L10N_TOP20_CODE).value) eq_( 5.0, WikiMetric.objects.get(locale="es", product=p, code=L10N_TOP100_CODE).value) eq_( 5.0, WikiMetric.objects.get(locale="es", product=p, code=L10N_ALL_CODE).value) eq_( 5.0, WikiMetric.objects.get(locale="es", product=None, code=L10N_TOP20_CODE).value) eq_( 5.0, WikiMetric.objects.get(locale="es", product=None, code=L10N_TOP100_CODE).value) eq_( 5.0, WikiMetric.objects.get(locale="es", product=None, code=L10N_ALL_CODE).value) # Verify de metrics. eq_(6, WikiMetric.objects.filter(locale="de").count()) eq_( 10.0, WikiMetric.objects.get(locale="de", product=p, code=L10N_TOP20_CODE).value) eq_( 10.0, WikiMetric.objects.get(locale="de", product=None, code=L10N_TOP100_CODE).value) eq_( 10.0, WikiMetric.objects.get(locale="de", product=p, code=L10N_ALL_CODE).value) eq_( 10.0, WikiMetric.objects.get(locale="de", product=None, code=L10N_TOP20_CODE).value) eq_( 10.0, WikiMetric.objects.get(locale="de", product=None, code=L10N_TOP100_CODE).value) eq_( 10.0, WikiMetric.objects.get(locale="de", product=None, code=L10N_ALL_CODE).value) # Verify ru metrics. eq_(6, WikiMetric.objects.filter(locale="ru").count()) eq_( 100.0, WikiMetric.objects.get(locale="ru", product=p, code=L10N_TOP20_CODE).value) eq_( 100.0, WikiMetric.objects.get(locale="ru", product=None, code=L10N_TOP100_CODE).value) eq_( 100.0, WikiMetric.objects.get(locale="ru", product=p, code=L10N_ALL_CODE).value) eq_( 100.0, WikiMetric.objects.get(locale="ru", product=None, code=L10N_TOP20_CODE).value) eq_( 100.0, WikiMetric.objects.get(locale="ru", product=None, code=L10N_TOP100_CODE).value) eq_( 100.0, WikiMetric.objects.get(locale="ru", product=None, code=L10N_ALL_CODE).value) # Verify it metrics. eq_(6, WikiMetric.objects.filter(locale="it").count()) eq_( 0.0, WikiMetric.objects.get(locale="it", product=p, code=L10N_TOP20_CODE).value) eq_( 0.0, WikiMetric.objects.get(locale="it", product=None, code=L10N_TOP100_CODE).value) eq_( 0.0, WikiMetric.objects.get(locale="it", product=p, code=L10N_ALL_CODE).value) eq_( 0.0, WikiMetric.objects.get(locale="it", product=None, code=L10N_TOP20_CODE).value) eq_( 0.0, WikiMetric.objects.get(locale="it", product=None, code=L10N_TOP100_CODE).value) eq_( 0.0, WikiMetric.objects.get(locale="it", product=None, code=L10N_ALL_CODE).value)
def _create_en_and_de_docs(self): en = settings.WIKI_DEFAULT_LANGUAGE en_doc = DocumentFactory(locale=en, slug='english-slug') de_doc = DocumentFactory(locale='de', parent=en_doc) RevisionFactory(document=de_doc, is_approved=True) return en_doc, de_doc
def test_latest_unreviewed_if_none_ready(self): """Return the latest unreviewed revision when no ready one exists.""" unreviewed = RevisionFactory(is_approved=False, reviewed=None) eq_(unreviewed, unreviewed.document.localizable_or_latest_revision())
def test_filter_by_category(self): RevisionFactory(document__category=CATEGORIES[1][0]) eq_(1, len(kb_overview_rows())) eq_(0, len(kb_overview_rows(category=CATEGORIES[0][0]))) eq_(1, len(kb_overview_rows(category=CATEGORIES[1][0])))
def generate_sampledata(options): # There are two products in our schema try: firefox = Product.objects.get(slug='firefox') except Product.DoesNotExist: # Note: This matches migration 156. When run in the tests, the # migrations don't happen. firefox = Product(title='Firefox', description='Web browser for Windows, Mac and Linux', display_order=1, visible=True, slug='firefox') firefox.save() try: mobile = Product.objects.get(slug='mobile') except Product.DoesNotExist: # Note: This matches migration 156. When run in the tests, the # migrations don't happen. mobile = Product( title='Firefox for Android', description='Web browser for Android smartphones and tablets', display_order=2, visible=True, slug='mobile') mobile.save() for p in [firefox, mobile]: # Create the top 10 topics used TopicFactory(product=p, title='Learn the Basics: get started', slug='get-started') TopicFactory(product=p, title='Download, install and migration', slug='download-and-install') TopicFactory(product=p, title='Privacy and security settings', slug='privacy-and-security') TopicFactory(product=p, title='Customize controls, options and add-ons', slug='customize') TopicFactory( product=p, title='Fix slowness, crashing, error messages and other problems', slug='fix-problems') TopicFactory(product=p, title='Tips and tricks', slug='tips') TopicFactory(product=p, title='Bookmarks', slug='bookmarks') TopicFactory(product=p, title='Cookies', slug='cookies') TopicFactory(product=p, title='Tabs', slug='tabs') TopicFactory(product=p, title='Websites', slug='websites') TopicFactory(product=p, title='Other', slug='other') # 'hot' topic is created by a migration. Check for it's existence # before creating a new one. if not Topic.objects.filter(product=p, slug='hot').exists(): TopicFactory(product=p, title='Hot topics', slug='hot') # Create a hot article flash = DocumentFactory(title='Flash 11.3 crashes', slug='flash-113-crashes') RevisionFactory(content=FLASH_CONTENT, document=flash, is_approved=True, reviewed=datetime.now()) flash.products.add(firefox) flash.topics.add(Topic.objects.get(product=firefox, slug='fix-problems')) flash.topics.add(Topic.objects.get(product=firefox, slug='hot')) # Generate 9 sample documents with 2 topics each topics = list(Topic.objects.all()) for i in range(9): d = DocumentFactory(title='Sample Article %s' % str(i + 1), slug='sample-article-%s' % str(i + 1)) RevisionFactory(document=d, is_approved=True, reviewed=datetime.now()) d.products.add(firefox) d.products.add(mobile) d.topics.add(topics[i]) d.topics.add(topics[i + 11]) ApprovedRevisionFactory(document__products=[firefox, mobile], document__topics=[topics[i], topics[i + 1]])