def test_wiki_topics(self): """Search wiki for topics, includes multiple.""" t1 = topic(slug='doesnotexist', save=True) t2 = topic(slug='extant', save=True) t3 = topic(slug='tagged', save=True) doc = document(locale=u'en-US', category=10, save=True) doc.topics.add(t2) revision(document=doc, is_approved=True, save=True) doc = document(locale=u'en-US', category=10, save=True) doc.topics.add(t2) doc.topics.add(t3) revision(document=doc, is_approved=True, save=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'), qs) eq_(number, json.loads(response.content)['total'])
def test_absolute_url_subtopic(self): p = product(save=True) t1 = topic(product=p, save=True) t2 = topic(parent=t1, product=p, save=True) expected = '/products/{p}/{t1}/{t2}'.format(p=p.slug, t1=t1.slug, t2=t2.slug) actual = t2.get_absolute_url() eq_(actual, expected)
def test_locale_filter(self): """Only questions for the current locale should be shown on the questions front page for AAQ locales.""" eq_(Question.objects.count(), 0) p = product(slug=u'firefox', save=True) topic(title='Fix problems', slug='fix-problems', product=p, save=True) question( title='question cupcakes?', product=p, save=True, locale='en-US') question( title='question donuts?', product=p, save=True, locale='en-US') question( title='question pies?', product=p, save=True, locale='pt-BR') question( title='question pastries?', product=p, save=True, locale='de') def sub_test(locale, *titles): url = urlparams(reverse( 'questions.list', args=['all'], locale=locale)) response = self.client.get(url, follow=True) doc = pq(response.content) eq_msg(len(doc('section[id^=question]')), len(titles), 'Wrong number of results for {0}'.format(locale)) for substr in titles: assert substr in doc('.questions section .content h2 a').text() # en-US and pt-BR are both in AAQ_LANGUAGES, so should be filtered. sub_test('en-US', 'cupcakes?', 'donuts?') sub_test('pt-BR', 'pies?') # de is not in AAQ_LANGUAGES, so should show en-US, but not pt-BR sub_test('de', 'cupcakes?', 'donuts?', 'pastries?')
def test_locale_filter(self): """Only questions for the current locale should be shown on the questions front page for AAQ locales.""" eq_(Question.objects.count(), 0) p = product(slug=u"firefox", save=True) topic(title="Fix problems", slug="fix-problems", product=p, save=True) q1 = question(title="question cupcakes?", save=True, locale="en-US") q1.products.add(p) q2 = question(title="question donuts?", save=True, locale="en-US") q2.products.add(p) q3 = question(title="question pies?", save=True, locale="pt-BR") q3.products.add(p) q4 = question(title="question pastries?", save=True, locale="de") q4.products.add(p) def sub_test(locale, *titles): url = urlparams(reverse("questions.questions", locale=locale)) response = self.client.get(url, follow=True) doc = pq(response.content) eq_msg(len(doc("section[id^=question]")), len(titles), "Wrong number of results for {0}".format(locale)) for substr in titles: assert substr in doc(".questions section .content h2 a").text() # en-US and pt-BR are both in AAQ_LANGUAGES, so should be filtered. sub_test("en-US", "cupcakes?", "donuts?") sub_test("pt-BR", "pies?") # de is not in AAQ_LANGUAGES, so should show en-US, but not pt-BR sub_test("de", "cupcakes?", "donuts?", "pastries?")
def test_question_topics(self): """Search questions for topics.""" p = product(save=True) t1 = topic(slug='doesnotexist', product=p, save=True) t2 = topic(slug='cookies', product=p, save=True) t3 = topic(slug='sync', product=p, save=True) q = question(save=True) q.topics.add(t2) q = question(save=True) q.topics.add(t2) q.topics.add(t3) self.refresh() topic_vals = ( (t1.slug, 0), (t2.slug, 2), (t3.slug, 1), ([t2.slug, t3.slug], 1), ) qs = {'a': 1, 'w': 2, 'format': 'json'} for topics, number in topic_vals: qs.update({'topics': topics}) response = self.client.get(reverse('search'), qs) eq_(number, json.loads(response.content)['total'])
def test_search_suggestion_questions_locale(self): """Verifies the right languages show up in search suggestions.""" p = product(slug=u'firefox', save=True) topic(title='Fix problems', slug='fix-problems', product=p, save=True) q1 = question(title='question cupcakes?', save=True, locale='en-US') q1.products.add(p) q2 = question(title='question donuts?', save=True, locale='en-US') q2.products.add(p) q3 = question(title='question pies?', save=True, locale='pt-BR') q3.products.add(p) q4 = question(title='question pastries?', save=True, locale='de') q4.products.add(p) self.refresh() def sub_test(locale, *titles): url = urlparams(reverse('questions.aaq_step4', args=['desktop', 'fix-problems'], locale=locale), search='question') response = self.client.get(url, follow=True) doc = pq(response.content) eq_msg(len(doc('.result.question')), len(titles), 'Wrong number of results for {0}'.format(locale)) for substr in titles: assert substr in doc('.result.question h3 a').text() sub_test('en-US', 'cupcakes?', 'donuts?') sub_test('pt-BR', 'cupcakes?', 'donuts?', 'pies?') sub_test('de', 'cupcakes?', 'donuts?', 'pastries?')
def test_search_suggestion_question_age(self): """Verifies the view doesn't return old questions.""" p = product(slug=u'firefox', save=True) topic(title='Fix problems', slug='fix-problems', product=p, save=True) q1 = question(title='Fresh Cupcakes', save=True) q1.products.add(p) max_age = settings.SEARCH_DEFAULT_MAX_QUESTION_AGE too_old = datetime.now() - timedelta(seconds=max_age * 2) q2 = question(title='Stale Cupcakes', created=too_old, updated=too_old, save=True) q2.products.add(p) self.refresh() url = urlparams( reverse('questions.aaq_step4', args=['desktop', 'fix-problems']), search='cupcakes') response = self.client.get(url, follow=True) eq_(200, response.status_code) self.assertContains(response, q1.title) self.assertNotContains(response, q2.title)
def test_product_landing(self): """Verify that /products/<slug> page renders topics.""" # Create a product. p = product(save=True) # Create some topics. topic(slug=HOT_TOPIC_SLUG, product=p, save=True) topics = [] for i in range(11): topics.append(topic(product=p, save=True)) # Create a document and assign the product and 10 topics. doc = revision(is_approved=True, save=True).document doc.products.add(p) for i in range(10): doc.topics.add(topics[i]) self.refresh() # GET the product landing page and verify the content. url = reverse('products.product', args=[p.slug]) r = self.client.get(url, follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_(11, len(doc('#help-topics li'))) eq_(p.slug, doc('#support-search input[name=product]').attr['value'])
def test_ratelimit(self): """Make sure posting new questions is ratelimited""" data = {'title': 'A test question', 'content': 'I have this question that I hope...', 'sites_affected': 'http://example.com', 'ff_version': '3.6.6', 'os': 'Intel Mac OS X 10.6', 'plugins': '* Shockwave Flash 10.1 r53', 'useragent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X ' '10.6; en-US; rv:1.9.2.6) Gecko/20100625 ' 'Firefox/3.6.6'} p = product(slug='firefox', save=True) l = QuestionLocale.objects.get(locale=settings.LANGUAGE_CODE) p.questions_locales.add(l) topic(slug='fix-problems', product=p, save=True) url = urlparams( reverse('questions.aaq_step5', args=['desktop', 'fix-problems']), search='A test question') u = user(save=True) self.client.login(username=u.username, password='******') for i in range(0, 5): self.client.post(url, data, follow=True) response = self.client.post(url, data, follow=True) eq_(403, response.status_code)
def test_search_suggestions_archived_articles(self): """Verifies that archived articles aren't shown.""" p = product(slug=u'firefox', save=True) topic(title='Fix problems', slug='fix-problems', product=p, save=True) d1 = document(title=u'document donut', category=10, save=True) d1.products.add(p) revision(document=d1, is_approved=True, save=True) d2 = document(title=u'document cupcake', category=10, is_archived=True, save=True) d2.products.add(p) revision(document=d1, is_approved=True, save=True) self.refresh() url = urlparams( reverse('questions.aaq_step4', args=['desktop', 'fix-problems']), search='document') response = self.client.get(url, follow=True) eq_(200, response.status_code) doc = pq(response.content) eq_(len(doc('.result.document')), 1) assert 'donut' in doc('.result.document h3 a').text() assert 'cupcake' not in doc('.result.document h3 a').text()
def test_search_suggestion_questions_locale(self): """Verifies the right languages show up in search suggestions.""" p = product(slug=u"firefox", save=True) topic(title="Fix problems", slug="fix-problems", product=p, save=True) q1 = question(title="question cupcakes?", save=True, locale="en-US") q1.products.add(p) q2 = question(title="question donuts?", save=True, locale="en-US") q2.products.add(p) q3 = question(title="question pies?", save=True, locale="pt-BR") q3.products.add(p) q4 = question(title="question pastries?", save=True, locale="de") q4.products.add(p) self.refresh() def sub_test(locale, *titles): url = urlparams( reverse("questions.aaq_step4", args=["desktop", "fix-problems"], locale=locale), search="question" ) response = self.client.get(url, follow=True) doc = pq(response.content) eq_msg(len(doc(".result.question")), len(titles), "Wrong number of results for {0}".format(locale)) for substr in titles: assert substr in doc(".result.question h3 a").text() sub_test("en-US", "cupcakes?", "donuts?") sub_test("pt-BR", "cupcakes?", "donuts?", "pies?") sub_test("de", "cupcakes?", "donuts?", "pastries?")
def test_topic_disambiguation(self): # First make another product, and a colliding topic. # It has the same slug, but a different product. new_product = product(save=True) topic(product=new_product, slug=self.topic.slug, save=True) serializer = api.QuestionSerializer( context=self.context, data=self.data) serializer.is_valid(raise_exception=True) obj = serializer.save() eq_(obj.topic, self.topic)
def test_topic_disambiguation(self): # First make another product, and a colliding topic. # It has the same slug, but a different product. new_product = product(save=True) topic(product=new_product, slug=self.topic.slug, save=True) serializer = api.QuestionSerializer(context=self.context, data=self.data) serializer.is_valid(raise_exception=True) obj = serializer.save() eq_(obj.topic, self.topic)
def test_path(self): """Verify that the path property works.""" p = product(slug='p', save=True) t1 = topic(product=p, slug='t1', save=True) t2 = topic(product=p, slug='t2', parent=t1, save=True) t3 = topic(product=p, slug='t3', parent=t2, save=True) eq_(t1.path, [t1.slug]) eq_(t2.path, [t1.slug, t2.slug]) eq_(t3.path, [t1.slug, t2.slug, t3.slug])
def test_topic_disambiguation(self): # First make another product, and a colliding topic. # It has the same slug, but a different product. new_product = product(save=True) topic(product=new_product, slug=self.topic.slug, save=True) serializer = api.QuestionSerializer(context=self.context, data=self.data) eq_(serializer.errors, {}) ok_(serializer.is_valid()) eq_(serializer.object.topic, self.topic)
def test_topic_disambiguation(self): # First make another product, and a colliding topic. # It has the same slug, but a different product. new_product = product(save=True) topic(product=new_product, slug=self.topic.slug, save=True) serializer = api.QuestionSerializer( context=self.context, data=self.data) eq_(serializer.errors, {}) ok_(serializer.is_valid()) eq_(serializer.object.topic, self.topic)
def test_get_topics(self): """Test the get_topics() method.""" en_us = document(save=True) en_us.topics.add(topic(save=True)) en_us.topics.add(topic(save=True)) eq_(2, len(en_us.get_topics())) # Localized document inherits parent's topics. document(parent=en_us, save=True) eq_(2, len(en_us.get_topics()))
def test_document_listing_order(self): """Verify documents are listed in order of helpful votes.""" # Create topic, product and documents. p = product(save=True) t = topic(product=p, save=True) docs = [] for i in range(3): doc = revision(is_approved=True, save=True).document doc.topics.add(t) doc.products.add(p) docs.append(doc) # Add a helpful vote to the second document. It should be first now. rev = docs[1].current_revision helpful_vote(revision=rev, helpful=True, save=True) docs[1].save() # Votes don't trigger a reindex. 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 2 helpful votes the third document. It should be first now. rev = docs[2].current_revision helpful_vote(revision=rev, helpful=True, save=True) helpful_vote(revision=rev, helpful=True, save=True) docs[2].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:first-child > a').text(), docs[2].title)
def test_bogus_articles_in_bundle(self): p = product(title='firefox', save=True) topic(title='topic1', product=p, save=True) # Document with no revision should be fun doc = document(title='test2', locale='en-US', save=True) bundle = utils.bundle_for_product(p, 'en-US') eq_(0, len(bundle['docs'])) eq_(0, len(bundle['topics'])) # article with no html. revision(document=doc, content='', save=True) bundle = utils.bundle_for_product(p, 'en-US') eq_(0, len(bundle['docs'])) eq_(0, len(bundle['topics']))
def test_ratelimit(self): """Make sure posting new questions is ratelimited""" data = { "title": "A test question", "content": "I have this question that I hope...", "sites_affected": "http://example.com", "ff_version": "3.6.6", "os": "Intel Mac OS X 10.6", "plugins": "* Shockwave Flash 10.1 r53", "useragent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X " "10.6; en-US; rv:1.9.2.6) Gecko/20100625 " "Firefox/3.6.6", } p = product(slug="firefox", save=True) t = topic(slug="fix-problems", product=p, save=True) url = urlparams(reverse("questions.aaq_step5", args=["desktop", "fix-problems"]), search="A test question") u = user(save=True) self.client.login(username=u.username, password="******") for i in range(0, 5): self.client.post(url, data, follow=True) response = self.client.post(url, data, follow=True) eq_(403, response.status_code)
def _create_bundle(self, prod, locale=settings.WIKI_DEFAULT_LANGUAGE): p = product(title=prod, save=True) t = topic(title="topic1", product=p, save=True) if locale == settings.WIKI_DEFAULT_LANGUAGE: parent = lambda i: None else: def parent(i): d = document(title="test {0} {1}".format(locale, i), locale=settings.WIKI_DEFAULT_LANGUAGE, save=True) d.products.add(p) d.topics.add(t) d.save() revision(summary="test article {0}".format(i), document=d, is_approved=True, save=True) return d for i in xrange(5): d = document(title="test {0} {1}".format(locale, i), locale=locale, save=True) revision(summary="test article {0}".format(i), document=d, is_approved=True, save=True) d.products.add(p) d.topics.add(t) d.parent = parent(i) d.save() build_kb_bundles((prod,))
def test_bad_data(self): """Test for bad data""" data = { 'product': product(save=True).id, 'topic': topic(save=True).id } response = self._request(data=data) eq_(400, response.status_code)
def _create_product_bundle(prefix='moo'): p = product(title=prefix + 'firefox', save=True) t1 = topic(title=prefix + 'topic1', product=p, save=True) t2 = topic(title=prefix + 'topic2', product=p, save=True) doc1, expected_doc1 = _create_doc(title=prefix + 'doc1', product=p, topic=t1) doc2, expected_doc2 = _create_doc(title=prefix + 'doc2', product=p, topic=t2) expected_locale_doc = { 'key': u'en-US', 'name': u'English', 'products': [{ 'slug': p.slug, 'name': p.title }] } expected_topic1 = { 'key': 'en-US~' + p.slug + '~' + t1.slug, 'name': t1.title, 'docs': [doc1.slug], 'product': p.slug, 'slug': t1.slug, 'children': [] } expected_topic2 = { 'key': 'en-US~' + p.slug + '~' + t2.slug, 'name': t2.title, 'docs': [doc2.slug], 'product': p.slug, 'slug': t2.slug, 'children': [] } return p, { 'doc1': expected_doc1, 'doc2': expected_doc2, 'locale': expected_locale_doc, 'topic1': expected_topic1, 'topic2': expected_topic2 }
def _new_question(self, post_it=False): """Post a new question and return the response.""" p = product(slug="mobile", save=True) t = topic(slug="fix-problems", product=p, save=True) url = urlparams(reverse("questions.aaq_step5", args=[p.slug, t.slug]), search="A test question") if post_it: return self.client.post(url, self.data, follow=True) return self.client.get(url, follow=True)
def _new_question(self, post_it=False): """Post a new question and return the response.""" p = product(slug='mobile', save=True) t = topic(slug='fix-problems', product=p, save=True) url = urlparams(reverse('questions.aaq_step5', args=[p.slug, t.slug]), search='A test question') if post_it: return self.client.post(url, self.data, follow=True) return self.client.get(url, follow=True)
def _new_question(self, post_it=False): """Post a new question and return the response.""" p = product(slug='mobile', save=True) l = QuestionLocale.objects.get(locale=settings.LANGUAGE_CODE) p.questions_locales.add(l) t = topic(slug='fix-problems', product=p, save=True) url = urlparams(reverse('questions.aaq_step5', args=[p.slug, t.slug]), search='A test question') if post_it: return self.client.post(url, self.data, follow=True) return self.client.get(url, follow=True)
def test_search_suggestions_questions(self): """Verifies the view doesn't kick up an HTTP 500""" p = product(slug=u"firefox", save=True) topic(title="Fix problems", slug="fix-problems", product=p, save=True) q = question(title=u"CupcakesQuestion cupcakes", save=True) q.products.add(p) d = document(title=u"CupcakesKB cupcakes", category=10, save=True) d.products.add(p) revision(document=d, is_approved=True, save=True) self.refresh() url = urlparams(reverse("questions.aaq_step4", args=["desktop", "fix-problems"]), search="cupcakes") response = self.client.get(url, follow=True) eq_(200, response.status_code) assert "CupcakesQuestion" in response.content assert "CupcakesKB" in response.content
def _new_question(self, post_it=False): """Post a new question and return the response.""" p = product(slug='mobile', save=True) l = QuestionLocale.objects.get(locale=settings.LANGUAGE_CODE) p.questions_locales.add(l) t = topic(slug='fix-problems', product=p, save=True) url = urlparams( reverse('questions.aaq_step5', args=[p.slug, t.slug]), search='A test question') if post_it: return self.client.post(url, self.data, follow=True) return self.client.get(url, follow=True)
def test_question_topics(self): """Search questions for topics.""" t1 = old_topic(slug='doesnotexist', save=True) t2 = old_topic(slug='cookies', save=True) t3 = old_topic(slug='sync', save=True) # TODO: This is a hack until we move questions to new topics. # We need to create these for the search form validation. topic(slug='doesnotexist', save=True) topic(slug='cookies', save=True) topic(slug='sync', save=True) q = question(save=True) q.topics.add(t2) q = question(save=True) q.topics.add(t2) q.topics.add(t3) self.refresh() topic_vals = ( (t1.slug, 0), (t2.slug, 2), (t3.slug, 1), ([t2.slug, t3.slug], 1), ) qs = {'a': 1, 'w': 2, 'format': 'json'} for topics, number in topic_vals: qs.update({'topics': topics}) response = self.client.get(reverse('search'), qs) eq_(number, json.loads(response.content)['total'])
def test_question_topics(self): """Search questions for topics.""" t1 = old_topic(slug="doesnotexist", save=True) t2 = old_topic(slug="cookies", save=True) t3 = old_topic(slug="sync", save=True) # TODO: This is a hack until we move questions to new topics. # We need to create these for the search form validation. topic(slug="doesnotexist", save=True) topic(slug="cookies", save=True) topic(slug="sync", save=True) q = question(save=True) q.topics.add(t2) q = question(save=True) q.topics.add(t2) q.topics.add(t3) self.refresh() topic_vals = ((t1.slug, 0), (t2.slug, 2), (t3.slug, 1), ([t2.slug, t3.slug], 1)) qs = {"a": 1, "w": 2, "format": "json"} for topics, number in topic_vals: qs.update({"topics": topics}) response = self.client.get(reverse("search"), qs) eq_(number, json.loads(response.content)["total"])
def facets_setUp(self): # Create products self.desktop = product(slug='firefox', save=True) self.mobile = product(slug='mobile', save=True) # Create topics self.general_d = topic(product=self.desktop, slug='general', save=True) self.bookmarks_d = topic(product=self.desktop, slug='bookmarks', save=True) self.sync_d = topic(product=self.desktop, slug='sync', save=True) self.general_m = topic(product=self.mobile, slug='general', save=True) self.bookmarks_m = topic(product=self.mobile, slug='bookmarks', save=True) self.sync_m = topic(product=self.mobile, slug='sync', save=True) # Set up documents. doc1 = revision(is_approved=True, save=True).document doc1.topics.add(self.general_d) doc1.topics.add(self.bookmarks_d) doc1.products.add(self.desktop) doc2 = revision(is_approved=True, save=True).document doc2.topics.add(self.bookmarks_d) doc2.topics.add(self.bookmarks_m) doc2.topics.add(self.sync_d) doc2.topics.add(self.sync_m) doc2.products.add(self.desktop) doc2.products.add(self.mobile) # An archived article shouldn't show up doc3 = revision(is_approved=True, save=True).document doc3.is_archived = True doc3.save() doc3.topics.add(self.general_d) doc3.topics.add(self.bookmarks_d) doc3.products.add(self.desktop) # A template article shouldn't show up either doc4 = revision(is_approved=True, save=True).document doc4.category = 60 doc4.title = 'Template: Test' doc4.save() doc4.topics.add(self.general_d) doc4.topics.add(self.bookmarks_d) doc4.products.add(self.desktop) # An article without current revision should be "invisible" # to everything. doc5 = revision(is_approved=False, save=True).document doc5.topics.add(self.general_d) doc5.topics.add(self.general_m) doc5.topics.add(self.bookmarks_d) doc5.topics.add(self.bookmarks_m) doc5.topics.add(self.sync_d) doc5.topics.add(self.sync_m) doc5.products.add(self.desktop) doc5.products.add(self.mobile)
def facets_setUp(self): # Create products self.desktop = product(slug='firefox', save=True) self.mobile = product(slug='mobile', save=True) # Create topics self.general_d = topic( product=self.desktop, slug='general', save=True) self.bookmarks_d = topic( product=self.desktop, slug='bookmarks', save=True) self.sync_d = topic(product=self.desktop, slug='sync', save=True) self.general_m = topic( product=self.mobile, slug='general', save=True) self.bookmarks_m = topic( product=self.mobile, slug='bookmarks', save=True) self.sync_m = topic(product=self.mobile, slug='sync', save=True) # Set up documents. doc1 = revision(is_approved=True, save=True).document doc1.topics.add(self.general_d) doc1.topics.add(self.bookmarks_d) doc1.products.add(self.desktop) doc2 = revision(is_approved=True, save=True).document doc2.topics.add(self.bookmarks_d) doc2.topics.add(self.bookmarks_m) doc2.topics.add(self.sync_d) doc2.topics.add(self.sync_m) doc2.products.add(self.desktop) doc2.products.add(self.mobile) # An archived article shouldn't show up doc3 = revision(is_approved=True, save=True).document doc3.is_archived = True doc3.save() doc3.topics.add(self.general_d) doc3.topics.add(self.bookmarks_d) doc3.products.add(self.desktop) # A template article shouldn't show up either doc4 = revision(is_approved=True, save=True).document doc4.category = 60 doc4.title = 'Template: Test' doc4.save() doc4.topics.add(self.general_d) doc4.topics.add(self.bookmarks_d) doc4.products.add(self.desktop) # An article without current revision should be "invisible" # to everything. doc5 = revision(is_approved=False, save=True).document doc5.topics.add(self.general_d) doc5.topics.add(self.general_m) doc5.topics.add(self.bookmarks_d) doc5.topics.add(self.bookmarks_m) doc5.topics.add(self.sync_d) doc5.topics.add(self.sync_m) doc5.products.add(self.desktop) doc5.products.add(self.mobile)
def test_translations_get_parent_tags(self): doc1 = document(title=u'Audio too loud') doc1.save() revision(document=doc1, is_approved=True, save=True) doc1.topics.add(topic(slug='cookies', save=True)) doc1.topics.add(topic(slug='general', save=True)) doc1.products.add(product(slug='desktop', save=True)) doc2 = document(title=u'Audio too loud bork bork', parent=doc1) doc2.save() revision(document=doc2, is_approved=True, save=True) doc2.tags.add(u'badtag') # Verify the parent has the right tags. doc_dict = DocumentMappingType.extract_document(doc1.id) eq_(doc_dict['topic'], [u'cookies', u'general']) eq_(doc_dict['product'], [u'desktop']) # Verify the translation has the parent's tags. doc_dict = DocumentMappingType.extract_document(doc2.id) eq_(doc_dict['topic'], [u'cookies', u'general']) eq_(doc_dict['product'], [u'desktop'])
def setUp(self): u = user(save=True) add_permission(u, Question, 'change_question') self.user = u p = product(save=True) t = topic(product=p, save=True) q = question(product=p, topic=t, save=True) self.product = p self.topic = t self.question = q
def test_search_suggestions_questions(self): """Verifies the view doesn't kick up an HTTP 500""" p = product(slug=u'firefox', save=True) l = QuestionLocale.objects.get(locale=settings.LANGUAGE_CODE) p.questions_locales.add(l) topic(title='Fix problems', slug='fix-problems', product=p, save=True) q = question(product=p, title=u'CupcakesQuestion cupcakes', save=True) d = document(title=u'CupcakesKB cupcakes', category=10, save=True) d.products.add(p) revision(document=d, is_approved=True, save=True) self.refresh() url = urlparams( reverse('questions.aaq_step4', args=['desktop', 'fix-problems']), search='cupcakes') response = self.client.get(url, follow=True) eq_(200, response.status_code) assert 'CupcakesQuestion' in response.content assert 'CupcakesKB' in response.content # Verify that archived articles and questions aren't shown... # Archive both and they shouldn't appear anymore. q.is_archived = True q.save() d.is_archived = True d.save() self.refresh() response = self.client.get(url, follow=True) eq_(200, response.status_code) assert 'CupcakesQuestion' not in response.content assert 'CupcakesKB' not in response.content
def test_index_generation(self): p = product(title='firefox', save=True) t = topic(title='topic1', product=p, save=True) doc = document(title='firefox bookmarks', locale='en-US', save=True) revision(is_approved=True, summary='this is an article about firefox bookmarks', document=doc, save=True) doc.products.add(p) doc.topics.add(t) doc2 = document(title='private browsing', locale='en-US', save=True) revision(is_approved=True, summary='this is an article about private browsing', document=doc2, save=True) doc2.products.add(p) doc2.topics.add(t) bundle = utils.bundle_for_product(p, 'en-US') index = bundle['indexes']['en-US~firefox']['index'] words_in_both = ('this', 'is', 'an', 'article', 'about') for word in words_in_both: assert word in index eq_(2, len(index[word])) eq_(2, len(index[word][0])) eq_(2, len(index[word][1])) assert 'firefox' in index eq_(1, len(index['firefox'])) # Yeah. 'firefox' in this corpus _better_ score higher than 'this'. assert index['firefox'][0][1] > index['this'][0][1] assert 'bookmarks' in index eq_(1, len(index['bookmarks'])) assert index['bookmarks'][0][1] > index['this'][0][1] assert 'private' in index eq_(1, len(index['private'])) assert index['private'][0][1] > index['this'][0][1] assert 'browsing' in index eq_(1, len(index['browsing'])) assert index['browsing'][0][1] > index['this'][0][1]
def test_question_feed_with_product_and_topic(self): """Test that questions feeds with products and topics work.""" p = product(save=True) t = topic(product=p, save=True) url = urlparams(reverse('questions.list', args=[p.slug]), topic=t.slug) res = self.client.get(url) doc = pq(res.content) feed_links = doc('link[type="application/atom+xml"]') feed = feed_links[0] eq_(1, len(feed_links)) eq_('Recently updated questions', feed.attrib['title']) eq_(urlparams('/en-US/questions/feed', product=p.slug, topic=t.slug), feed.attrib['href'])
def test_search_suggestions_questions(self): """Verifies the view doesn't kick up an HTTP 500""" p = product(slug=u'firefox', save=True) topic(title='Fix problems', slug='fix-problems', product=p, save=True) q = question(title=u'CupcakesQuestion cupcakes', save=True) q.products.add(p) d = document(title=u'CupcakesKB cupcakes', category=10, save=True) d.products.add(p) revision(document=d, is_approved=True, save=True) self.refresh() url = urlparams( reverse('questions.aaq_step4', args=['desktop', 'fix-problems']), search='cupcakes') response = self.client.get(url, follow=True) eq_(200, response.status_code) assert 'CupcakesQuestion' in response.content assert 'CupcakesKB' in response.content
def setUp(self): u = user(save=True) add_permission(u, Question, 'change_question') self.user = u p = product(save=True) t = topic(product=p, save=True) q = question(save=True) q.products.add(p) q.topics.add(t) q.save() self.question = q
def test_wiki_topics_inherit(self): """Translations inherit topics from their parents.""" doc = document(locale=u'en-US', category=10, save=True) doc.topics.add(topic(slug='extant', save=True)) revision(document=doc, is_approved=True, save=True) translated = document(locale=u'es', parent=doc, category=10, save=True) revision(document=translated, is_approved=True, save=True) self.refresh() qs = {'a': 1, 'w': 1, 'format': 'json', 'topics': 'extant'} response = self.client.get(reverse('search', locale='es'), qs) eq_(1, json.loads(response.content)['total'])
def new_document_data(topic_ids=None, product_ids=None): product_ids = product_ids or [product(save=True).id] p = Product.objects.get(id=product_ids[0]) topic_ids = topic_ids or [topic(product=p, save=True).id] return { 'title': 'A Test Article', 'slug': 'a-test-article', 'locale': 'en-US', 'topics': topic_ids, 'products': product_ids, 'category': CATEGORIES[0][0], 'keywords': 'key1, key2', 'summary': 'lipsum', 'content': 'lorem ipsum dolor sit amet', }
def test_subtopics(self): """Verifies subtopics appear on document listing page.""" # Create a topic and product. p = product(save=True) t = topic(product=p, save=True) # Create a documents with the topic and product doc = revision(is_approved=True, save=True).document doc.topics.add(t) doc.products.add(p) self.refresh() # GET the page and verify no subtopics yet. url = reverse('products.documents', args=[p.slug, t.slug]) r = self.client.get(url, follow=True) eq_(200, r.status_code) pqdoc = pq(r.content) eq_(0, len(pqdoc('li.subtopic'))) # Create a subtopic, it still shouldn't show up because no # articles are assigned. subtopic = topic(parent=t, product=p, save=True) r = self.client.get(url, follow=True) eq_(200, r.status_code) pqdoc = pq(r.content) eq_(0, len(pqdoc('li.subtopic'))) # Add a document to the subtopic, now it should appear. doc.topics.add(subtopic) self.refresh() r = self.client.get(url, follow=True) eq_(200, r.status_code) pqdoc = pq(r.content) eq_(1, len(pqdoc('li.subtopic')))