Example #1
0
    def move_work_item_here(self,
                            work_item_id,
                            parent_id,
                            position=-1,
                            retain_flow=True):
        """Moves a work item to a specific position in a Document. If the work
        item is not yet inside the Document it will be moved into the Document.

        Args:
            work_item_id: WorkItem id to move
            parent_id: The parent WorkItem id, can be None
            position (int): desired position in the list of children or a
                            value < 0 to insert at the end (if the old and new
                            parent is the same then moved work item is not
                            counted)
            retain_flow (bool): true to retain the position of moved work item
                                in the document flow (even if it means to
                                change the parent).
                                false to keep desired parent (even if it means
                                to move work item to different position)

        Returns:
            None

        References:
            Tracker.moveWorkItemToDocument
        """
        self._verify_obj()
        wi = _WorkItem(self.project_id, work_item_id)
        if parent_id:
            parent_uri = _WorkItem(self.project_id, parent_id).uri
        else:
            parent_uri = None
        self.session.tracker_client.service.moveWorkItemToDocument(
            wi.uri, self.uri, parent_uri, position, retain_flow)
Example #2
0
def set_automation_of_wi(project, wi_id, automation):
    """
    Get the automation status of a workitem.
    """
    polarion_wi = _WorkItem(project_id=project, work_item_id=wi_id)
    if automation not in ['manualonly', 'notautomated', 'automated']:
        raise RuntimeError("Invalud automation status: %s" % automation)
    if not _WorkItem.session.tx_in():
        _WorkItem.session.tx_begin()
    polarion_wi._set_custom_field('caseautomation', EnumOptionId(enum_id=automation)._suds_object)
    _WorkItem.session.tx_commit()
Example #3
0
def get_automation_of_wi(project, wi_id):
    """
    Get the automation status of a workitem.
    """
    polarion_wi = _WorkItem(project_id=project, work_item_id=wi_id)
    try:
        for custom in polarion_wi._suds_object.customFields.Custom:
            if custom.key == 'caseautomation':
                return literal(custom.value.id)
    except AttributeError:
        pass
    return None
Example #4
0
def get_automation_of_wi(wi_id):
    """
    Get the automation status of a workitem.
    """
    ret = 'notautomated'
    polarion_wi = _WorkItem(project_id=PROJECT, work_item_id=wi_id)
    try:
        for custom in polarion_wi._suds_object.customFields.Custom:
            if custom.key == 'caseautomation':
                ret = custom.value.id
    except AttributeError:
        # Skip heading / case with no automation attribute
        pass
    return ret
Example #5
0
def get_automation_of_wi(wi_id):
    """
    Get the automation status of a workitem.
    """
    ret = 'notautomated'
    polarion_wi = _WorkItem(project_id=PROJECT, work_item_id=wi_id)
    try:
        for custom in polarion_wi._suds_object.customFields.Custom:
            if custom.key == 'caseautomation':
                ret = custom.value.id
    except AttributeError:
        # Skip heading / case with no automation attribute
        pass
    return ret
Example #6
0
    def get_work_items(self,
                       parent_work_item_id,
                       deep,
                       fields=["work_item_id", "type"]):
        """Returns work items (with given fields set) contained in given
        Module/Document under given parent (if specified).

        Args:
            parent_work_item_id (str): Id of parent work item or None
            deep: true to return work items from the whole subtree
            fields: fields to fill. For nested structures in the lists you can
                    use following syntax to include only subset of fields:
                    myList.LIST.key (e.g. linkedWorkItems.LIST.role).
                    For custom fields you can specify which fields you want to
                    be filled using following syntax:
                    customFields.CUSTOM_FIELD_ID (e.g. customFields.risk).

        Returns:
            list of _WorkItem objects

        References:
            Tracker.getModuleWorkItems
        """
        self._verify_obj()
        if parent_work_item_id:
            parent_uri = _WorkItem(work_item_id=parent_work_item_id,
                                   project_id=self.project_id).uri
        else:
            parent_uri = None
        p_fields = _WorkItem._convert_obj_fields_to_polarion(fields)
        suds_wi = self.session.tracker_client.service. \
            getModuleWorkItems(self.uri, parent_uri, deep, p_fields)
        work_items = []
        for w_item in suds_wi:
            work_items.append(_WorkItem(suds_object=w_item))
        return work_items
