Пример #1
0
    def find_view(self, view_name):
        """Attempts to locate a sub-view under this nested view with the given name

        :param str view_name: the name of the sub-view to locate
        :returns: Reference to View object for the view with the given name, or None if no view with that name exists
        :rtype: Object derived from :class:`~.view.View`
        """

        data = self._controller.get_api_data()

        raw_views = data['views']

        for cur_view in raw_views:
            if cur_view['name'] == view_name:
                new_io_obj = self._controller.clone(cur_view['url'])
                return View.create(new_io_obj, self._master)

        for cur_view in raw_views:
            new_io_obj = self._controller.clone(cur_view['url'])
            temp_view = View.create(new_io_obj, self._master)
            if temp_view.type == NestedView.type:
                sub_view = temp_view.find_view(view_name)
                if sub_view is not None:
                    return sub_view

        return None
Пример #2
0
    def find_view(self, view_name):
        """Searches views directly managed by this Jenkins instance for a specific view

        .. seealso: :py:meth:`.get_view`

        :param str view_name: the name of the view to search for
        :returns:
            If a view with the specified name can be found, an object to manage the view will be returned,
            otherwise None
        :rtype: :class:`~.view.View`
        """
        data = self._controller.get_api_data()

        raw_views = data['views']

        for cur_view in raw_views:
            if cur_view['name'] == view_name:
                turl = cur_view['url']
                if turl.find('view') == -1:
                    turl = turl.rstrip("/") + "/view/" + cur_view['name']

                new_io_obj = self._controller.clone(turl)
                return View.create(new_io_obj, self)

        return None
Пример #3
0
    def views(self):
        """Gets a list of all views directly managed by the Jenkins dashboard

        To retrieve all views managed by this Jenkins instance, including recursing into
        views that support sub-views, see the :py:meth:`.all_views` property

        :returns: list of one or more views defined on this Jenkins instance.
        :rtype: :class:`list` of :class:`~.view.View` objects
        """
        data = self._controller.get_api_data()

        raw_views = data['views']
        retval = []

        for cur_view in raw_views:
            # The default view will not have a valid view URL
            # so we need to look for this and generate a corrected one
            turl = cur_view['url']
            if turl.find('view') == -1:
                turl = turl.rstrip("/") + "/view/" + cur_view['name']

            new_io_obj = self._controller.clone(turl)
            tview = View.create(new_io_obj, self)
            retval.append(tview)

        return retval
Пример #4
0
    def create_view(self, view_name, view_type):
        """Creates a new sub-view within this nested view

        :param str view_name: name of the new sub-view to create
        :param str view_type: data type for newly generated view
        """
        view_type = view_type.replace("__", "_")
        headers = {'Content-Type': 'application/x-www-form-urlencoded'}
        data = {
            "name": view_name,
            "mode": view_type,
            "Submit": "OK",
            "json": json.dumps({"name": view_name, "mode": view_type})
        }

        args = {}
        args['data'] = data
        args['headers'] = headers

        self._controller.post('/createView', args)

        # Load a pyjen.View object with the new view
        data = self._controller.get_api_data()

        raw_views = data['views']

        for cur_view in raw_views:
            if cur_view['name'] == view_name:
                new_io_obj = self._controller.clone(cur_view['url'])
                return View.create(new_io_obj, self._master)

        raise NestedViewCreationError("Failed to create nested view " + view_name + " under " + self.name)
Пример #5
0
 def view_types(self):
     """
     :returns: a list of Jenkins view types currently supported by this instance of PyJen
               Elements from this list may be used when creating new views on this Jenkins instance,
               so long as the accompanying view type is supported by the live Jenkins server
     :rtype: :class:`list` of :class:`str`
     """
     return View.supported_types()
Пример #6
0
    def test_supported_types(self):
        actual_types = View.supported_types()

        self.assertIn("hudson.model.ListView", actual_types)
        self.assertIn("hudson.model.AllView", actual_types)
        self.assertIn("hudson.model.MyView", actual_types)

        self.assertGreater(len(actual_types), 3)
Пример #7
0
    def default_view(self):
        """returns a reference to the primary / default Jenkins view

        The default view is the one displayed when navigating to
        the main URL. Typically this will be the "All" view.

        :returns: object that manages the default Jenkins view
        :rtype: :class:`~.view.View`
        """
        data = self._api.get_api_data()

        return View.instantiate(data['primaryView'], self._api)
Пример #8
0
    def default_view(self):
        """returns a reference to the primary / default Jenkins view

        The default view is the one displayed when navigating to
        the main URL. Typically this will be the "All" view.

        :returns: object that manages the default Jenkins view
        :rtype: :class:`~.view.View`
        """
        data = self._api.get_api_data()

        return View.instantiate(data['primaryView'], self._api)
