Exemplo n.º 1
0
 def build_url(self):
     f = furl('http://where.yahooapis.com/geocode?flags=JST&gflags=A')
     f.args['location'] = self.search_location
     f.args['appid'] = self.api_key
     request = self.fetch(f.url)
     request = json.load(request)
     self._request = request
Exemplo n.º 2
0
 def __init__(self, base_uri, test_dir):
     self.number = 0
     self.failed = 0
     self.shared = dict()
     self.base_uri = furl(base_uri)
     self.test_dir = test_dir
     self.slowdown = 0
Exemplo n.º 3
0
 def build_url(self):
     api_url = furl(MAPS_API_GEOCODE)
     api_url.args['address'] = self.search_location
     api_url.args['sensor'] = False
     request = self.fetch(api_url.url)
     request = json.load(request)
     self._request = request
Exemplo n.º 4
0
 def fetch_data(self):
     """
     Fetches the data from Battlelog and shows the result to the user.
     Here self.build_url() is called for every QCheckBox list we have.
     Checks whether the application has admin privilege by sending one ping.
     """
     self.save_config()
     try:
         do_one("battlelog.battlefield.com")
     except socker_error:
         error_msg = "Cannot ping the servers since the application doesn't have admin privilege."
         QtGui.QMessageBox.warning(self, "Socket Error", error_msg)
         return
     self.browse_button.setText("Working...")
     self.base_url = furl("http://battlelog.battlefield.com/bf3/servers/")
     self.base_url.add({'filtered': '1'})
     self.build_url(self.map_check_box, BF3Server.map_code, 'maps')
     self.build_url(self.mode_check_box, BF3Server.game_mode, 'gamemodes')
     self.build_url(self.game_size_check_box, BF3Server.game_size, 'gameSize')
     self.build_url(self.free_slots_check_box, BF3Server.free_slots, 'slots')
     self.build_url(self.preset_check_box, BF3Server.preset, 'gamepresets')
     self.build_url(self.game_check_box, BF3Server.game, 'gameexpansions')
     self.base_url.add(self.detailed_settings)
     if self.countries:
         self.base_url.add({'useLocation': '1'})
         self.base_url.add({'country': '|'.join(self.countries)})
     if self.server_name_search_box.text():
         self.base_url.add({'q': self.server_name_search_box.text()})
     params = dict(url=str(self.base_url), limit=self.results_limit_spinbox.value(),
                   ping_repeat=self.ping_repeat, ping_step=self.ping_step)
     self.worker = WorkerThread(params)
     self.worker.start()
     self.browse_button.setDisabled(True)
     self.worker.network_error_signal.connect(self.show_network_error_message)
     self.worker.completed.connect(self.enable_browse_button)
Exemplo n.º 5
0
    def url_is(self, uri, message=None):
        """
        Verify the current URI is as given

        @param uri: URI to match
        @type uri: str
        @param message: Message to display
        @type message: str
        """
        if message is None:
            message = "Current URL is: %s" % uri

        expected = furl(self.base_uri).join(uri)
        got = furl(self.browser.current_url).copy()
        expected.fragment = ''
        got.fragment = ''
        expected.query = None
        got.query = None

        self.is_equal(str(got), str(expected), message)
Exemplo n.º 6
0
    def url_like(self, expected, message=None):
        """
        Verify the current URI matches the given regex

        @param expected: Regex of URI to match
        @type expected: regex
        @param message: Message to display
        @type message: str
        """
        if message is None:
            message = "Current URL matches: %s" % expected

        got = furl(self.browser.current_url).copy()
        got.fragment = ''
        got.query = None

        self.is_like(str(got), expected, message)
Exemplo n.º 7
0
    def get_ok(self, uri, message=None):
        """
        Set the browser to load a given uri

        @param uri: URI to load
        @type uri: str
        @param message: Message to display
        @type message: str
        """
        if message is None:
            message = "Opened: %s" % uri
        full_uri = furl(self.base_uri).join(uri)
        try:
            self.browser.get(str(full_uri))
        except Exception, e:
            self.failure('%s (%s)' % (message, str(e)))
            return
Exemplo n.º 8
0
 def testTraverse(self):
     logger = getLogger().getChild("testTraverse")
     import os
     file_counter = 0
     dir_counter = 0
     for root, dirs, files in os.walk(".."):
         for file in files:
             file_counter += 1
             path = os.path.abspath(os.path.join(root, file))
             url = "file://localhost" + pathname2url(path)[2:]
             logger.debug("file[" + str(file_counter) + "]" + url)
             #identifier = IdentifierModel() 
         for dir in dirs:
             dir_counter += 1
             path = os.path.abspath(os.path.join(root, dir))
             url = "file://localhost" + pathname2url(path)[2:]
             logger.debug("dir[" + str(dir_counter) + "]" + url)
         f = furl("http://a.example.com/path/http://b.example.com/xyz.html")
         logger.debug(f.url)
Exemplo n.º 9
0
    def validate(cls, value: Any, field: ModelField,
                 config: BaseConfig) -> furl:
        """Validate and parse the given URL string value.

        Args:
            value (Any):
                The URL provided by a user.
            field (ModelField):
                The field instance the URL is using.
            config (BaseConfig):
                The config instance the URL is in.

        Returns:
            :class:`furl.furl.furl`:
                The furl instance of the given URL string.
        """

        AnyHttpUrl.validate(value, field, config)
        return furl(url=value)
