예제 #1
0
 def test_typeahead_candidate_search_id(self):
     row = factories.CandidateSearchFactory(
         name='Bartlet', fulltxt=sa.func.to_tsvector('Bartlet P0123'),
     )
     decoy = factories.CandidateSearchFactory()  # noqa
     rest.db.session.flush()
     results = self._results(api.url_for(CandidateNameSearch, q='P0123'))
     assert len(results) == 1
     assert results[0]['name'] == row.name
 def test_fulltext_match(self):
     danielle = factories.CandidateFactory(name='Danielle')
     factories.CandidateSearchFactory(id=danielle.candidate_id, fulltxt=sa.func.to_tsvector('Danielle'))
     dana = factories.CandidateFactory(name='Dana')
     factories.CandidateSearchFactory(id=dana.candidate_id, fulltxt=sa.func.to_tsvector('Dana'))
     rest.db.session.flush()
     results = self._results(api.url_for(CandidateList, q='danielle'))
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0]['candidate_id'], danielle.candidate_id)
     results = self._results(api.url_for(CandidateList, q='dan'))
     self.assertEqual(len(results), 2)
     self.assertEqual(
         set(each['candidate_id'] for each in results),
         {danielle.candidate_id, dana.candidate_id},
     )
예제 #3
0
 def test_full_text_search_with_whitespace(self):
     candidate = factories.CandidateFactory(name='Josiah Bartlet')
     factories.CandidateSearchFactory(
         id=candidate.candidate_id, fulltxt=sa.func.to_tsvector('Josiah Bartlet'),
     )
     rest.db.session.flush()
     results = self._results(api.url_for(CandidateList, q='bartlet josiah'))
     self.assertEqual(len(results), 1)
     self.assertIn('josiah', results[0]['name'].lower())
예제 #4
0
파일: test_api.py 프로젝트: mbland/openFEC
 def test_typeahead_candidate_search(self):
     [
         factories.CandidateSearchFactory(
             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(CandidateNameSearch, 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())
예제 #5
0
파일: test_api.py 프로젝트: nbedi/openFEC
 def test_typeahead_candidate_search(self):
     rows = [
         factories.CandidateSearchFactory(
             name='Bartlet {0}'.format(idx),
             fulltxt=sa.func.to_tsvector(
                 'Bartlet for America {0}'.format(idx)),
             office_sought='P',
             receipts=idx,
         ) for idx in range(30)
     ]
     rest.db.session.flush()
     results = self._results(api.url_for(CandidateNameSearch, 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)
     assert all(each['office_sought'] == 'P' for each in results)