Example #7
0
    def create_work_item(self, parent_id, w_item):
        """create a work item in the current document

        Args:
            parent_id: The work_item_id of the parent _WorkItem
            wi: The Work Item object to create.

        Returns:
            The created _WorkItem

        References:
            Tracker.createWorkItemInModule
        """
        self._verify_obj()
        if isinstance(w_item, _WorkItem):
            w_item.verify_required()
            suds_wi = w_item._suds_object
        else:
            raise PylarionLibException(
                "the w_item parameter must be a _WorkItem")
        if parent_id:
            parent_uri = _WorkItem(work_item_id=parent_id,
                                   project_id=self.project_id).uri
        else:
            doc_wis = self.get_work_items(None, False, None)
            if doc_wis:
                parent_uri = doc_wis[0].uri
            else:
                parent_uri = None
            wi_uri = self.session.tracker_client.service. \
                createWorkItemInModule(self.uri, parent_uri, suds_wi)
            new_wi = w_item.__class__(uri=wi_uri)
            new_wi._changed_fields = w_item._changed_fields
            new_wi.update()
            new_wi = _WorkItem(uri=wi_uri)
            return new_wi
Example #8
0
    def add_referenced_work_item(self, work_item_id):
        """Adds a work item to the document as a referenced work_item to the
        end of the current document.

        Args:
            work_item_id (str): the id of a work item in the same project as
            the current document

        Returns:
            None
        """
        self._verify_obj()
        wi = _WorkItem(project_id=self.project_id, work_item_id=work_item_id)
        ref_wi_template = """<div id="polarion_wiki macro name=""" \
            """module-workitem;params=id=%s|external=true">"""
        self.home_page_content += ref_wi_template % work_item_id
        self.update()
Example #9
0
    def remove_plan_items(self, work_items):
        """Remove plan records to the plan.

        Args:
            items: list of work_item_ids

        Returns:
            None

        References:
            Planning.removePlanItems
        """
        self._verify_obj()
        if work_items:
            if not isinstance(work_items, list):
                raise PylarionLibException(
                    "work_items must be a list of _WorkItem objects")
        p_items = []
        for item in work_items:
            wi = _WorkItem(self.project_id, work_item_id=item)
            p_items.append(wi.uri)
        self.session.planning_client.service.removePlanItems(self.uri, p_items)
Example #10
0
    def create(cls,
               project_id,
               space,
               document_name,
               document_title,
               allowed_wi_types,
               document_type,
               structure_link_role="parent",
               home_page_content=""):
        # There is no document object.
        # don't know what to do with the URI it returns.
        """class method create Creates a document or an old-style
        Module/Document in given location with given parameters.

        Args:
            project_id: project to create module in
            space: document space location with one component or None for
                   default space
            document_name: Document name (required)
            document_title: Document title (required)
            allowed_wi_types: list of types, only one should be specified
            document_type: Type of document (required i.e testspecification).
            structure_link_role: required, role which defines the hierarchy of
                                 work items inside the Module, default: parent
            home_page_content: HTML markup for document home page, default ""

        Returns:
            None

        References:
            Tracker.createDocument
        """
        if isinstance(allowed_wi_types, basestring):
            allowed_wi_types = [allowed_wi_types]
        awit = [EnumOptionId(item)._suds_object for item in allowed_wi_types]
        slr = EnumOptionId(structure_link_role)._suds_object
        try:
            uri = cls.session.tracker_client.service.createDocument(
                project_id, space, document_name, document_title, awit, slr,
                home_page_content)
            doc = Document(uri=uri)
            doc.type = document_type
            # for some reason, when in a tx (@tx_wrapper), the
            # returned doc does not include the home_page_content attribute
            # so it must be reset before the update. If it is not set, an
            # exception is raised:
            # "java.lang.IllegalArgumentException: Content can't be null"
            if not doc.home_page_content:
                doc.home_page_content = home_page_content
            doc.update()
            if not home_page_content:
                # create heading work item for each document
                wi_head = _WorkItem()
                wi_head.type = "heading"
                wi_head.title = document_title
                doc.create_work_item(None, wi_head)
            return doc
        except suds.WebFault as e:
            if "Invalid document on location Location" in e.fault.faultstring:
                raise PylarionLibException(
                    "Document {0}/{1} already exists".format(
                        space, document_name))
            else:
                raise PylarionLibException(e.fault)