示例#1
0
    def test_it_works(self):
        u1 = UserFactory()
        u2 = UserFactory()

        RevisionFactory(creator=u1)
        r2 = RevisionFactory(creator=u1, reviewer=u2)
        r3 = RevisionFactory(creator=u2)

        self.refresh()

        req = self.factory.get('/')
        data = self.api.get_data(req)

        eq_(data['count'], 2)

        eq_(data['results'][0]['user']['username'], u1.username)
        eq_(data['results'][0]['rank'], 1)
        eq_(data['results'][0]['revision_count'], 2)
        eq_(data['results'][0]['review_count'], 0)
        eq_(data['results'][0]['last_contribution_date'],
            r2.created.replace(microsecond=0))

        eq_(data['results'][1]['user']['username'], u2.username)
        eq_(data['results'][1]['rank'], 2)
        eq_(data['results'][1]['revision_count'], 1)
        eq_(data['results'][1]['review_count'], 1)
        eq_(data['results'][1]['last_contribution_date'],
            r3.created.replace(microsecond=0))
示例#2
0
    def test_top_contributors_kb(self):
        d = DocumentFactory(locale='en-US')
        r1 = RevisionFactory(document=d)
        RevisionFactory(document=d, creator=r1.creator)
        RevisionFactory(document=d)
        r4 = RevisionFactory(document=d, created=date.today() - timedelta(days=91))

        self.refresh()

        # By default, we should only get 2 top contributors back.
        top, _ = top_contributors_kb()
        eq_(2, len(top))
        assert r4.creator_id not in [u['term'] for u in top]
        eq_(r1.creator_id, top[0]['term'])

        # If we specify an older start, then we get all 3.
        top, _ = top_contributors_kb(start=date.today() - timedelta(days=92))
        eq_(3, len(top))

        # If we also specify an older end date, we only get the creator for
        # the older revision.
        top, _ = top_contributors_kb(
            start=date.today() - timedelta(days=92),
            end=date.today() - timedelta(days=1))
        eq_(1, len(top))
        eq_(r4.creator_id, top[0]['term'])
示例#3
0
    def test_last_contribution_date(self):
        """Verify the last_contribution_date field works properly."""
        u = UserFactory(username="******")
        self.refresh()

        data = UserMappingType.search().query(username__match="satdav")[0]
        assert not data["last_contribution_date"]

        # Add a Support Forum answer. It should be the last contribution.
        d = datetime(2014, 1, 2)
        AnswerFactory(creator=u, created=d)
        u.profile.save()  # we need to resave the profile to force a reindex
        self.refresh()

        data = UserMappingType.search().query(username__match="satdav")[0]
        eq_(data["last_contribution_date"], d)

        # Add a Revision edit. It should be the last contribution.
        d = datetime(2014, 1, 3)
        RevisionFactory(created=d, creator=u)
        u.profile.save()  # we need to resave the profile to force a reindex
        self.refresh()

        data = UserMappingType.search().query(username__match="satdav")[0]
        eq_(data["last_contribution_date"], d)

        # Add a Revision review. It should be the last contribution.
        d = datetime(2014, 1, 4)
        RevisionFactory(reviewed=d, reviewer=u)

        u.profile.save()  # we need to resave the profile to force a reindex
        self.refresh()

        data = UserMappingType.search().query(username__match="satdav")[0]
        eq_(data["last_contribution_date"], d)
示例#4
0
    def test_wiki_topics(self):
        """Search wiki for topics, includes multiple."""
        t1 = TopicFactory(slug="doesnotexist")
        t2 = TopicFactory(slug="extant")
        t3 = TopicFactory(slug="tagged")

        doc = DocumentFactory(locale="en-US", category=10)
        doc.topics.add(t2)
        RevisionFactory(document=doc, is_approved=True)

        doc = DocumentFactory(locale="en-US", category=10)
        doc.topics.add(t2)
        doc.topics.add(t3)
        RevisionFactory(document=doc, is_approved=True)

        self.refresh()

        topic_vals = (
            (t1.slug, 0),
            (t2.slug, 2),
            (t3.slug, 1),
            ([t2.slug, t3.slug], 1),
        )

        qs = {"a": 1, "w": 1, "format": "json"}
        for topics, number in topic_vals:
            qs.update({"topics": topics})
            response = self.client.get(reverse("search.advanced"), qs)
            eq_(number, json.loads(response.content)["total"])
