def test_question_topics(self): """Search questions for topics.""" t1 = topic(slug='doesnotexist', save=True) t2 = topic(slug='cookies', save=True) t3 = 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_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_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) topic(title='Fix problems', slug='fix-problems', save=True) p = product(slug=u'firefox', 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_LOCALES, so should be filtered. sub_test('en-US', 'cupcakes?', 'donuts?') sub_test('pt-BR', 'pies?') # de is not in AAQ_LOCALES, so should show en-US, but not pt-BR sub_test('de', 'cupcakes?', 'donuts?', 'pastries?')
def test_product_landing(self, flag_is_active): """Verify that /products/<slug> page renders topics.""" flag_is_active.return_value = True # Create a product. p = product(save=True) # Create some topics. topic(slug=HOT_TOPIC_SLUG, save=True) topics = [] for i in range(11): topics.append(topic(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_(10, len(doc('#help-topics li')))
def test_search_suggestions(self): """Verifies the view doesn't kick up an HTTP 500""" topic(title='Fix problems', slug='fix-problems', save=True) q = question(title=u'CupcakesQuestion cupcakes', save=True) q.tags.add(u'desktop') q.save() d = document(title=u'CupcakesKB cupcakes', category=10, save=True) d.products.add(product(slug=u'firefox', save=True)) d.save() rev = 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 test_search_suggestion_questions_locale(self): """Verifies the right languages show up in search suggestions.""" topic(title='Fix problems', slug='fix-problems', save=True) p = product(slug=u'firefox', 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.""" topic(title='Fix problems', slug='fix-problems', save=True) p = product(slug=u'firefox', 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_subtopics(self): """Verifies subtopics appear on document listing page.""" # Create a topic and product. t = topic(save=True) p = product(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) doc = pq(r.content) eq_(0, len(doc('ul.subtopics'))) # Create a subtopic and verify it is listed topic(parent=t, save=True) 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_(1, len(doc('ul.subtopics')))
def test_search_suggestion_question_age(self): """Verifies the view doesn't return old questions.""" topic(title='Fix problems', slug='fix-problems', save=True) p = product(slug=u'firefox', 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_document_listing(self, flag_is_active): """Verify /products/<product slug>/<topic slug> renders articles.""" flag_is_active.return_value = True # Create a topic and product. t1 = topic(save=True) t2 = topic(save=True) p = product(save=True) # Create 3 documents with the topic and product and one without. for i in range(3): doc = revision(is_approved=True, save=True).document doc.topics.add(t1) doc.products.add(p) if i == 1: # Only one document with t2 doc.topics.add(t2) doc = revision(is_approved=True, save=True).document 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'))) # GET the page with refine topic and verify the content. url = reverse('products.documents', args=[p.slug, t1.slug]) url = urlparams(url, refine=t2.slug) r = self.client.get(url, follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_(1, len(doc('#document-list > ul > li')))
def test_search_suggestions_archived_articles(self): """Verifies that archived articles aren't shown.""" topic(title='Fix problems', slug='fix-problems', save=True) p = product(slug=u'firefox', 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 setUp(self): super(TestFacetHelpers, self).setUp() # Create topics self.general = topic(slug='general', save=True) self.bookmarks = topic(slug='bookmarks', save=True) self.sync = topic(slug='sync', save=True) # Create products self.desktop = product(slug='firefox', save=True) self.mobile = product(slug='mobile', save=True) # Set up documents. doc1 = revision(is_approved=True, save=True).document doc1.topics.add(self.general) doc1.topics.add(self.bookmarks) doc1.products.add(self.desktop) doc2 = revision(is_approved=True, save=True).document doc2.topics.add(self.bookmarks) doc2.topics.add(self.sync) doc2.products.add(self.desktop) doc2.products.add(self.mobile) self.refresh()
def test_search_suggestion_questions_locale(self): """Verifies the right languages show up in search suggestions.""" topic(title="Fix problems", slug="fix-problems", save=True) p = product(slug=u"firefox", 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_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) topic(title="Fix problems", slug="fix-problems", save=True) p = product(slug=u"firefox", 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_LOCALES, so should be filtered. sub_test("en-US", "cupcakes?", "donuts?") sub_test("pt-BR", "pies?") # de is not in AAQ_LOCALES, so should show en-US, but not pt-BR sub_test("de", "cupcakes?", "donuts?", "pastries?")
def _new_question(self, post_it=False): """Post a new question and return the response.""" topic(title="Fix problems", slug="fix-problems", save=True) url = urlparams(reverse("questions.aaq_step5", args=["desktop", "fix-problems"]), 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_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' } topic(title='Fix problems', slug='fix-problems', 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.""" topic(title='Fix problems', slug='fix-problems', save=True) p = product(slug=u'firefox', 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 _new_question(self, post_it=False): """Post a new question and return the response.""" topic(title='Fix problems', slug='fix-problems', save=True) url = urlparams( reverse('questions.aaq_step5', args=['desktop', 'fix-problems']), 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.""" topic(title='Fix problems', slug='fix-problems', save=True) url = urlparams(reverse('questions.aaq_step5', args=['desktop', 'fix-problems']), 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_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. l10n = document(parent=en_us, save=True) eq_(2, len(en_us.get_topics()))
def test_topic_select_product(self, flag_is_active): """Verify that /topics/<slug>?selectproduct=1 renders products.""" flag_is_active.return_value = True # Create a topic t = topic(save=True) # Create 3 products prods = [] for i in range(3): prods.append(product(save=True)) # Create a document and assign the topic and two products. doc = revision(is_approved=True, save=True).document doc.topics.add(t) doc.products.add(prods[0]) doc.products.add(prods[1]) self.refresh() # GET the topic page and verify the content url = reverse('topics.topic', args=[t.slug]) url = urlparams(url, selectproduct=1) r = self.client.get(url, follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_(2, len(doc('#products-and-services li')))
def test_hot_topics(self, flag_is_active): """Verifies the hot topics section.""" flag_is_active.return_value = True # Create a product and the hot topics topic. p = product(save=True) hot = topic(slug=HOT_TOPIC_SLUG, save=True) # Create 7 hot documents. for i in range(7): doc = revision(is_approved=True, save=True).document doc.products.add(p) doc.topics.add(hot) # Create a not hot document. doc = revision(is_approved=True, save=True).document doc.products.add(p) 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_(7, len(doc('#hot-topics li')))
def test_home(self): """Verify that home page renders topics and products.""" # Create some topics and products topic(slug=HOT_TOPIC_SLUG, save=True) for i in range(6): topic(save=True) for i in range(4): product(save=True) # GET the home page and verify the content r = self.client.get(reverse('home'), follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_(6, len(doc('#help-topics li'))) eq_(5, len(doc('#products-and-services li')))
def test_home(self, flag_is_active): """Verify that home page renders topics and products.""" flag_is_active.return_value = True # Create some topics and products for i in range(6): topic(save=True) for i in range(4): product(save=True) # GET the home page and verify the content r = self.client.get(reverse('home'), follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_(6, len(doc('#help-topics li'))) eq_(4, len(doc('#products-and-services li')))
def test_document_listing(self, flag_is_active): """Verify /products/<product slug>/<topic slug> renders articles.""" flag_is_active.return_value = True # Create a topic and product. t1 = topic(save=True) p = product(save=True) # Create 3 documents with the topic and product and one without. for i in range(3): doc = revision(is_approved=True, save=True).document doc.topics.add(t1) doc.products.add(p) doc = revision(is_approved=True, save=True).document 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 facets_setUp(self): # Create topics self.general = topic(slug='general', save=True) self.bookmarks = topic(slug='bookmarks', save=True) self.sync = topic(slug='sync', save=True) # Create products self.desktop = product(slug='firefox', save=True) self.mobile = product(slug='mobile', save=True) # Set up documents. doc1 = revision(is_approved=True, save=True).document doc1.topics.add(self.general) doc1.topics.add(self.bookmarks) doc1.products.add(self.desktop) doc2 = revision(is_approved=True, save=True).document doc2.topics.add(self.bookmarks) doc2.topics.add(self.sync) 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) doc3.topics.add(self.bookmarks) 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) doc4.topics.add(self.bookmarks) 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) doc5.topics.add(self.bookmarks) doc5.topics.add(self.sync) doc5.products.add(self.desktop) doc5.products.add(self.mobile)
def facets_setUp(self): # Create topics self.general = topic(slug='general', save=True) self.bookmarks = topic(slug='bookmarks', save=True) self.sync = topic(slug='sync', save=True) # Create products self.desktop = product(slug='firefox', save=True) self.mobile = product(slug='mobile', save=True) # Set up documents. doc1 = revision(is_approved=True, save=True).document doc1.topics.add(self.general) doc1.topics.add(self.bookmarks) doc1.products.add(self.desktop) doc2 = revision(is_approved=True, save=True).document doc2.topics.add(self.bookmarks) doc2.topics.add(self.sync) doc2.products.add(self.desktop) doc2.products.add(self.mobile)
def test_search_suggestions_questions(self): """Verifies the view doesn't kick up an HTTP 500""" topic(title="Fix problems", slug="fix-problems", save=True) p = product(slug=u"firefox", 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) rev = 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 test_question_topics(self): """Search questions for topics.""" t1 = topic(slug="doesnotexist", save=True) t2 = topic(slug="cookies", save=True) t3 = 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 new_document_data(topic_ids=None, product_ids=None): return { 'title': 'A Test Article', 'slug': 'a-test-article', 'locale': 'en-US', 'topics': topic_ids or [topic(save=True).id], 'products': product_ids or [product(save=True).id], 'category': CATEGORIES[0][0], 'keywords': 'key1, key2', 'summary': 'lipsum', 'content': 'lorem ipsum dolor sit amet', }
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 = Document.extract_document(doc1.id) eq_(doc_dict['document_topic'], [u'cookies', u'general']) eq_(doc_dict['document_product'], [u'desktop']) # Verify the translation has the parent's tags. doc_dict = Document.extract_document(doc2.id) eq_(doc_dict['document_topic'], [u'cookies', u'general']) eq_(doc_dict['document_product'], [u'desktop'])
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 = Document.extract_document(doc1.id) eq_(doc_dict["document_topic"], [u"cookies", u"general"]) eq_(doc_dict["document_product"], [u"desktop"]) # Verify the translation has the parent's tags. doc_dict = Document.extract_document(doc2.id) eq_(doc_dict["document_topic"], [u"cookies", u"general"]) eq_(doc_dict["document_product"], [u"desktop"])
def test_search_suggestions_questions(self): """Verifies the view doesn't kick up an HTTP 500""" topic(title='Fix problems', slug='fix-problems', save=True) p = product(slug=u'firefox', 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) rev = 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 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 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 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 = Document.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 = Document.extract_document(doc2.id) eq_(doc_dict['topic'], [u'cookies', u'general']) eq_(doc_dict['product'], [u'desktop'])
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_stats(self): """Tests questions/stats view""" t = topic(title='Websites', slug='websites', save=True) q = question(title=u'cupcakes', content=u'Cupcakes rock!', created=datetime.now() - timedelta(days=1), save=True) q.topics.add(t) q.save() self.refresh() response = self.client.get(reverse('questions.stats')) eq_(200, response.status_code) # If there's histogram data, this is probably good enough to # denote its existence. assert ' data-graph="[' in response.content
def test_hot_topics(self): """Verifies the hot topics section.""" # Create the hot topics topic. hot = topic(slug=HOT_TOPIC_SLUG, save=True) # Create 3 hot documents. for i in range(3): doc = revision(is_approved=True, save=True).document doc.topics.add(hot) # Create a not hot document. doc = revision(is_approved=True, save=True).document self.refresh() # GET the home page and verify the content r = self.client.get(reverse('home'), follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_(3, len(doc('#hot-topics li')))
def test_topic_document_listing(self, flag_is_active): """Verify that /topics/<slug> renders articles.""" flag_is_active.return_value = True # Create a topic t = topic(save=True) # Create 3 documents with the topic and one without for i in range(3): doc = revision(is_approved=True, save=True).document doc.topics.add(t) doc = revision(is_approved=True, save=True).document self.refresh() # GET the topic page and verify the content url = reverse('topics.topic', args=[t.slug]) r = self.client.get(url, follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_(3, len(doc('#document-list li')))
def test_question_topics(self): """Make sure that adding topics to a Question causes it to refresh the index. """ t = topic(slug=u'hiphop', save=True) eq_(Question.search().filter(topic=t.slug).count(), 0) q = question(save=True) self.refresh() eq_(Question.search().filter(topic=t.slug).count(), 0) q.topics.add(t) self.refresh() eq_(Question.search().filter(topic=t.slug).count(), 1) q.topics.clear() self.refresh() # Make sure the question itself is still there and that we didn't # accidentally delete it through screwed up signal handling: eq_(Question.search().filter().count(), 1) eq_(Question.search().filter(topic=t.slug).count(), 0)
def test_wiki_topics(self): """Make sure that adding topics to a Document causes it to refresh the index. """ t = topic(slug=u'hiphop', save=True) eq_(Document.search().filter(document_topic=t.slug).count(), 0) doc = document(save=True) revision(document=doc, is_approved=True, save=True) self.refresh() eq_(Document.search().filter(document_topic=t.slug).count(), 0) doc.topics.add(t) self.refresh() eq_(Document.search().filter(document_topic=t.slug).count(), 1) doc.topics.clear() self.refresh() # Make sure the document itself is still there and that we didn't # accidentally delete it through screwed up signal handling: eq_(Document.search().filter().count(), 1) eq_(Document.search().filter(document_topic=t.slug).count(), 0)
def test_document_listing_order(self, flag_is_active): """Verify documents are listed in order of helpful votes.""" flag_is_active.return_value = True # Create topic, product and documents. t = topic(save=True) p = product(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 li:first').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 li:first').text(), docs[2].title)
def generate_sampledata(options): # Create the top 10 topics used topic(title='Learn the Basics: get started', slug='get-started', save=True) topic(title='Download, install and migration', slug='download-and-install', save=True) topic(title='Privacy and security settings', slug='privacy-and-security', save=True) topic(title='Customize controls, options and add-ons', slug='customize', save=True) topic(title='Fix slowness, crashing, error messages and other problems', slug='fix-problems', save=True) topic(title='Tips and tricks', slug='tips', save=True) topic(title='Bookmarks', slug='bookmarks', save=True) topic(title='Cookies', slug='cookies', save=True) topic(title='Tabs', slug='tabs', save=True) topic(title='Websites', slug='websites', save=True) # 'hot' topic is created by a migration. Check for it's existence # before creating a new one. if not Topic.objects.filter(slug='hot').exists(): topic(title='Hot topics', slug='hot', save=True) # 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 Mobile', description='Web browser for Android smartphones and tablets', display_order=2, visible=True, slug='mobile') mobile.save() # Create the special documents that are linked to from the home page moznews = document(title='Mozilla News', slug='mozilla-news', save=True) revision(content=MOZILLA_NEWS_CONTENT, document=moznews, is_approved=True, reviewed=datetime.now(), save=True) suggestion = document(title='Suggestion Box', slug='suggestion-box', save=True) revision(content=SUGGESTION_BOX_CONTENT, document=suggestion, is_approved=True, reviewed=datetime.now(), save=True) community = document(title='Get community support', slug='get-community-support', save=True) revision(content=COMMUNITY_CONTENT, document=community, is_approved=True, reviewed=datetime.now(), save=True) # Create a hot article flash = document(title='Flash 11.3 crashes', slug='flash-113-crashes', save=True) revision(content=FLASH_CONTENT, document=flash, is_approved=True, reviewed=datetime.now(), save=True) flash.products.add(firefox) flash.topics.add(Topic.objects.get(slug='fix-problems')) flash.topics.add(Topic.objects.get(slug='hot')) # Generate 9 sample documents with 2 topics each topics = list(Topic.objects.all()) for i in xrange(9): d = document(title='Sample Article %s' % str(i + 1), slug='sample-article-%s' % str(i + 1), save=True) revision(document=d, is_approved=True, reviewed=datetime.now(), save=True) d.products.add(firefox) d.products.add(mobile) d.topics.add(topics[i]) d.topics.add(topics[i + 1])