def _create_query_2_excluded_terms(): """ Helper method that returns a ReservoirQuery with two excluded terms. """ term1 = SearchTerm(term='cops', negate=True) term2 = SearchTerm(term='robbers', negate=True) terms = [term1, term2] return ReservoirQuery(searchterms=terms)
def test_for_duplicate_term(self): """ Tests the add_searchterm method for a duplicate term. """ terms = [SearchTerm(term='police'), SearchTerm(term='car')] query = ReservoirQuery(searchterms=terms) query.add_searchterm(SearchTerm(term='police')) self.assertEqual(len(query.searchterms), 2)
def test_format_searchterms_param(self): """ Tests the _format_searchterms_param method. """ searchterms = [SearchTerm(term='photos'), SearchTerm(term='social media')] actual = self.stream_handler._format_searchterms_param(searchterms) expected = ['photos', '"social media"'] self.assertEqual(actual, expected)
def test_dup_terms(self): """ Tests the _handle_phrases method for terms with duplicate words. """ terms = [SearchTerm(term='police'), SearchTerm(term='police officer')] query = ReservoirQuery(searchterms=terms) specs = PipeSpecSheet(accepts_phrases=False) engineer = Engineer(query=query, specs=specs) engineer._handle_phrases() searchterms = engineer.get_searchterms() self.assertEqual(len(searchterms), 3)
def test_for_mixed_terms(self): """ Tests the transform_phrases method for a mix of phrases and non-phrases. """ terms = [SearchTerm(term='robbery'), SearchTerm(term='police car')] query = ReservoirQuery(searchterms=terms) query.wrap_phrases_in_quotes() self.assertEqual(len(query.searchterms), 2) self.assertEqual(query.searchterms[0].term, 'robbery') self.assertEqual(query.searchterms[1].term, '"police car"')
def test_for_negation_not_allowed(self): """ Tests the _handle_negation method for an API that doesn't allow negation of search terms. """ terms = [SearchTerm(term='police'), SearchTerm(term='car', negate=True)] query = ReservoirQuery(searchterms=terms) engineer = Engineer(query=query, specs=PipeSpecSheet()) engineer._handle_negation() searchterms = engineer.get_searchterms() self.assertEqual(len(searchterms), 1)
def _create_test_query(self): """ Helper method that returns an example ReservoirQuery. """ accounts = [Account(username='******')] locations = [ Location(geom=Point(-76.6653729, 39.4904058), buffer_m=1000) ] searchterms = [SearchTerm(term='photos'), SearchTerm(term='media')] timeframe = self._create_example_timeframe() return ReservoirQuery(accounts=accounts, locations=locations, searchterms=searchterms, timeframe=timeframe)
def test_for_accepts_phrases(self): """ Tests the _handle_phrases method for an API that accepts phrases. """ terms = [SearchTerm(term='police officer')] query = ReservoirQuery(searchterms=terms) specs = PipeSpecSheet(accepts_phrases=True) engineer = Engineer(query=query, specs=specs) engineer._handle_phrases() searchterms = engineer.get_searchterms() self.assertEqual(len(searchterms), 1) self.assertEqual(searchterms[0].term, 'police officer')
def _create_terms_by_type(self, keywords, negate=False): """ Takes a string of comma-separated or space-separated keywords/phrases and a Boolean indicating whether they should be negated in a text search. Returns a list of SearchTerm objects. """ keyword_array = self._parse_keywords(keywords) searchterms = [] for keyword in keyword_array: cleaned_keyword = keyword.strip() cleaned_keyword = cleaned_keyword.replace('"', '') if cleaned_keyword != '': term = SearchTerm(term=cleaned_keyword, negate=negate) searchterms.append(term) return searchterms