示例#5
0
    def test_majorly_outdated_with_unapproved_parents(self):
        """Migrations might introduce translated revisions without based_on
        set. Tolerate these.

        If based_on of a translation's current_revision is None, the
        translation should be considered out of date iff any
        major-significance, approved revision to the English article exists.

        """
        # Create a parent doc with only an unapproved revision...
        parent_rev = RevisionFactory()
        # ...and a translation with a revision based on nothing.
        trans = DocumentFactory(parent=parent_rev.document, locale='de')
        trans_rev = RevisionFactory(document=trans, is_approved=True)

        assert trans_rev.based_on is None, \
            ('based_on defaulted to something non-None, which this test '
             "wasn't expecting.")

        assert not trans.is_majorly_outdated(), \
            ('A translation was considered majorly out of date even though '
             'the English document has never had an approved revision of '
             'major significance.')

        ApprovedRevisionFactory(document=parent_rev.document,
                                significance=MAJOR_SIGNIFICANCE,
                                is_ready_for_localization=True)

        assert trans.is_majorly_outdated(), \
            ('A translation was not considered majorly outdated when its '
             "current revision's based_on value was None.")
示例#6
0
    def test_it_works(self):
        u1 = UserFactory()
        u2 = UserFactory()

        RevisionFactory(creator=u1)
        r2 = RevisionFactory(creator=u1, reviewer=u2)
        r3 = RevisionFactory(creator=u2)

        self.refresh()

        req = self.factory.get("/")
        data = self.api.get_data(req)

        eq_(data["count"], 2)

        eq_(data["results"][0]["user"]["username"], u1.username)
        eq_(data["results"][0]["rank"], 1)
        eq_(data["results"][0]["revision_count"], 2)
        eq_(data["results"][0]["review_count"], 0)
        eq_(data["results"][0]["last_contribution_date"],
            r2.created.replace(microsecond=0))

        eq_(data["results"][1]["user"]["username"], u2.username)
        eq_(data["results"][1]["rank"], 2)
        eq_(data["results"][1]["revision_count"], 1)
        eq_(data["results"][1]["review_count"], 1)
        eq_(data["results"][1]["last_contribution_date"],
            r3.created.replace(microsecond=0))
示例#7
0
    def test_previous(self):
        r1 = RevisionFactory(is_approved=True)
        d = r1.document
        r2 = RevisionFactory(document=d, is_approved=True)

        eq_(r1.previous, None)
        eq_(r2.previous.id, r1.id)
    def test_filter_by_doctype(self):
        desktop = ProductFactory(slug=u'desktop')
        ques = QuestionFactory(title=u'audio', product=desktop)
        ans = AnswerFactory(question=ques, content=u'volume')
        AnswerVoteFactory(answer=ans, helpful=True)

        doc = DocumentFactory(title=u'audio', locale=u'en-US', category=10, products=[desktop])
        RevisionFactory(document=doc, is_approved=True)

        doc = DocumentFactory(title=u'audio too', locale=u'en-US', category=10, products=[desktop])
        RevisionFactory(document=doc, is_approved=True)

        self.refresh()

        # There should be 2 results for kb (w=1) and 1 for questions (w=2).
        response = self.client.get(reverse('search'), {
            'q': 'audio', 'format': 'json', 'w': '1'})
        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content['total'], 2)

        response = self.client.get(reverse('search'), {
            'q': 'audio', 'format': 'json', 'w': '2'})
        eq_(200, response.status_code)
        content = json.loads(response.content)
        eq_(content['total'], 1)
