def test_get_by_name(self):
        self.assertIs(AppModes.get_by_name("shiny"), AppModes.SHINY)
        self.assertIs(AppModes.get_by_name("bad-name", True), AppModes.UNKNOWN)
        self.assertIs(AppModes.get_by_name(None, True), AppModes.UNKNOWN)

        with self.assertRaises(ValueError):
            AppModes.get_by_name("bad-name")

        with self.assertRaises(ValueError):
            AppModes.get_by_name(None)
Пример #2
0
    def test_get_by_extension(self):
        self.assertIs(AppModes.get_by_extension(".R"), AppModes.SHINY)
        self.assertIs(AppModes.get_by_extension(".bad-ext", True), AppModes.UNKNOWN)
        self.assertIs(AppModes.get_by_extension(None, True), AppModes.UNKNOWN)

        with self.assertRaises(ValueError):
            AppModes.get_by_extension(".bad-ext")

        with self.assertRaises(ValueError):
            AppModes.get_by_extension(None)
    def test_get_by_ordinal(self):
        self.assertIs(AppModes.get_by_ordinal(1), AppModes.SHINY)
        self.assertIs(AppModes.get_by_ordinal(-1, True), AppModes.UNKNOWN)
        self.assertIs(AppModes.get_by_ordinal(None, True), AppModes.UNKNOWN)

        with self.assertRaises(ValueError):
            AppModes.get_by_ordinal(-1)

        with self.assertRaises(ValueError):
            AppModes.get_by_ordinal(None)
Пример #4
0
    def map_app(app, config):
        """
        Creates the abbreviated data dictionary for the specified app and config
        information.

        :param app: the raw app data to start with.
        :param config: the configuration data to use.
        :return: the abbreviated app data dictionary.
        """
        return {
            "id": app["id"],
            "name": app["name"],
            "title": app["title"],
            "app_mode": AppModes.get_by_ordinal(app["app_mode"]).name(),
            "url": app["url"],
            "config_url": config["config_url"],
        }
Пример #5
0
    def resolve(self, server, app_id, app_mode):
        metadata = self.get(server)
        if metadata is None:
            logger.debug(
                "No previous deployment to this server was found; this will be a new deployment."
            )
            return app_id, app_mode

        logger.debug("Found previous deployment data in %s" % self.get_path())

        if app_id is None:
            app_id = metadata.get("app_guid") or metadata.get("app_id")
            logger.debug("Using saved app ID: %s" % app_id)

        # app mode cannot be changed on redeployment
        app_mode = AppModes.get_by_name(metadata.get("app_mode"))
        return app_id, app_mode
Пример #6
0
    def map_app(app, config):
        """
        Creates the abbreviated data dictionary for the specified app and config
        information.

        :param app: the raw app data to start with.
        :param config: the configuration data to use.
        :return: the abbreviated app data dictionary.
        """
        return {
            'id': app['id'],
            'name': app['name'],
            'title': app['title'],
            'app_mode': AppModes.get_by_ordinal(app['app_mode']).name(),
            'url': app['url'],
            'config_url': config['config_url']
        }
Пример #7
0
    def mapping_filter(client, app):
        """
        Mapping/filter function for retrieving apps.  We only keep apps
        that have an app mode of static or Jupyter notebook.  The data
        for the apps we keep is an abbreviated subset.

        :param client: the client object to use for RStudio Connect calls.
        :param app: the current app from Connect.
        :return: the abbreviated data for the app or None.
        """
        # Only keep apps that match our app modes.
        app_mode = AppModes.get_by_ordinal(app["app_mode"])
        if app_mode not in (AppModes.STATIC, AppModes.JUPYTER_NOTEBOOK):
            return None

        config = client.app_config(app["id"])
        connect_server.handle_bad_response(config)

        return map_app(app, config)
Пример #8
0
def override_title_search(connect_server, app_id, app_title):
    """
    Returns a list of abbreviated app data that contains apps with a title
    that matches the given one and/or the specific app noted by its ID.

    :param connect_server: the Connect server information.
    :param app_id: the ID of a specific app to look for, if any.
    :param app_title: the title to search for.
    :return: the list of matching apps, each trimmed to ID, name, title, mode
    URL and dashboard URL.
    """
    def map_app(app, config):
        """
        Creates the abbreviated data dictionary for the specified app and config
        information.

        :param app: the raw app data to start with.
        :param config: the configuration data to use.
        :return: the abbreviated app data dictionary.
        """
        return {
            "id": app["id"],
            "name": app["name"],
            "title": app["title"],
            "app_mode": AppModes.get_by_ordinal(app["app_mode"]).name(),
            "url": app["url"],
            "config_url": config["config_url"],
        }

    def mapping_filter(client, app):
        """
        Mapping/filter function for retrieving apps.  We only keep apps
        that have an app mode of static or Jupyter notebook.  The data
        for the apps we keep is an abbreviated subset.

        :param client: the client object to use for RStudio Connect calls.
        :param app: the current app from Connect.
        :return: the abbreviated data for the app or None.
        """
        # Only keep apps that match our app modes.
        app_mode = AppModes.get_by_ordinal(app["app_mode"])
        if app_mode not in (AppModes.STATIC, AppModes.JUPYTER_NOTEBOOK):
            return None

        config = client.app_config(app["id"])
        connect_server.handle_bad_response(config)

        return map_app(app, config)

    apps = retrieve_matching_apps(
        connect_server,
        filters={
            "filter": "min_role:editor",
            "search": app_title
        },
        mapping_function=mapping_filter,
        limit=5,
    )

    if app_id:
        found = next((app for app in apps if app["id"] == app_id), None)

        if not found:
            try:
                app = get_app_info(connect_server, app_id)
                mode = AppModes.get_by_ordinal(app["app_mode"])
                if mode in (AppModes.STATIC, AppModes.JUPYTER_NOTEBOOK):
                    apps.append(
                        map_app(app, get_app_config(connect_server, app_id)))
            except RSConnectException:
                logger.debug(
                    'Error getting info for previous app_id "%s", skipping.',
                    app_id)

    return apps