Exemplo n.º 10
0
    def configure_for_flask(self):
        app.switch_to_test_mode()

        if not re.search(r'test', app.db.name):
            raise Exception("Mongo database '%s' doesn't have 'test' in its name. Refusing to run tests" % app.db.name)

        server_url = furl(app.settings.get('server', 'url'))

        selenium_server_url = 'http://%s:%d/wd/hub' % (app.settings.get('test', 'selenium_server_host'), int(app.settings.get('test', 'selenium_server_port')))
        selenium_browser = app.settings.get('test', 'browser')

        sys.stderr.write("Tests will run against: %s\n" % server_url)
        sys.stderr.write("Tests will use mongodb: %s\n" % app.db.name)

        # This just stops the "accesslog" output from the server
        logging.getLogger('werkzeug').setLevel(logging.ERROR)

        # Stops lots of crappy selenium logging
        logging.getLogger('selenium.webdriver.remote.remote_connection').setLevel(logging.WARNING)

        self.configure(
            server_url          = server_url,
            selenium_server_url = selenium_server_url,
            selenium_browser    = selenium_browser,
            test_dir            = os.path.join(app.root_path, 'test'),
            screenshot_dir      = os.path.join(app.root_path, '..', 'logs'),
        )

        if not self.configured:
            return

        # Empty the test database to get things rolling
        app.db.connection.drop_database(app.db.name)

        # Start the server
        self.server_process = Process(target=self._start_flask_app)
        self.server_process.start()

        # This is a dodgy way of ensuring the server is running
        sleep(1)
        if not self.server_process.is_alive():
            raise Exception("Server failed to start")
Exemplo n.º 11
0
    def __call__(self, request):
        # for now we ensure these are available
        if not request.params:
            request.params = {}
        if not request.data:
            request.data = {}

        # this is an apparent bug in Requests that is being addressed
        if isinstance(request.params, list):
            request.params = dict(request.params)
        if isinstance(request.data, list):
            request.data = dict(request.data)

        # generate the necessary request params
        request.oauth_params = self.generate_oauth_params()

        # here we append an oauth_callback parameter if any
        if 'oauth_callback' in request.data:
            request.oauth_params['oauth_callback'] = \
                    request.data.pop('oauth_callback')
        if 'oauth_callback' in request.params:
            request.oauth_params['oauth_callback'] = \
                    request.params.pop('oauth_callback')

        # this is used in the Normalize Request Parameters step
        request.data_and_params = request.oauth_params.copy()

        # sign and add the signature to the request params
        self.signature.sign(request, self.consumer, self.token)

        if self.header_auth:
            # authenticate in the header
            request.headers['Authorization'] = \
                    self.generate_authorization_header(request.oauth_params)
        else:
            # add data_and_params to the URL parameters
            f = furl.furl(request.url)
            f.args.update(request.data_and_params)
            request.url = f.url
Exemplo n.º 12
0
    def _permissions_query(cls, request, email=None, item=None, search=None):
        """
        This is a utility method for any AuthZ query. It ensures results are properly paged.
        :param request: The current user request context
        :param email: The email of the person for whom permissions apply (if None, calling user must have permissions
                      to lookup permissions of other users)
        :param item: The item to check permissions on (e.g. 'Hypatio', 'Hypatio.n2c2-t2')
        :param search: Any search parameters, comma separated (email and permission is 'iexact', item is 'contains'
                       Searching can include any number of parameters but will only be compared to `item`, `permission`
                       and `email`
        :return:
        """
        # Get request objects
        jwt = request.COOKIES.get("DBMI_JWT")
        if not jwt:
            raise ValueError('Cannot request permissions without valid JWT')

        # Set url
        url = furl(DBMIAuthz.user_permissions_url)

        # Build parameters
        params = {}
        if email:
            params['email'] = email
        else:
            params['email'] = request.user.email
        if item:
            params['item'] = item
        if search:
            params['search'] = search

        # Set headers
        headers = {
            "Authorization": "JWT " + jwt,
            'Content-Type': 'application/json'
        }

        # Page until we have no more URLs returned
        permissions = []
        content = None
        while url is not None:
            try:
                # Make the request
                response = requests.get(url=url.url,
                                        headers=headers,
                                        params=params)
                content = response.content
                response.raise_for_status()

                # Parse result
                results = response.json()

                # If there are any permissions returned, add them to the list.
                if 'results' in results:
                    permissions.extend(results['results'])

                # If there are more permissions to pull, update the URL to hit. Otherwise, exit the loop.
                url = furl.furl(
                    results['next']) if results.get('next') else None

            except Exception as e:
                logger.exception(f'AuthZ Error: {e}',
                                 exc_info=True,
                                 extra={
                                     'url': url,
                                     'params': params,
                                     'content': content,
                                 })

        return permissions
Exemplo n.º 13
0
 def get(self, uri):
     full_uri = furl(self.base_uri).join(uri)
     self.browser.get(str(full_uri))