示例#9
0
    def test_l10n_welcome_email(self, get_current):
        get_current.return_value.domain = 'testserver'

        u1 = UserFactory()
        u2 = UserFactory(profile__first_l10n_email_sent=True)

        two_days = datetime.now() - timedelta(hours=48)

        d = DocumentFactory(locale='ru')
        RevisionFactory(document=d, creator=u1, created=two_days)
        RevisionFactory(document=d, creator=u2, created=two_days)

        # Clear out the notifications that were sent
        mail.outbox = []
        # Send email(s) for welcome messages
        cron.send_welcome_emails()

        # There should be an email for u1 only.
        # u2 has already recieved the email

        eq_(len(mail.outbox), 1)
        attrs_eq(mail.outbox[0], to=[u1.email])

        # Links should be locale-neutral
        assert 'en-US' not in mail.outbox[0].body

        # Check that no links used the wrong host.
        assert 'support.mozilla.org' not in mail.outbox[0].body
        # Check that one link used the right host.
        assert 'https://testserver/kb/locales' in mail.outbox[0].body
        # Assumption: links will be done consistently, and so this is enough testing.

        # u3's flag should now be set.
        u1 = User.objects.get(id=u1.id)
        eq_(u1.profile.first_l10n_email_sent, True)
示例#10
0
    def test_active_contributors(self):
        """Test active contributors API call."""
        # 2 en-US revisions by 2 contributors:
        r1 = RevisionFactory()
        r2 = RevisionFactory()
        # A translation with 2 contributors (translator + reviewer):
        d = DocumentFactory(parent=r1.document, locale="es")
        RevisionFactory(
            document=d, reviewed=datetime.now(), reviewer=r1.creator, creator=r2.creator
        )
        # 1 active support forum contributor:
        # A user with 10 answers
        u1 = UserFactory()
        for x in range(10):
            AnswerFactory(creator=u1)
        # A user with 9 answers
        u2 = UserFactory()
        # FIXME: create_batch?
        for x in range(9):
            AnswerFactory(creator=u2)
        # A user with 1 answer
        u3 = UserFactory()
        AnswerFactory(creator=u3)

        # Create metric kinds and update metrics for tomorrow (today's
        # activity shows up tomorrow).
        self._make_contributor_metric_kinds()
        call_command("update_contributor_metrics", str(date.today() + timedelta(days=1)))

        r = self._get_api_result("api.kpi.contributors")

        eq_(r["objects"][0]["en_us"], 2)
        eq_(r["objects"][0]["non_en_us"], 2)
        eq_(r["objects"][0]["support_forum"], 1)
示例#11
0
    def test_synonyms_work_in_search_view(self):
        d1 = DocumentFactory(title='frob')
        d2 = DocumentFactory(title='glork')
        RevisionFactory(document=d1, is_approved=True)
        RevisionFactory(document=d2, is_approved=True)

        self.refresh()

        # First search without synonyms
        response = self.client.get(reverse('search'), {'q': 'frob'})
        doc = pq(response.content)
        header = doc.find('#search-results h2').text().strip()
        eq_(header, 'Found 1 result for frob for All Products')

        # Now add a synonym.
        SynonymFactory(from_words='frob', to_words='frob, glork')
        update_synonyms_task()
        self.refresh()

        # Forward search
        response = self.client.get(reverse('search'), {'q': 'frob'})
        doc = pq(response.content)
        header = doc.find('#search-results h2').text().strip()
        eq_(header, 'Found 2 results for frob for All Products')

        # Reverse search
        response = self.client.get(reverse('search'), {'q': 'glork'})
        doc = pq(response.content)
        header = doc.find('#search-results h2').text().strip()
        eq_(header, 'Found 1 result for glork for All Products')
示例#12
0
文件: test_es.py 项目: zu83/kitsune
    def test_reindex_users_that_contributed_yesterday(self):
        yesterday = datetime.now() - timedelta(days=1)

        # Verify for answers.
        u = UserFactory(username="******")
        AnswerFactory(creator=u, created=yesterday)

        call_command("reindex_users_that_contributed_yesterday")
        self.refresh()

        data = UserMappingType.search().query(username__match="answerer")[0]
        eq_(data["last_contribution_date"].date(), yesterday.date())

        # Verify for edits.
        u = UserFactory(username="******")
        RevisionFactory(creator=u, created=yesterday)

        call_command("reindex_users_that_contributed_yesterday")
        self.refresh()

        data = UserMappingType.search().query(username__match="editor")[0]
        eq_(data["last_contribution_date"].date(), yesterday.date())

        # Verify for reviews.
        u = UserFactory(username="******")
        RevisionFactory(reviewer=u, reviewed=yesterday)

        call_command("reindex_users_that_contributed_yesterday")
        self.refresh()

        data = UserMappingType.search().query(username__match="reviewer")[0]
        eq_(data["last_contribution_date"].date(), yesterday.date())
