pyral deleteAttachment для удаления вложения из определения Test Case не работает - PullRequest
1 голос
/ 25 января 2020

Я пытаюсь удалить вложения из определения Test Case на Rally, используя pyral:

del_attachment = rally.deleteAttachment('TestCase',filename)

любые предложения, что не так?

Ответы [ 2 ]

0 голосов
/ 26 марта 2020

передача строки FormattedID артефакта должна работать, потому что pyral пытается определить тип артефакта и получить его для вас в вызове ниже.

        art_type, artifact = self._realizeArtifact(artifact)

посмотрите на код для _realizeArtifact ...

    def _realizeArtifact(self, artifact):
    """
        Helper method to identify the artifact type and to retrieve it if the 
        artifact value is a FormattedID. If the artifact is already an instance
        of a Rally entity, then all that needs to be done is deduce the art_type
        from the class name.  If the artifact argument given is neither of those 
        two conditions, return back a 2 tuple of (False, None).
        Once you have a Rally instance of the artifact, return back a 
        2 tuple of (art_type, artifact)
    """
    art_type = False
    if 'pyral.entity.' in str(type(artifact)):
        # we've got the artifact already...
        art_type = artifact.__class__.__name__
    elif self.FORMATTED_ID_PATTERN.match(artifact): 
        # artifact is a potential FormattedID value
        prefix = artifact[:2]
        if prefix[1] in string.digits:
            prefix = prefix[0]
        art_type = self.ARTIFACT_TYPE[prefix]
        response = self.get(art_type, fetch=True, query='FormattedID = %s' % artifact)
        if response.resultCount == 1:
            artifact = response.next()
        else:
            art_type = False
    else: # the supplied artifact isn't anything we can deal with here...
        pass

    return art_type, artifact
0 голосов
/ 25 января 2020

Если вы посмотрите на код из pyral, вы получите следующую подпись:

  def deleteAttachment(self, artifact, filename):
        """
            Still unclear for WSAPI v2.0 if Attachment items can be deleted.
            Apparently AttachmentContent items can be deleted.
        """
        art_type, artifact = self._realizeArtifact(artifact)
        if not art_type:
            return False

        current_attachments = [att for att in artifact.Attachments]
        hits = [att for att in current_attachments if att.Name == filename]
        if not hits:
            return False

        ...

Таким образом, первый аргумент - это артефакт (то есть объект тестового примера), не строка.

Может быть так:

import logging

logging.basicConfig(format="%(levelname)s:%(module)s:%(lineno)d:%(msg)s")


try:
    # Get number of existing steps
    testcase = rally.get("TestCase", query="FormattedID = %s" % tcid, instance=True)
    has_been_deleted = rally.deleteAttachment(testcase, filename)
    if not has_been_deleted:
        msg = "Attachment '{0}' of Test Case {1} not deleted successfully"
        logging.warning(msg.format(filename, testcase.FormattedID))

except RallyRESTAPIError as e:
    logging.error("Error while deleting attachment '{0}': {1}".format(filename, e))
...