Esempio n. 1
0
class TestGoogleJSNSearch(unittest.TestCase):
    def setUp(self):
        self.gjs = GoogleJSONSearch('"query text"')
        fixture_path = normpath(
            join(dirname(__file__), ('../../../../tests/'
                                     'fixtures/search/googleSearch.json')))
        self.fixture = open(fixture_path)
        self.page = simplejson.load(self.fixture)
        self.results = self.gjs._extract_raw_results_list(self.page)

    def tearDown(self):
        self.fixture.close()

    def test_extract_info(self):
        search_info = self.gjs._extract_info(self.page)
        self.failUnless(search_info['to'] == 8, 'Wrong "to" field')
        self.failUnless(search_info['from'] == 1, 'Wrong "from" field')
        self.failUnless(search_info['total'] == 30, 'Wrong total field')

    def test_extract_result(self):
        result = self.gjs._extract_result(self.results[0])
        self.failUnless(result.title == ('Charlie Rose - A discussion about '
                                         'George W. Bush's DWI'))
        self.failUnless(
            result.url == 'http://www.charlierose.com/view/content/3432')
        self.failUnless(result.desc.startswith('Then, Dionne and'))
Esempio n. 2
0
class TestGoogleJSNSearch(unittest.TestCase):
    def setUp(self):
        self.gjs = GoogleJSONSearch('"query text"')
        fixture_path = normpath(join(dirname(__file__), ('../../../../tests/'
            'fixtures/search/googleSearch.json')))
        self.fixture = open(fixture_path)
        self.page = simplejson.load(self.fixture)
        self.results = self.gjs._extract_raw_results_list(self.page)
        
    def tearDown(self):
        self.fixture.close() 
    
    def test_extract_info(self):
        search_info = self.gjs._extract_info(self.page)
        self.failUnless(search_info['to'] == 8, 'Wrong "to" field')
        self.failUnless(search_info['from'] == 1, 'Wrong "from" field')
        self.failUnless(search_info['total'] == 30, 'Wrong total field')
    
    def test_extract_result(self):
        result = self.gjs._extract_result(self.results[0])
        self.failUnless(result.title == ('Charlie Rose - A discussion about '
                                         'George W. Bush's DWI'))
        self.failUnless(result.url == 
                        'http://www.charlierose.com/view/content/3432')
        self.failUnless(result.desc.startswith('Then, Dionne and'))
Esempio n. 3
0
 def setUp(self):
     self.gjs = GoogleJSONSearch('"query text"')
     fixture_path = normpath(
         join(dirname(__file__), ('../../../../tests/'
                                  'fixtures/search/googleSearch.json')))
     self.fixture = open(fixture_path)
     self.page = simplejson.load(self.fixture)
     self.results = self.gjs._extract_raw_results_list(self.page)
Esempio n. 4
0
 def setUp(self):
     self.gjs = GoogleJSONSearch('"query text"')
     fixture_path = normpath(join(dirname(__file__), ('../../../../tests/'
         'fixtures/search/googleSearch.json')))
     self.fixture = open(fixture_path)
     self.page = simplejson.load(self.fixture)
     self.results = self.gjs._extract_raw_results_list(self.page)
Esempio n. 5
0
 def create_searcher(self, engine):
     if engine == Searcher.GOOGLE:
         return GoogleJSONSearch()
     elif engine == Searcher.SCHOLAR:
         return ScholarSearch()
     elif engine == Searcher.BING:
         return BingSearch()
     elif engine == Searcher.YAHOO:
         return YahooSearch()
     else:
         raise UtilCreationError('Requested searcher is not available')