示例#13
0
    def test_synonyms_work_in_search_view(self):
        d1 = DocumentFactory(title="frob")
        d2 = DocumentFactory(title="glork")
        RevisionFactory(document=d1, is_approved=True)
        RevisionFactory(document=d2, is_approved=True)

        self.refresh()

        # First search without synonyms
        response = self.client.get(reverse("search"), {"q": "frob"})
        doc = pq(response.content)
        header = doc.find("#search-results h2").text().strip()
        eq_(header, "Found 1 result for frob for All Products")

        # Now add a synonym.
        SynonymFactory(from_words="frob", to_words="frob, glork")
        update_synonyms_task()
        self.refresh()

        # Forward search
        response = self.client.get(reverse("search"), {"q": "frob"})
        doc = pq(response.content)
        header = doc.find("#search-results h2").text().strip()
        eq_(header, "Found 2 results for frob for All Products")

        # Reverse search
        response = self.client.get(reverse("search"), {"q": "glork"})
        doc = pq(response.content)
        header = doc.find("#search-results h2").text().strip()
        eq_(header, "Found 1 result for glork for All Products")
示例#14
0
    def test_wiki_topics(self):
        """Search wiki for topics, includes multiple."""
        t1 = TopicFactory(slug='doesnotexist')
        t2 = TopicFactory(slug='extant')
        t3 = TopicFactory(slug='tagged')

        doc = DocumentFactory(locale=u'en-US', category=10)
        doc.topics.add(t2)
        RevisionFactory(document=doc, is_approved=True)

        doc = DocumentFactory(locale=u'en-US', category=10)
        doc.topics.add(t2)
        doc.topics.add(t3)
        RevisionFactory(document=doc, is_approved=True)

        self.refresh()

        topic_vals = (
            (t1.slug, 0),
            (t2.slug, 2),
            (t3.slug, 1),
            ([t2.slug, t3.slug], 1),
        )

        qs = {'a': 1, 'w': 1, 'format': 'json'}
        for topics, number in topic_vals:
            qs.update({'topics': topics})
            response = self.client.get(reverse('search.advanced'), qs)
            eq_(number, json.loads(response.content)['total'])
示例#15
0
    def test_sortby_documents_helpful(self):
        """Tests advanced search with a sortby_documents by helpful"""
        r1 = RevisionFactory(is_approved=True)
        r2 = RevisionFactory(is_approved=True)
        HelpfulVoteFactory(revision=r2, helpful=True)

        # Note: We have to wipe and rebuild the index because new
        # helpful_votes don't update the index data.
        self.setup_indexes()
        self.reindex_and_refresh()

        # r2.document should come first with 1 vote.
        response = self.client.get(reverse('search.advanced'), {
            'w': '1', 'a': '1', 'sortby_documents': 'helpful',
            'format': 'json'
        })
        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(r2.document.title, content['results'][0]['title'])

        # Vote twice on r1, now it should come first.
        HelpfulVoteFactory(revision=r1, helpful=True)
        HelpfulVoteFactory(revision=r1, helpful=True)

        self.setup_indexes()
        self.reindex_and_refresh()

        response = self.client.get(reverse('search.advanced'), {
            'w': '1', 'a': '1', 'sortby_documents': 'helpful',
            'format': 'json'})
        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(r1.document.title, content['results'][0]['title'])
示例#16
0
    def setUp(self):
        # create some random revisions.

        RevisionFactory()
        RevisionFactory(is_approved=True)
        RevisionFactory(is_approved=True)
        RevisionFactory(is_approved=True)
        RevisionFactory(is_approved=True)
示例#17
0
    def test_num_documents(self):
        """Verify the number of documents contributed by user."""
        u = UserFactory()
        RevisionFactory(creator=u)
        RevisionFactory(creator=u)

        r = self.client.get(reverse('users.profile', args=[u.username]))
        eq_(200, r.status_code)
        assert '2 documents' in r.content
