'Tests advanced search with a sortby_documents by helpful'

def test_sortby_documents_helpful(self):

    r1 = RevisionFactory(is_approved=True)
    r2 = RevisionFactory(is_approved=True)
    HelpfulVoteFactory(revision=r2, 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_(r2.document.title, content['results'][0]['title'])
    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'])
