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
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
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)}' )
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!"
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!"
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)
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)
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)