示例#18
0
    def test_what_links_here(self):
        d1 = DocumentFactory(title="D1")
        RevisionFactory(document=d1, content="", is_approved=True)
        d2 = DocumentFactory(title="D2")
        RevisionFactory(document=d2, content="[[D1]]", is_approved=True)

        url = reverse("wiki.what_links_here", args=[d1.slug])
        resp = self.client.get(url, follow=True)
        eq_(200, resp.status_code)
        assert b"D2" in resp.content
示例#19
0
    def test_what_links_here(self):
        d1 = DocumentFactory(title='D1')
        RevisionFactory(document=d1, content='', is_approved=True)
        d2 = DocumentFactory(title='D2')
        RevisionFactory(document=d2, content='[[D1]]', is_approved=True)

        url = reverse('wiki.what_links_here', args=[d1.slug])
        resp = self.client.get(url, follow=True)
        eq_(200, resp.status_code)
        assert 'D2' in resp.content
示例#20
0
    def setUp(self):
        super(ActiveContributorsTestCase, self).setUp()

        start_date = date.today() - timedelta(days=10)
        self.start_date = start_date
        before_start = start_date - timedelta(days=1)

        # Create some revisions to test with.

        # 3 'en-US' contributors:
        d = DocumentFactory(locale="en-US")
        u = UserFactory()
        self.user = u
        RevisionFactory(document=d, is_approved=True, reviewer=u)
        RevisionFactory(document=d, creator=u)

        self.product = ProductFactory()
        RevisionFactory(created=start_date, document__products=[self.product])

        # Add one that shouldn't count:
        self.en_us_old = RevisionFactory(document=d, created=before_start)

        # 4 'es' contributors:
        d = DocumentFactory(locale="es")
        RevisionFactory(document=d, is_approved=True, reviewer=u)
        RevisionFactory(document=d, creator=u, reviewer=UserFactory())
        RevisionFactory(document=d, created=start_date)
        RevisionFactory(document=d)
        # Add one that shouldn't count:
        self.es_old = RevisionFactory(document=d, created=before_start)
示例#21
0
    def test_revision_delete(self):
        RevisionFactory(document=self.document,
                        keywords="revision1",
                        is_approved=True)
        revision2 = RevisionFactory(document=self.document,
                                    keywords="revision2",
                                    is_approved=True)
        self.assertEqual(self.get_doc().keywords["en-US"], "revision2")
        revision2.delete()

        self.assertNotIn("revision2", self.get_doc().keywords["en-US"])
        self.assertEqual(self.get_doc().keywords["en-US"], "revision1")
示例#22
0
    def setUp(self):
        # create some random revisions.

        RevisionFactory()
        RevisionFactory(is_approved=True)
        RevisionFactory(is_approved=True)
        RevisionFactory(is_approved=True)
        RevisionFactory(is_approved=True)

        # TODO: fix this crap
        self.old_settings = copy(settings._wrapped.__dict__)
        settings.CELERY_ALWAYS_EAGER = True
示例#23
0
    def test_top_l10n(self):
        d = DocumentFactory(locale="es")
        r1 = RevisionFactory(document=d)
        r2 = RevisionFactory(document=d)

        self.refresh()

        response = self.client.get(urlparams(reverse("community.top_contributors", args=["l10n"])))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(2, len(doc("li.results-user")))
        assert str(r1.creator.username) in response.content
        assert str(r2.creator.username) in response.content
示例#24
0
 def test_translate_with_parent_slug_while_trans_article_available(self):
     doc = DocumentFactory(locale=settings.WIKI_DEFAULT_LANGUAGE)
     r = RevisionFactory(document=doc)
     trans_doc = DocumentFactory(parent=doc, locale='bn-BD', slug='bn-BD_slug')
     RevisionFactory(document=trans_doc, based_on=r)
     url = reverse('wiki.edit_document', args=[doc.slug], locale=trans_doc.locale)
     response = self.client.get(url)
     eq_(response.status_code, 200)
     # Check translate article template is being used
     self.assertTemplateUsed(response, 'wiki/translate.html')
     content = pq(response.content)
     eq_(content('#id_title').val(), trans_doc.title)
     eq_(content('#id_slug').val(), trans_doc.slug)
