Ejemplo n.º 1
0
 def test_load_phantomjs_with_headers(self, mock_dcap, mock_driver):
     self.config["DRIVER_NAME"] = "PhantomJS"
     self.config["HEADERS"] = {
         "User-Agent": "Mozilla/7.0 (Macintosh; Intel Mac OS X 10_11_3) Apple"
         "WebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.10"
         "3 Safari/537.36"
     }
     driver = load_driver(self.config)
     driver.close()
Ejemplo n.º 2
0
 def test_load_phantomjs(self, mock_dcap, mock_driver):
     self.config["DRIVER_NAME"] = "PhantomJS"
     driver = load_driver(self.config)
     mock_driver.assert_called_once_with(
         desired_capabilities={},
         service_args=["--ignore-ssl-errors=true", "--ssl-protocol=any", "--web-security=false"],
         service_log_path="/dev/null",
     )
     driver.close()
Ejemplo n.º 3
0
Archivo: core.py Proyecto: thylong/cabu
    def __init__(self, import_name=__package__, db=None, *args, **kwargs):
        """Cabu main class, acts as a WSGI interface.

        It overrides Flask to include the config, the Selenium WebDriver,
        the Database, eventually an S3 bucket and a FTP.

        Args:
            import_name (str): Same as for Flask initialization.
            db (Optional[object]): The database driver class. Defaults to None.

        Returns:
            object: A Flask instance plus Cabu specific attributes.
        """
        super(Cabu, self).__init__(import_name, **kwargs)
        settings_path = os.environ.get('CABU_SETTINGS', 'cabu.default_settings')
        self.load_config(settings_path)

        if db:
            if 'DATABASE_URI' not in self.config:
                if db.__name__ == 'PyMongo':
                    default_uri = 'mongodb://localhost/%s' % self.name
                else:
                    raise ConfigurationException(
                        'Unknown database missing DATABASE_URI setting.'
                    )

                self.config['DATABASE_URI'] = os.environ.get(
                    'DATABASE_URI', default_uri
                )
            mongo = db(self, config_prefix='DATABASE')
            with self.app_context():
                self.db = mongo.db
                self.cookies = CookieStorage(self.db)

        if self.config.get('S3_BUCKET'):
            self.bucket = Bucket(
                self.config['S3_BUCKET'],
                self.config['S3_ACCESS_KEY'],
                self.config['S3_SECRET_KEY']
            )

        if self.config.get('FTP_HOST'):  # pragma: no cover
            self.ftp = ftpretty(
                self.config['FTP_HOST'],
                self.config['FTP_LOGIN'],
                self.config['FTP_PASSWORD']
            )

        self.vdisplay = load_vdisplay(self.config)
        self.webdriver = load_driver(self.config, self.vdisplay)
Ejemplo n.º 4
0
 def test_load_with_phantomjs_https_proxy(self, mock_dcap, mock_driver):
     os.environ["HTTP_PROXY"] = "http://127.0.0.1:80"
     driver = load_driver(self.config)
     mock_driver.assert_called_once_with(
         desired_capabilities={},
         service_args=[
             "--ignore-ssl-errors=true",
             "--ssl-protocol=any",
             "--web-security=false",
             "--proxy=127.0.0.1:80",
             "--proxy-type=http",
         ],
         service_log_path="/dev/null",
     )
     driver.close()
Ejemplo n.º 5
0
 def test_load_with_firefox_https_proxy(self, mock_driver):
     self.config["DRIVER_NAME"] = "Firefox"
     os.environ["HTTPS_PROXY"] = "http://127.0.0.1:80"
     driver = load_driver(self.config)
     driver.close()
Ejemplo n.º 6
0
 def test_load_chrome(self, mock_driver):
     self.config["DRIVER_NAME"] = "Chrome"
     driver = load_driver(self.config)
     mock_driver.assert_called_once_with()
     driver.close()
Ejemplo n.º 7
0
 def test_load_firefox_with_binary(self, mock_driver):
     self.config["DRIVER_NAME"] = "Firefox"
     self.config["DRIVER_BINARY_PATH"] = "firefox"
     driver = load_driver(self.config)
     driver.close()
Ejemplo n.º 8
0
 def test_load_firefox(self, mock_driver):
     self.config["DRIVER_NAME"] = "Firefox"
     driver = load_driver(self.config)
     driver.close()
Ejemplo n.º 9
0
 def test_unload_driver_fail(self, mock_driver):
     driver = load_driver(self.config)
     mock_driver.assert_called_once_with(self.config)
     driver.close = Mock()
     driver.close.side_effect = Exception("Boom !")
     unload_driver(driver)
Ejemplo n.º 10
0
 def test_load_driver(self, mock_driver):
     driver = load_driver(self.config)
     mock_driver.assert_called_once_with(self.config)
     unload_driver(driver)
Ejemplo n.º 11
0
 def test_load_unrecognized_driver(self):
     self.config["DRIVER_NAME"] = "Netscape"
     with self.assertRaises(DriverException):
         load_driver(self.config)
Ejemplo n.º 12
0
 def test_load_no_driver(self):
     self.config["DRIVER_NAME"] = None
     load_driver(self.config)