Beispiel #1
0
 def test_no_accounts(self):
     """
     Tests the _handle_combined_trm_fol_limit method for a query that doesn't
     include any accounts.
     """
     terms = SearchTerm.objects.all()  # exceeds search terms limit
     query = ReservoirQuery(searchterms=terms)
     specs = PipeSpecSheet.objects.get(pipe=1)  # Twitter Search API
     engineer = Engineer(query=query, specs=specs)
     queries = engineer._handle_combined_trm_fol_limit([query])
     self.assertEqual(len(queries), 1)
Beispiel #2
0
 def test_and_specs_and_query(self):
     """
     Tests the _separate_components method for a query that joins SearchTerms
     and Locations with AND logic, with an API that can't join SearchTerms
     and Accounts using OR logic.
     """
     self.query.trm_loc_logic = 'AND'
     specs = PipeSpecSheet.objects.get(pipe=5)  # YouTube Data API
     engineer = Engineer(query=self.query, specs=specs)
     queries = engineer._separate_components()
     self.assertEqual(len(queries), 2)
Beispiel #3
0
 def test_no_limits_exceeded(self):
     """
     Tests the _factor_components method for a query that doesn't exceed any
     API limits on number of arguments.
     """
     specs = PipeSpecSheet(searchterms_limit=10,
                           locations_limit=10,
                           followees_limit=10)
     engineer = Engineer(query=self.query, specs=specs)
     queries = engineer._factor_components([self.query])
     self.assertEqual(len(queries), 1)
Beispiel #4
0
 def test_exceeds_searchterms_limit(self):
     """
     Tests the _factor_components method for a query that exceeds the API
     limit on number of terms.
     """
     specs = PipeSpecSheet(searchterms_limit=1,
                           locations_limit=10,
                           followees_limit=10)
     engineer = Engineer(query=self.query, specs=specs)
     queries = engineer._factor_components([self.query])
     self.assertEqual(len(queries), 3)
Beispiel #5
0
 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)
Beispiel #6
0
 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)
Beispiel #7
0
 def test_or_specs_or_query(self):
     """
     Tests the _separate_components method for a query that joins SearchTerms
     and Locations with OR logic, with an API that joins SearchTerms and
     Accounts using OR logic.
     """
     self.query.trm_loc_logic = 'OR'
     specs = PipeSpecSheet.objects.get(pipe=2)  # Twitter Public Streams API
     engineer = Engineer(query=self.query, specs=specs)
     queries = engineer._separate_components()
     self.assertEqual(len(queries), 1)
Beispiel #8
0
 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)
Beispiel #9
0
 def test_no_searchterms(self):
     """
     Tests the _handle_combined_trm_fol_limit method for a query that doesn't
     include any search terms.
     """
     accounts = Account.objects.filter(pk__in=[1, 2, 3])
     accounts = list(accounts).extend(accounts) # exceeds search terms limit
     query = ReservoirQuery(accounts=accounts)
     specs = PipeSpecSheet.objects.get(pipe=1)   # Twitter Search API
     engineer = Engineer(query=query, specs=specs)
     queries = engineer._handle_combined_trm_fol_limit([query])
     self.assertEqual(len(queries), 1)
Beispiel #10
0
 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')
Beispiel #11
0
    def test_exceeds_twitter_search_api(self):
        """
        Tests the _exceeds_searchterms_limit method for the Twitter Search API
        when the search terms exceed the limit.
        """
        terms = SearchTerm.objects.filter(pk__in=[1, 2, 3, 4])
        accounts = Account.objects.filter(pk__in=[1, 2])
        query = ReservoirQuery(searchterms=terms, accounts=accounts)
        specs = PipeSpecSheet.objects.get(pipe=1)  # Twitter Search API
        engineer = Engineer(query=query, specs=specs)

        # expect 10 terms: 4 for SearchTerms, 2 for Accounts, 5 for "OR" operators
        self.assertTrue(engineer._exceeds_searchterms_limit(query))
Beispiel #12
0
    def test_do_not_count_operator(self):
        """
        Tests the get_num_searchterms method when operators are not counted
        as search terms. Uses the Twitter Public Streams API as an example.
        """
        terms = SearchTerm.objects.filter(pk=1)
        accounts = Account.objects.filter(pk__in=[1, 2])
        query = ReservoirQuery(searchterms=terms, accounts=accounts)
        specs = PipeSpecSheet.objects.get(pipe=2)  # Twitter Public Streams API
        engineer = Engineer(query=query, specs=specs)

        # expect 1: 1 for SearchTerm
        self.assertEqual(engineer.get_num_searchterms(query), 1)
Beispiel #13
0
    def test_factor_queries_by_component(self):
        """
        Tests the _factor_queries_by_component method for searchterms.
        """
        specs = PipeSpecSheet(searchterms_limit=1)
        engineer = Engineer(query=self.query, specs=specs)

        queries1 = engineer._factor_queries_by_component([self.query],
                                                         'locations', 1)
        self.assertEqual(len(queries1), 4)

        queries2 = engineer._factor_queries_by_component([self.query],
                                                         'accounts', 1)
        self.assertEqual(len(queries2), 2)
Beispiel #14
0
    def test_with_or_operator(self):
        """
        Tests the get_num_searchterms method when operators are counted as
        search terms, the default logic is "AND", and an "OR" operator can
        be used to join terms. Uses the Twitter Search API as an example.
        """
        terms = SearchTerm.objects.filter(pk=1)
        accounts = Account.objects.filter(pk__in=[1, 2])
        query = ReservoirQuery(searchterms=terms, accounts=accounts)
        specs = PipeSpecSheet.objects.get(pipe=1)  # Twitter Search API
        engineer = Engineer(query=query, specs=specs)

        # expect 5: 1 for SearchTerm, 2 for Accounts, 2 for "OR" operators
        self.assertEqual(engineer.get_num_searchterms(query), 5)
