def setUp(self): app = Flask(__name__, template_folder=os.path.dirname(__file__)) app.debug = True app.config['TESTING'] = True app.config['SOLRQUERY_URL'] = 'http://httpbin.org/get' self.solr = FlaskSolrQuery(app) self.app = app
class FlaskSolrTestCase(fixtures.TestWithFixtures, unittest.TestCase): def setUp(self): app = Flask(__name__, template_folder=os.path.dirname(__file__)) app.debug = True app.config['TESTING'] = True app.config['SOLRQUERY_URL'] = 'http://httpbin.org/get' self.solr = FlaskSolrQuery(app) self.app = app def tearDown(self): self.solr = None self.app = None def test_00_query(self): with fake_solr_http_response(): req = self.solr.create_request("black holes") req = self.solr.set_defaults(req) resp = self.solr.get_response(req) self.assertEqual(resp.get_hits(), 13) def test_01_reqest_context(self): with self.app.test_request_context('/'): with fake_solr_http_response(): resp = solr.query(**{'q': "black holes"}) self.assertEqual(resp.get_hits(), 13) def test_02_solr_request_http_method(self): req = SearchRequest("foo") prepared = req.prepare("http://example.com/select") self.assertEqual(prepared.method, 'GET') prepared = req.prepare("http://example.com/select", method='POST') self.assertEqual(prepared.method, 'POST') with self.app.test_request_context(): solr.request_http_method = 'POST' with fake_solr_http_response(): resp = solr.query(**{'q': "black holes"}) self.assertEqual(resp.request.prepared.method, 'POST') solr.request_http_method = 'GET'