Exemplo n.º 1
0
    def test_crawl_002(self):
        """Must call `httplib2.Http.request` and `report_item`."""

        def mock_get_crawl_queue(_limit):
            return [{'url': "http://localhost/test_crawl_002_link", 'visited': None, 'links': []}]

        def mock_report_result(report):
            self.assertEqual(report['url'], "http://localhost/test_crawl_002_link")

        smock.mock('api.get_crawl_queue', returns_func=mock_get_crawl_queue)
        smock.mock('api.report_result', returns_func=mock_report_result)
        smock.mock('httplib2.Http.request', returns=(make_http_response(404), ""))
        with eventlet.Timeout(DEFAULT_TIMEOUT, False):
            self.client.crawl()
        self.assertTrue(smock.is_called('httplib2.Http.request'))
        self.assertTrue(smock.is_called('api.report_result'))
Exemplo n.º 2
0
    def test_crawl_001(self):
        """Must call `api.get_crawl_queue()`."""

        smock.mock('api.get_crawl_queue', returns=[])
        with eventlet.Timeout(DEFAULT_TIMEOUT, False):
            self.client.crawl()
        self.assertTrue(smock.is_called('api.get_crawl_queue'))
Exemplo n.º 3
0
    def test_get_001(self):
        """Must call `storage.meta.query_new_random`."""

        req = webob.Request.blank('/')
        req.method = 'POST'
        req.body = "limit=10"

        smock.mock('StorageConnection.query_new_random', returns=[])
        self.manager.active = True
        self.manager.crawl_queue(req)
        self.assertTrue(smock.is_called('StorageConnection.query_new_random'))