예제 #1
0
def main(args):

    jira = JiraProxy(REG_USER_CONFIG)

    target_issue = jira.getIssue(JIRA_ISSUE_KEY)

    attachments = jira.getIssueAttachmentsInfo(JIRA_ISSUE_KEY)

    textfile = '../test/attachments/testattachment.txt'
    txtf_info  = {'filename'      : 'uvular.txt',
                  'file_content'  : Path(textfile).read_bytes(),
                  'mimetype'      : "text/plain"
                 }

    jpeg_file = '../test/attachments/earthjello.jpeg'
    imgf_info = {'filename'      : 'ragnarok.jpeg',
                 'file_content'  : Path(jpeg_file).read_bytes(),
                 'mimetype'      : "image/jpeg"
                }

    attachments = [txtf_info, imgf_info]
    result = jira.addAttachmentsToIssue(target_issue.key, attachments)

    assert result['uvular.txt']["added"] == True
    assert result['ragnarok.jpeg']["added"]    == True
예제 #2
0
def main(args):

    jira = JiraProxy(REG_USER_CONFIG)

    attachments = jira.getIssueAttachmentsInfo(JIRA_ISSUE_KEY)

    for attachment_info in attachments:
        content = jira.getAttachmentContent(attachment_info)
        print(
            f'{attachment_info.filename:<20} {attachment_info.mimetype:<12} Content length : {len(content)}'
        )
예제 #3
0
def test_adding_multiple_attachments_to_an_issue():
    """
        add 2 attachments to an issue like from the connector
    """
    jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG)

    issue_key = ensureTargetJiraBugExists(jp, PROJECT_KEY_1, 'Bug')
    attachments = jp.getIssueAttachmentsInfo(issue_key)
    assert len(attachments) == 2
    att_content = jp.getAttachmentContent(attachments[1])
    assert att_content.decode('UTF-8') == "Hello World of hurt!"
예제 #4
0
def test_get_list_of_attachments_for_specific_issue():
    """
        get a list of attachments with the getIssueAttachmentsInfo method given an issue id
    """
    jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG)
    target_bug = ensureTargetJiraBugExists(jp, PROJECT_KEY_1, 'Bug')
    attachments = jp.getIssueAttachmentsInfo(target_bug)
    assert len(attachments) == 2
    matching_atts = [att for att in attachments if att.filename == 'earthjello.jpeg']
    assert len(matching_atts) >= 1
    image_attachment = matching_atts[0]
    assert image_attachment.filename == "earthjello.jpeg"
    assert image_attachment.mimetype == "image/jpeg"
    assert 40000 < image_attachment.filesize < 45000
예제 #5
0
def test_get_list_of_attachments_for_specific_issue():
    """
        get a list of attachments with the getIssueAttachmentsInfo method given an issue id
    """
    jp = JiraProxy(CLOUD_CONFIG)
    attachments = jp.getIssueAttachmentsInfo(SMO_TEST_ITEM)
    assert len(attachments) == 2
    matching_atts = [
        att for att in attachments if att.filename == 'earthjello.jpeg'
    ]
    assert len(matching_atts) >= 1
    image_attachment = matching_atts[0]
    assert image_attachment.filename == "earthjello.jpeg"
    assert image_attachment.mimetype == "image/jpeg"
    assert image_attachment.filesize == 43739
예제 #6
0
def test_fail_gracefully_when_attempting_to_obtain_content_of_nonexistent_attachment():
    """
        should fail elegantly when attempting to retrieve the attachment 
        content of a non-existent attachment
    """
    jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG)
    issue_key = ensureTargetJiraBugExists(jp, PROJECT_KEY_1, 'Bug')
    attachments = jp.getIssueAttachmentsInfo(issue_key)
    acref = attachments[1].content_ref[:]
    acref = re.sub(r'attachment\/\d+\/', 'attachment/0000/', acref)
    attachments[1].content_ref = acref
    
    with pytest.raises(JiraProxyError) as excinfo:
        jp.getAttachmentContent(attachments[1])
    actualErrorMessage = str(excinfo)
    assert '404 (Not Found)' in actualErrorMessage
