def test_basic_get_projects(): """ will return a hash of project keys as keys and project names as values with the getProjects method """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) projects = jp.getProjects() assert PROJECT_KEY_1 in projects assert projects[PROJECT_KEY_1] == PROJECT_NAME_1
def test_query_using_display_name_for_components(): """ will return issues using jql that uses the display name for Component/s """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) jql = f'{proj1} AND issuetype = Story AND Component/s = "Front End" ' jira_issues = jp.getIssuesWithJql(jql) assert len(jira_issues) > 0 assert "Front End" in jira_issues[0]["Component/s"]
def test_query_using_components_with_percent_symbol_in_value(): """ will return issues using jql that for Component/s that use % in their name """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) jql = f'{proj1} AND Component/s = "machine % calc" ' jira_issues = jp.getIssuesWithJql(jql) assert len(jira_issues) > 0 assert "machine % calc" in jira_issues[0]["Component/s"]
def test_simple_query_with_multiple_items(): """ will return an Array of JiraIssue objects from a getIssuesWithJql call """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) jql = f'{proj1} AND issuetype = Story' jira_issues = jp.getIssuesWithJql(jql) assert len(jira_issues) >= 5 assert jira_issues[0].__class__ == JiraIssue
def test_query_using_display_name_for_fix_versions(): """ will return issues using jql that uses the display name for Fix Version/s """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) jql = f'{proj1} AND issuetype = Story AND Fix Version/s = peach' jira_issues = jp.getIssuesWithJql(jql) assert len(jira_issues) > 0 assert "peach" in set(jira_issues[0]["Fix Version/s"])
def test_query_specifying_for_field_whose_value_is_null(): """ query using jql for issues having no value in a specific field """ jp = JiraProxy(GOOD_VANILLA_SERVER_DEV_USER_CONFIG) #jql = f'{proj1} AND status != Closed AND assignee is null' jql = f'{proj1} AND status != Done AND Resolution is null' jira_issues = jp.getIssuesWithJql(jql) assert len(jira_issues) > 0
def test_query_using_components_with_plus_symbol_in_value(): """ it 'will return issues using jql that for Component/s that use + in their name' do """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) jql = f'{proj1} AND Component/s = "blue + gold" ' jira_issues = jp.getIssuesWithJql(jql) assert len(jira_issues) > 0 assert "blue + gold" in jira_issues[0]["Component/s"]
def test_get_custom_field_names_list(): """ will return an array of custom field names """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) #custom_field_names = jp.getCustomFields(PROJECT_KEY_1, "Story") custom_field_names = jp.getCustomFields(PROJECT_KEY_1, "Bug") assert "RallyID" in custom_field_names
def test_raise_error_for_bad_project(): """ will raise JiraProxyError when project does not exist """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) with py.test.raises(JiraProxyError) as excinfo: issue_key = jp.getPermissions(BAD_PROJECT_KEY_1) actualErrorMessage = excErrorMessage(excinfo) assert 'Could not find project for identifier:' in actualErrorMessage
def hide_test_sad_no_such_issue_type_for_project(): """ could not find issue type bug in project jest """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) with py.test.raises(JiraProxyError) as excinfo: jp.getStandardFields(PROJECT_KEY_1, 'Bug') actualErrorMessage = excErrorMessage(excinfo) assert ': Could not find Issue Type "Bug" in Project "JEST".' in actualErrorMessage assert 'Ensure the Issue Type "Bug" is available ' in actualErrorMessage
def test_bad_proj_ident_raises_error(): """ attempt to get custom fields using a bad project identifier will raise an error """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) with py.test.raises(JiraProxyError) as excinfo: custom_field_names = jp.getCustomFields(BAD_PROJECT_KEY_1, "Story") actualErrorMessage = excErrorMessage(excinfo) assert actualErrorMessage == f'Could not find project for identifier: {BAD_PROJECT_KEY_1}'
def test_sad_raise_for_invalid_project_identifier(): """ on attempt to get users will raise an error for a invalid project identifier """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) with py.test.raises(JiraProxyError) as excinfo: users = jp.getAssignableUsers(BAD_PROJECT_KEY_1) actualErrorMessage = excErrorMessage(excinfo) assert 'Could not find project for identifier:' in actualErrorMessage
def test_get_standard_fields_list_for_project_name(): """ returns an array of standard field names """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) standard_field_names = jp.getStandardFields(PROJECT_NAME_1, "Bug") assert "Summary" in standard_field_names assert "Priority" in standard_field_names assert "Affects Version/s" in standard_field_names
def test_sad_get_jira_schema_for_invalid_project(): """ will raise an error on attempt to return a JiraFieldSchema instance for a valid field for an invalid project identifier """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) with py.test.raises(JiraProxyError) as excinfo: fs = jp.fieldSchema(BAD_PROJECT_KEY_1, 'Bug', 'Priority') actualErrorMessage = excErrorMessage(excinfo) assert 'Could not find project for identifier:' in actualErrorMessage
def test_show_all_groups_for_user(): """ will return an array of groups that a user belongs to """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) regular_user = GOOD_VANILLA_SERVER_REG_USER_CONFIG['user'] groups = jp.getGroups(regular_user) assert "monsieur-connecteur" in groups assert "jira-software-users" in groups
def test_using_invalid_project_raises_error(): """ on attempt to get standard field names using an invalid project will raise an error """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) with py.test.raises(JiraProxyError) as excinfo: standard_field_names = jp.getStandardFields(BAD_PROJECT_KEY_1, "Bug") actualErrorMessage = excErrorMessage(excinfo) assert actualErrorMessage == f'Could not find project for identifier: {BAD_PROJECT_KEY_1}'
def test_update_original_estimate_field(): """ create an issue without originalEstimate and later update it with originalEstimate """ original_estimate = '2d 4h' remaining_estimate = '2d 6h' jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) work_item = {"Summary": "Another Blustery Day"} issue_key = jp.createIssue(PROJECT_KEY_1, "Bug", work_item) issue = jp.getIssue(issue_key) assert issue['Time Tracking'] == {} issue['Time Tracking'] = {'originalEstimate': original_estimate} # don't try this: # issue['Time Tracking']['originalEstimate'] = original_estimate # It will not work and you will be sad and you will gnash your teeth... assert jp.updateIssue(issue) == True issueAgain = jp.getIssue(issue_key) assert issueAgain['Time Tracking']['originalEstimate'] == original_estimate assert issueAgain['Time Tracking'][ 'remainingEstimate'] == original_estimate # you have to set the whole 'Time Tracking' item so that the originalEstimate is not overwritten issue['Time Tracking'] = { 'originalEstimate': original_estimate, 'remainingEstimate': remaining_estimate } assert jp.updateIssue(issue) == True issueAgain = jp.getIssue(issue_key) assert issueAgain['Time Tracking']['originalEstimate'] == original_estimate assert issueAgain['Time Tracking'][ 'remainingEstimate'] == remaining_estimate assert jp.deleteIssue(issue_key)
def test_get_assignable_users(): """ will return assignable users with the getAssignableUsers method """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) users = jp.getAssignableUsers(PROJECT_KEY_1) assert len(users) > 1 user_names = [user.name for user in users] assert GOOD_VANILLA_SERVER_CONFIG['user'] in user_names
def test_create_bug_with_multiple_affects_version_values(): """ create a new Jira Bug with a multiple valid Affects Version/s values """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) item_data = {'Summary' : 'Narrow morbid futons for sales', 'Affects Version/s' : 'apple,lime' } issue_key = jp.createIssue(PROJECT_KEY_1, 'Bug', item_data) issue = jp.getIssue(issue_key) assert set(issue['Affects Version/s']) == set(['apple', 'lime'])
def test_create_bug_with_single_affects_version_value(): """ create a new Jira Bug with a single valid Affects Version/s value """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) item_data = {'Summary' : 'Narrow morbid futons for sales', 'Affects Version/s' : 'orange' } issue_key = jp.createIssue(PROJECT_KEY_1, 'Bug', item_data) issue = jp.getIssue(issue_key) assert issue['Affects Version/s'] == ['orange']
def test_create_bug_with_target_release_value(): """ create a new Jira Bug with a valid Target Release value """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) item_data = {'Summary' : 'Archery nomads on a rampage for doilies', 'Target Release' : 'lime' } issue_key = jp.createIssue(PROJECT_KEY_1, 'Bug', item_data) issue = jp.getIssue(issue_key) assert issue['Target Release'] == 'lime'
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_obtaining_jira_proxy_instance(): """ will create with new using URL, user, password and project """ with py.test.raises(JiraProxyError) as excinfo: jp = JiraProxy(INCOMPLETE_CONFIG) actual_error_message = excErrorMessage(excinfo) assert actual_error_message == 'JiraProxy requires the config item for password to be present' jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) assert jp is not None
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_project_uses_cached_info(): """ subsequent calls to getProjects returns the cached information """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) projects_initial = jp.getProjects() projects_subsequent = jp.getProjects() assert id(projects_initial) == id(projects_subsequent) assert PROJECT_KEY_1 in projects_subsequent assert projects_subsequent[PROJECT_KEY_1] == PROJECT_NAME_1
def test_get_jira_user_with_info(): """ return a JiraUser with all attributes correctly populated """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) users = jp.getAllUsers() jb_user = [u for u in users if u.name == USERNUM_USER_NAME][0] assert jb_user.display_name == USERNUM_DISPLAY_NAME assert jb_user.email == USERNUM_EMAIL assert jb_user.active == USERNUM_ACTIVE
def test_create_new_issue_via_on_demand_connection(): """ create a minimal JIRA issue via the createIssue method over https """ jp = JiraProxy(GOOD_VANILLA_ONDEMAND_CONFIG) work_item = {"Summary" : "kindergarten hopscotch games"} issue_key = jp.createIssue(ON_DEMAND_PROJECT_KEY_1, "Bug", work_item) issue_key_patt = re.compile(f'{ON_DEMAND_PROJECT_KEY_1}-\\d+') assert issue_key_patt.search(issue_key) is not None jp.deleteIssue(issue_key)
def test_retrieving_jira_server_info(): """ will return a JiraServerInfo """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) assert jp is not None assert jp.jira_version is not None info = jp.getServerInfo() #assert info.url == GOOD_VANILLA_SERVER_CONFIG['url'] assert re.search(r'^https?://\w+', info.url) assert re.search(r'^7\.([2-9])', info.version) or re.search(r'^8\.[0-3][0-9]?\.[0-9]+', info.version)
def test_retrieving_a_valid_jira_user(): """ will return a single JiraUser instance """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) print(f'USER1_USER_NAME: {USER1_USER_NAME}') user = jp.getUser(USER1_USER_NAME) assert user print(user.info()) assert user.name == USER1_USER_NAME assert user.email == USER1_EMAIL
def test_get_standard_fields_list_for_project_key(): """ will return an array of standard field names for an issue type related to a project key """ jp = JiraProxy(GOOD_VANILLA_SERVER_CONFIG) standard_field_names = jp.getStandardFields(PROJECT_KEY_1, "Bug") assert "Summary" in standard_field_names assert "Description" in standard_field_names assert "Affects Version/s" in standard_field_names assert "Assignee" in standard_field_names