Beispiel #15
0
    def test_for_multiple_phrases(self):
        """
        Tests the _handle_phrases method for an API that accepts phrases.
        """
        # 'police', 'police oficeer', 'bank robbery'
        terms = SearchTerm.objects.filter(pk__in=[1, 2, 3])
        query = ReservoirQuery(searchterms=terms)
        specs = PipeSpecSheet(accepts_phrases=False)
        engineer = Engineer(query=query, specs=specs)
        engineer._handle_phrases()
        searchterms = engineer.get_searchterms()

        # 'police', 'officer', policeoficeer', 'bank', 'robbery', bankrobbery'
        self.assertEqual(len(searchterms), 6)
Beispiel #16
0
    def test_single_term(self):
        """
        Tests the _separate_terms method for a single term.
        """
        terms = SearchTerm.objects.filter(pk=1)
        accounts = Account.objects.filter(pk__in=[1, 2])
        query = ReservoirQuery(searchterms=terms, accounts=accounts)
        specs = PipeSpecSheet.objects.get(pipe=1)  # Twitter Search API
        engineer = Engineer(query=query, specs=specs)
        queries = engineer._separate_terms(query)

        self.assertEqual(len(queries), 1)

        # make sure Accounts are being copied to the child queries
        self.assertEqual(queries[0].accounts[0], accounts[0])
Beispiel #17
0
    def test_needs_splitting(self):
        """
        Tests the _handle_combined_trm_fol_limit method for a query that
        includes accounts and search terms, but that doesn't exceed the API
        limit.
        """
        specs = PipeSpecSheet(searchterms_limit=8,
                              combine_trm_fol=True,
                              trm_trm_logic='AND',
                              combine_trm_opr=True,
                              OR_operator='OR')
        engineer = Engineer(query=self.query, specs=specs)
        queries = engineer._handle_combined_trm_fol_limit([self.query])

        self.assertEqual(len(queries), 2)
Beispiel #18
0
    def test_without_or(self):
        """
        Tests the get_num_searchterms method when the operators are counted as
        search terms and the default logic is "OR".
        """
        terms = SearchTerm.objects.filter(pk=1)
        accounts = Account.objects.filter(pk__in=[1, 2])
        query = ReservoirQuery(searchterms=terms, accounts=accounts)
        specs = PipeSpecSheet(combine_trm_fol=True,
                              combine_trm_opr=True,
                              trm_trm_logic='OR',
                              OR_operator='OR')
        engineer = Engineer(query=query, specs=specs)

        # expect 5: 1 for SearchTerm, 2 for Accounts
        self.assertEqual(engineer.get_num_searchterms(query), 3)
Beispiel #19
0
    def test_separate_locations_and_terms(self):
        """
        Tests the _separate_locations_and_terms method.
        """
        terms = SearchTerm.objects.filter(pk__in=[1, 2, 3])
        locations = Location.objects.filter(pk__in=[2, 3, 5])
        query = ReservoirQuery(searchterms=terms, locations=locations)
        specs = PipeSpecSheet.objects.get(pipe=4)
        engineer = Engineer(query=query, specs=specs)
        queries = engineer._separate_locations_and_terms(query)

        self.assertEqual(len(queries), 2)
        self.assertEqual(len(queries[0].locations), 3)
        self.assertEqual(len(queries[0].searchterms), 0)
        self.assertEqual(len(queries[1].locations), 0)
        self.assertEqual(len(queries[1].searchterms), 3)
Beispiel #20
0
    def test_separate_accounts_and_terms(self):
        """
        Tests the _separate_accounts_and_terms method.
        """
        terms = SearchTerm.objects.filter(pk__in=[1, 2, 3])
        accounts = Account.objects.filter(pk__in=[1, 2])
        query = ReservoirQuery(searchterms=terms, accounts=accounts)
        specs = PipeSpecSheet.objects.get(pipe=4)
        engineer = Engineer(query=query, specs=specs)
        queries = engineer._separate_accounts_and_terms(query)

        self.assertEqual(len(queries), 2)
        self.assertEqual(len(queries[0].accounts), 2)
        self.assertEqual(len(queries[0].searchterms), 0)
        self.assertEqual(len(queries[1].accounts), 0)
        self.assertEqual(len(queries[1].searchterms), 3)
Beispiel #21
0
    def test_format_for_box(self):
        """
        Tests the format_locations method for a 'box' location_format.
        """
        query = ReservoirQuery(locations=self.locations)
        specs = PipeSpecSheet(location_format='box')
        engineer = Engineer(query=query, specs=specs)
        engineer._format_locations()

        all_boxes = False
        for new_location in engineer.get_locations():
            if new_location.shape == 'Rectangle':
                all_boxes = True
            else:
                all_boxes = False
                break

        self.assertTrue(all_boxes)
Beispiel #22
0
    def test_format_for_radius(self):
        """
        Tests the format_locations method for a 'radius' location_format.
        """
        query = ReservoirQuery(locations=self.locations)
        specs = PipeSpecSheet(location_format='radius', radius_limit_km=100)
        engineer = Engineer(query=query, specs=specs)
        engineer._format_locations()

        all_circles = False
        for new_location in engineer.get_locations():
            if new_location.shape == 'Circle':
                all_circles = True
            else:
                all_circles = False
                break

        self.assertTrue(all_circles)
Beispiel #23
0
 def setUp(self):
     super(GetQueryParametersTestCase, self).setUp()
     self.engineer = Engineer(query=self.query, specs=PipeSpecSheet())