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_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_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 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 _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_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_(5, len(doc('#products-and-services 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_(5, len(doc('#products-and-services li')))
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_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_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_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_(QuestionMappingType.search().filter(topic=t.slug).count(), 0) q = question(save=True) self.refresh() eq_(QuestionMappingType.search().filter(topic=t.slug).count(), 0) q.topics.add(t) self.refresh() eq_(QuestionMappingType.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_(QuestionMappingType.search().filter().count(), 1) eq_(QuestionMappingType.search().filter(topic=t.slug).count(), 0)