예제 #7
0
def test_get_the_attachment_content_for_an_issue_with_an_attachment():
    """
        should get the content of an attachment from an issue with an attachment
    """
    jp = JiraProxy(CLOUD_CONFIG)
    attachments = jp.getIssueAttachmentsInfo(SMO_TEST_ITEM)
    assert len(attachments) == 2

    matching_atts = [
        att for att in attachments if att.filename == 'testattachment.txt'
    ]
    assert len(matching_atts) >= 1
    text_attachment = matching_atts[0]
    assert text_attachment.filename == "testattachment.txt"
    content = jp.getAttachmentContent(text_attachment)
    assert content.decode('UTF-8') == "Hello World of hurt!"
예제 #8
0
def test_fail_gracefully_when_attempting_to_obtain_content_of_nonexistent_attachment(
):
    """
        should fail elegantly when attempting to retrieve the attachment 
        content of a non-existent attachment
    """
    jp = JiraProxy(CLOUD_CONFIG)
    attachments = jp.getIssueAttachmentsInfo(SMO_TEST_ITEM)
    acref = attachments[1].content_ref[:]
    acref = re.sub(r'attachment\/content\/\d+', 'attachment/content/0000',
                   acref)
    attachments[1].content_ref = acref

    with py.test.raises(JiraProxyError) as excinfo:
        jp.getAttachmentContent(attachments[1])
    actualErrorMessage = excErrorMessage(excinfo)
    assert '404 (Not Found)' in actualErrorMessage
예제 #9
0
def test_adding_an_attachment_to_an_issue():
    """
        add a simple text file attachment to an issue
    """
    jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG)
    work_item = {"Summary" : "Bonhomie was a brother warship to the Bon Homme Richard" }
    issue_key = jp.createIssue(PROJECT_KEY_1, "Bug", work_item)

    att_info = {'filename'      : ATTACHMENT_FILE,
                'file_content'  : Path(ATTACHMENT_FILE).read_bytes(),
                'mimetype'      : "text/plain"
               }

    attachments = [att_info]
    result = jp.addAttachmentsToIssue(issue_key, attachments)
    assert result[ATTACHMENT_FILE]["added"] == True
    attachments = jp.getIssueAttachmentsInfo(issue_key)
    att_content = jp.getAttachmentContent(attachments[0])
    assert att_content.decode() == "The World is Good."

    assert jp.deleteIssue(issue_key)
예제 #10
0
def test_adding_an_attachment_to_an_issue():
    """
        add an attachment to an issue
    """

    jp = JiraProxy(CLOUD_CONFIG)
    work_item = {"Summary": "Monet was a painter"}
    issue_key = jp.createIssue(SMO_KEY_NAME, "Bug", work_item)
    attachments = []
    att_info = {
        'filename': ATTACHMENT_FILE,
        'file_content': Path(ATTACHMENT_FILE).read_bytes(),
        'mimetype': "text/plain"
    }
    attachments.append(att_info)
    result = jp.addAttachmentsToIssue(issue_key, attachments)
    assert result[ATTACHMENT_FILE]["added"] == True
    attachments = jp.getIssueAttachmentsInfo(issue_key)
    att_content = jp.getAttachmentContent(attachments[0])
    assert att_content.decode() == "The World is Good."

    assert jp.deleteIssue(issue_key)
예제 #11
0
def test_adding_an_attachment_using_connector_protocol():
    """
        add an attachment to an issue like from the connector
    """
    jp = JiraProxy(CLOUD_CONFIG)
    work_item = {"Summary": "Monet was a painter"}
    issue_key = jp.createIssue(SMO_KEY_NAME, "Bug", work_item)
    attachments = []
    filename = f"attach-{uuid.uuid1()}.txt"
    minimal_text = b'Some text in the file'
    att_info = {
        'filename': filename,
        'mimetype': "text/plain",
        'file_content': minimal_text
    }
    attachments.append(att_info)
    result = jp.addAttachmentsToIssue(issue_key, attachments)
    assert result[filename]["added"] == True
    attachments = jp.getIssueAttachmentsInfo(issue_key)
    att_content = jp.getAttachmentContent(attachments[0])
    assert att_content.decode('UTF-8') == "Some text in the file"

    assert jp.deleteIssue(issue_key)