def check(self, database, search_term, expected_matches=(), limit=None): if expected_matches and limit: raise ValueError("Bad test - TogoWS makes no promises about order") search_count = TogoWS.search_count(database, search_term) if expected_matches and search_count < len(expected_matches): raise ValueError("Only %i matches, expected at least %i" % (search_count, len(expected_matches))) if search_count > 5000 and not limit: print("%i results, skipping" % search_count) return if limit: count = min(search_count, limit) else: count = search_count # Iteration should find everything... unless a limit is used search_iter = list(TogoWS.search_iter(database, search_term, limit)) self.assertEqual(count, len(search_iter)) for match in expected_matches: self.assertTrue(match in search_iter, "Expected %s in results but not" % match)
def check(self, database, search_term, expected_matches=[], limit=None): if expected_matches and limit: raise ValueError("Bad test - TogoWS makes no promises about order") search_count = TogoWS.search_count(database, search_term) if expected_matches and search_count < len(expected_matches): raise ValueError("Only %i matches, expected at least %i" \ % (search_count, len(expected_matches))) if search_count > 5000 and not limit: print "%i results, skipping" % search_count return if limit: count = min(search_count, limit) else: count = search_count #Iteration should find everything... unless a limit is used search_iter = list(TogoWS.search_iter(database, search_term, limit)) self.assertEqual(count, len(search_iter)) for match in expected_matches: self.assert_(match in search_iter, "Expected %s in results but not" % match)
def check(self, database, search_term, expected_matches=(), limit=None): if expected_matches and limit: raise ValueError("Bad test - TogoWS makes no promises about order") try: search_count = TogoWS.search_count(database, search_term) except HTTPError as err: raise ValueError("%s from %s" % (err, err.url)) from None if expected_matches: self.assertGreaterEqual(search_count, len(expected_matches)) if search_count > 5000 and not limit: print("%i results, skipping" % search_count) return if limit: count = min(search_count, limit) else: count = search_count # Iteration should find everything... unless a limit is used search_iter = list(TogoWS.search_iter(database, search_term, limit)) self.assertEqual(count, len(search_iter)) for match in expected_matches: self.assertIn(match, search_iter, "Expected %s in results" % match)