示例#25
0
    def test_top_kb(self):
        d = DocumentFactory(locale='en-US')
        r1 = RevisionFactory(document=d)
        r2 = RevisionFactory(document=d)

        self.refresh()

        response = self.client.get(urlparams(reverse('community.top_contributors', args=['kb'])))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(2, len(doc('li.results-user')))
        assert str(r1.creator.username) in response.content
        assert str(r2.creator.username) in response.content
示例#26
0
    def test_wiki_topics_inherit(self):
        """Translations inherit topics from their parents."""
        doc = DocumentFactory(locale="en-US", category=10)
        doc.topics.add(TopicFactory(slug="extant"))
        RevisionFactory(document=doc, is_approved=True)

        translated = DocumentFactory(locale="es", parent=doc, category=10)
        RevisionFactory(document=translated, is_approved=True)

        self.refresh()

        qs = {"a": 1, "w": 1, "format": "json", "topics": "extant"}
        response = self.client.get(reverse("search.advanced", locale="es"), qs)
        eq_(1, json.loads(response.content)["total"])
示例#27
0
    def test_wiki_topics_inherit(self):
        """Translations inherit topics from their parents."""
        doc = DocumentFactory(locale=u'en-US', category=10)
        doc.topics.add(TopicFactory(slug='extant'))
        RevisionFactory(document=doc, is_approved=True)

        translated = DocumentFactory(locale=u'es', parent=doc, category=10)
        RevisionFactory(document=translated, is_approved=True)

        self.refresh()

        qs = {'a': 1, 'w': 1, 'format': 'json', 'topics': 'extant'}
        response = self.client.get(reverse('search.advanced', locale='es'), qs)
        eq_(1, json.loads(response.content)['total'])
示例#28
0
    def test_top_contributors_l10n(self):
        d = DocumentFactory(locale="es")
        es1 = RevisionFactory(document=d)
        RevisionFactory(document=d, creator=es1.creator)
        RevisionFactory(document=d)
        es4 = RevisionFactory(document=d,
                              created=date.today() - timedelta(days=91))

        d = DocumentFactory(locale="de")
        de1 = RevisionFactory(document=d)
        RevisionFactory(document=d, creator=de1.creator)

        d = DocumentFactory(locale="en-US")
        RevisionFactory(document=d)
        RevisionFactory(document=d)

        self.refresh()

        # By default, we should only get 2 top contributors back for 'es'.
        top, _ = top_contributors_l10n(locale="es")
        eq_(2, len(top))
        assert es4.creator_id not in [u["term"] for u in top]
        eq_(es1.creator_id, top[0]["term"])

        # By default, we should only get 1 top contributors back for 'de'.
        top, _ = top_contributors_l10n(locale="de")
        eq_(1, len(top))
        eq_(de1.creator_id, top[0]["term"])

        # If no locale is passed, it includes all locales except en-US.
        top, _ = top_contributors_l10n()
        eq_(3, len(top))
示例#29
0
    def test_wiki_products_inherit(self):
        """Translations inherit products from their parents."""
        doc = DocumentFactory(locale="en-US", category=10)
        p = ProductFactory(title="Firefox", slug="desktop")
        doc.products.add(p)
        RevisionFactory(document=doc, is_approved=True)

        translated = DocumentFactory(locale="fr", parent=doc, category=10)
        RevisionFactory(document=translated, is_approved=True)

        self.refresh()

        qs = {"a": 1, "w": 1, "format": "json", "product": p.slug}
        response = self.client.get(reverse("search.advanced", locale="fr"), qs)
        eq_(1, json.loads(response.content)["total"])
示例#30
0
    def test_wiki_products_inherit(self):
        """Translations inherit products from their parents."""
        doc = DocumentFactory(locale=u'en-US', category=10)
        p = ProductFactory(title=u'Firefox', slug=u'desktop')
        doc.products.add(p)
        RevisionFactory(document=doc, is_approved=True)

        translated = DocumentFactory(locale=u'fr', parent=doc, category=10)
        RevisionFactory(document=translated, is_approved=True)

        self.refresh()

        qs = {'a': 1, 'w': 1, 'format': 'json', 'product': p.slug}
        response = self.client.get(reverse('search.advanced', locale='fr'), qs)
        eq_(1, json.loads(response.content)['total'])