Пример #9
0
def test_load_all_view_plugins():
    plugins = View.get_supported_plugins()
    assert plugins is not None
    assert isinstance(plugins, list)
    assert len(plugins) > 0

    mock_api = MagicMock()
    expected_name = "FakeName"
    mock_api.get_api_data.return_value = {"name": expected_name}
    for cur_plugin in plugins:
        view = cur_plugin(mock_api)
        assert view.name == expected_name
        assert isinstance(view, View)
Пример #10
0
    def get_view(self, url):
        """Establishes a connection to a View based on an absolute URL

        This method may be a bit less convenient to use in certain situations but it
        has better performance than :py:meth:`.find_view`

        .. seealso: :py:meth:`.find_view`

        :param str url: absolute URL of the view to load
        :return: an instance of the appropriate View subclass for the given view
        :rtype: :class:`~.view.View`
        """
        new_io_obj = self._controller.clone(url)
        return View.create(new_io_obj, self)
Пример #11
0
    def default_view(self):
        """returns a reference to the primary / default Jenkins view

        The default view is the one displayed when navigating to
        the main URL. Typically this will be the "All" view.

        :returns: object that manages the default Jenkins view
        :rtype: :class:`~.view.View`
        """
        data = self._controller.get_api_data()

        default_view = data['primaryView']
        new_io_obj = self._controller.clone(default_view['url'].rstrip("/") + "/view/" + default_view['name'])
        return View.create(new_io_obj, self)
Пример #12
0
def test_load_all_view_plugins():
    plugins = View.get_supported_plugins()
    assert plugins is not None
    assert isinstance(plugins, list)
    assert len(plugins) > 0

    mock_api = MagicMock()
    expected_name = "FakeName"
    mock_api.get_api_data.return_value = {
        "name": expected_name
    }
    for cur_plugin in plugins:
        view = cur_plugin(mock_api)
        assert view.name == expected_name
        assert isinstance(view, View)
Пример #13
0
    def views(self):
        """Gets all views contained within this view, non-recursively

        To get a recursive list of all child views and their children use
        :py:meth:`all_views`.

        :returns: list of all views contained within this view
        :rtype: :class:`list` of :class:`pyjen.view.View`
        """
        retval = list()

        data = self._api.get_api_data()

        for cur_view in data['views']:
            retval.append(View.instantiate(cur_view, self._api))

        return retval
Пример #14
0
    def views(self):
        """Gets a list of all views directly managed by the Jenkins dashboard

        To retrieve all views managed by this Jenkins instance, including
        recursing into views that support sub-views, see the
        :py:meth:`.all_views` property

        :returns: list of one or more views defined on this Jenkins instance.
        :rtype: :class:`list` of :class:`~.view.View` objects
        """
        retval = list()

        data = self._api.get_api_data()

        for cur_view in data['views']:
            retval.append(View.instantiate(cur_view, self._api))

        return retval
Пример #15
0
    def views(self):
        """Gets a list of all views directly managed by the Jenkins dashboard

        To retrieve all views managed by this Jenkins instance, including
        recursing into views that support sub-views, see the
        :py:meth:`.all_views` property

        :returns: list of one or more views defined on this Jenkins instance.
        :rtype: :class:`list` of :class:`~.view.View` objects
        """
        retval = list()

        data = self._api.get_api_data()

        for cur_view in data['views']:
            retval.append(View.instantiate(cur_view, self._api))

        return retval
Пример #16
0
    def find_view(self, view_name):
        """Searches views for a specific one

        .. seealso: :py:meth:`.get_view`

        :param str view_name: the name of the view to search for
        :returns:
            If a view with the specified name can be found, an object to manage
            the view will be returned, otherwise None
        :rtype: :class:`~.view.View`
        """
        data = self._api.get_api_data()

        for cur_view in data['views']:
            temp_view = View.instantiate(cur_view, self._api)
            if temp_view.name == view_name:
                return temp_view

        return None
Пример #17
0
    def views(self):
        """Gets all views contained within this view

        To get a recursive list of all child views and their children use :py:func:`all_views`.

        :returns: list of all views contained within this view
        :rtype: :class:`list`
        """
        data = self._controller.get_api_data()

        raw_views = data['views']
        retval = []

        for cur_view in raw_views:
            new_io_obj = self._controller.clone(cur_view['url'])
            tview = View.create(new_io_obj, self._master)
            retval.append(tview)

        return retval
Пример #18
0
    def find_view(self, view_name):
        """Searches views for a specific one

        .. seealso: :py:meth:`.get_view`

        :param str view_name: the name of the view to search for
        :returns:
            If a view with the specified name can be found, an object to manage
            the view will be returned, otherwise None
        :rtype: :class:`~.view.View`
        """
        data = self._api.get_api_data()

        for cur_view in data['views']:
            temp_view = View.instantiate(cur_view, self._api)
            if temp_view.name == view_name:
                return temp_view

        return None