def test_complex_query(self): """ Tests the factor_query method for an API that doens't accept phrases and for which the query exceeds the search term limit. """ terms = SearchTerm.objects.filter(pk__in=[1, 2, 3]) # 6 terms when parsed accounts = Account.objects.filter(pk__in=[1, 2]) locations = Location.objects.filter(pk=2) query = ReservoirQuery(searchterms=list(terms), accounts=list(accounts), locations=list(locations), trm_loc_logic='AND') specs = PipeSpecSheet(searchterms_limit=10, followees_limit=1, accepts_phrases=False, combine_trm_fol=True, combine_trm_opr=True, trm_trm_logic='AND', trm_fol_logic='AND', trm_loc_logic='AND', OR_operator='OR', location_format='radius', radius_limit_km=0.1) engineer = Engineer(query=query, specs=specs) queries = engineer.factor_query() self.assertEqual(len(queries), 4)
def _factor_query(self, query): """ Takes a ReservoirQuery and returns it as a list of one or more ReservoirQueries formatted for the Pump's Pipe. """ engineer = Engineer(query=query, specs=self._specsheet) return engineer.factor_query()
def test_for_small_circle(self): """ Tests the factor_query method for a circular location smaller than the radius limit. """ locations = Location.objects.filter(pk=2) query = ReservoirQuery(locations=locations) specs = PipeSpecSheet(location_format='radius', radius_limit_km=1) engineer = Engineer(query=query, specs=specs) queries = engineer.factor_query() self.assertTrue(len(queries[0].locations) == 1)