Пример #1
0
 def test_fulltext_search(self):
     committee = factories.CommitteeFactory(
         name='Americans for a Better Tomorrow, Tomorrow')
     decoy_committee = factories.CommitteeFactory()
     factories.CommitteeSearchFactory(
         id=committee.committee_id,
         fulltxt=sa.func.to_tsvector(committee.name),
     )
     results = self._results(api.url_for(CommitteeList, q='america'))
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0]['committee_id'], committee.committee_id)
     self.assertNotEqual(results[0]['committee_id'],
                         decoy_committee.committee_id)
Пример #2
0
 def test_typeahead_committee_search(self):
     rows = [
         factories.CommitteeSearchFactory(
             name='Bartlet {0}'.format(idx),
             fulltxt=sa.func.to_tsvector(
                 'Bartlet for America {0}'.format(idx)),
             receipts=idx,
         ) for idx in range(30)
     ]
     rest.db.session.flush()
     results = self._results(api.url_for(CommitteeNameSearch, q='bartlet'))
     expected = [str(each.id) for each in rows[:-21:-1]]
     observed = [each['id'] for each in results]
     assert expected == observed
     assert all('bartlet' in each['name'].lower() for each in results)
Пример #3
0
 def test_typeahead_committee_search(self):
     [
         factories.CommitteeSearchFactory(
             name='Bartlet {0}'.format(idx),
             fulltxt=sa.func.to_tsvector('Bartlet for America {0}'.format(idx)),
         )
         for idx in range(30)
     ]
     rest.db.session.flush()
     results = self._results(api.url_for(CommitteeNameSearch, q='bartlet'))
     self.assertEqual(len(results), 20)
     ids = [r['id'] for r in results if r['id']]
     self.assertEqual(len(ids), len(set(ids)))
     for each in results:
         self.assertIn('bartlet', each['name'].lower())
Пример #4
0
 def test_fulltext_search(self):
     committee = factories.CommitteeFactory(
         name='Americans for a Better Tomorrow, Tomorrow')
     decoy_committee = factories.CommitteeFactory()
     factories.CommitteeSearchFactory(
         id=committee.committee_id,
         fulltxt=sa.func.to_tsvector(committee.name),
         is_active=True,
     )
     queries = [
         'america',
         'tomorrow',
         'america tomorrow',
         'america & tomorrow',
     ]
     for query in queries:
         results = self._results(api.url_for(CommitteeList, q=query))
         self.assertEqual(len(results), 1)
         self.assertEqual(results[0]['committee_id'],
                          committee.committee_id)
         self.assertNotEqual(results[0]['committee_id'],
                             decoy_committee.committee_id)