def test_create_card(self): target_list = mock.MagicMock() target_list.list_cards.return_value = [] cards.create_card( target_list, "test", "test", labels=['test'], due="null") target_list.add_card.assert_called_with( "test", "test", ['test'], "null")
def test_create_card(self): self.mock_list.list_cards.return_value = [] cards.create_card(target_list=self.mock_list, title="test_card", description="test_card_desc", labels=["test_label"], due="null") self.mock_list.add_card.assert_called_with( "test_card", "test_card_desc", ["test_label"], "null")
def test_create_card_duplicate(self): duplicate_card = trello.Card(self.mock_list, None, "test_card") duplicate_card.description = "duplicate card" self.mock_list.list_cards.return_value = [duplicate_card] cards.create_card(target_list=self.mock_list, title="test_card", description="duplicate card", labels=["test_label"], due="null") self.mock_list.add_card.assert_not_called()
def test_create_card_duplicate(self): target_list = mock.MagicMock() duplicate = trello.Card(target_list, None, 'test') duplicate.description = 'test' target_list.list_cards.return_value = [ duplicate, ] result = cards.create_card( target_list, "test", "test", labels=['test'], due="null") target_list.add_card.assert_not_called()
def importer(service, id, url, host, user, password, project, board, labels, list_name): try: config = configuration.get_config() except Exception as err: click.echo(err) sys.exit(1) trello_key = config['trello']['api_key'] trello_token = config['trello']['access_token'] if not board: if 'default_board' not in config['trello']: click.echo("No default_board exists in ~/filch.conf") click.echo("You must either set a default_board in ~/filch.conf " "or use the --board_name option.") sys.exit(1) else: board = config['trello']['default_board'] trello_api = trelloclient.TrelloClient( api_key=config['trello']['api_key'], token=config['trello']['access_token'] ) board_obj = [b for b in trello_api.list_boards() if b.name == board][0] # ensure labels being used are actually in the board card_labels = [label for label in board_obj.get_labels() if label.name in list(labels)] # ensure list name exists in board board_list = [trello_list for trello_list in board_obj.open_lists() if trello_list.name == list_name][0] if service == 'gerrit': # default to upstream openstack # if host is present then use that # if url is present then use that gerrit_url = "https://review.openstack.org" if host: gerrit_url = config['gerrit'][host]['url'] if url: gerrit_url = url gerrit_api = GerritRestAPI(url=gerrit_url, auth=None) for change_id in list(id): change = gerrit_api.get("/changes/%s" % change_id) cards.create_card( board_list, change['subject'], constants.GERRIT_CARD_DESC.format(**change), labels=card_labels, due="null", ) click.echo( 'You have successfully imported "%s"' % change['subject']) if service == 'blueprint': if not project: click.echo('To import a blueprint you must provide a project.') sys.exit(1) for bp_id in list(id): blueprint = utils.get_blueprint(project, bp_id) cards.create_card( board_list, blueprint['title'], constants.BLUEPRINT_CARD_DESC.format(**blueprint), labels=card_labels, due="null", ) click.echo( 'You have successfully imported "%s"' % blueprint['title']) if service == 'bug': for bug_id in list(id): bug = utils.get_launchpad_bug(bug_id) cards.create_card( board_list, bug['title'], constants.BUG_CARD_DESC.format(**bug), labels=card_labels, due="null", ) click.echo( 'You have successfully imported "%s"' % bug['title']) if service == 'story': for story_id in list(id): story = utils.get_storyboard_story(story_id) cards.create_card( board_list, story['title'], constants.STORY_CARD_DESC.format(**story), labels=card_labels, due="null", ) click.echo( 'You have successfully imported "%s"' % story['title']) if service in ['bz', 'bugzilla']: if url: # also need user & password. sslverify is optional if not user or not password: click.echo("If using a url for Bugzilla, you must also " "provide a user and password.") sys.exit(1) # if host arg is not used, use first host from # configuration as default if not host: # check to ensure a host for bugzilla exists in config if len(config['bugzilla'].keys()) == 0: click.echo("No Bugzilla data configuration file. Please " "add configuration data or pass url, user and " "password arguments.") sys.exit(1) else: host = list(config['bugzilla'].keys())[0] url = config['bugzilla'][host]['url'] user = config['bugzilla'][host]['user'] sslverify = config['bugzilla'][host].get('sslverify', True) for bz_id in list(id): try: bug = utils.get_bz(bz_id, url=url, user=user, password=password, sslverify=sslverify) if len(bug.comments) > 0: bug.description = bug.comments[0]['text'] bug_card = cards.create_card( board_list, bug.summary, constants.BZ_CARD_DESC.format(**bug.__dict__), labels=card_labels, due="null", ) # adds comments to a card if len(bug.comments) > 1: for comment in bug.comments[1:]: bug_card.comment(constants.COMMENT_TEXT.format( text=comment['text'], author=comment['author'], create_time=comment['creation_time'], is_private=constants.COMMENT_PRIVACY[ comment['is_private'] ], )) # adds external trackers to card if len(bug.external_bugs) > 0: external_trackers = [] for ext_bug in bug.external_bugs: external_trackers.append( os.path.join(ext_bug['type']['url'], ext_bug['ext_bz_bug_id']) ) bug_card.add_checklist( 'External Trackers', external_trackers ) click.echo('You have successfully imported "%s"' % bug.summary) except Exception as err: click.echo(err) if service == 'debug': ids = list(id) print(ids)
def importer(service, id, url, host, user, password, project, board, labels, list_name): config = configuration.get_config() trello_key = config['trello']['api_key'] trello_token = config['trello']['access_token'] if not board: if 'default_board' not in config['trello']: click.echo("No default_board exists in ~/filch.conf") click.echo("You must either set a default_board in ~/filch.conf " "or use the --board_name option.") sys.exit(1) else: board = config['trello']['default_board'] if service == 'gerrit': # default to upstream openstack # if host is present then use that # if url is present then use that gerrit_url = "https://review.openstack.org" if host: gerrit_url = config['gerrit'][host]['url'] if url: gerrit_url = url gerrit_api = GerritRestAPI(url=gerrit_url, auth=None) for change_id in list(id): change = gerrit_api.get("/changes/%s" % change_id) cards.create_card(trello_key, trello_token, board, change['subject'], constants.GERRIT_CARD_DESC.format(**change), card_labels=list(labels), card_due="null", list_name=list_name) click.echo('You have successfully imported "%s"' % change['subject']) if service == 'blueprint': if not project: click.echo('To import a blueprint you must provide a project.') sys.exit(1) for bp_id in list(id): blueprint = utils.get_blueprint(project, bp_id) cards.create_card( trello_key, trello_token, board, blueprint['title'], constants.BLUEPRINT_CARD_DESC.format(**blueprint), card_labels=list(labels), card_due="null", list_name=list_name) click.echo('You have successfully imported "%s"' % blueprint['title']) if service == 'bug': for bug_id in list(id): bug = utils.get_launchpad_bug(bug_id) cards.create_card(trello_key, trello_token, board, bug['title'], constants.BUG_CARD_DESC.format(**bug), card_labels=list(labels), card_due="null", list_name=list_name) click.echo('You have successfully imported "%s"' % bug['title']) if service in ['bz', 'bugzilla']: if url: # also need user & password. sslverify is optional if not user or not password: click.echo("If using a url for Bugzilla, you must also " "provide a user and password.") sys.exit(1) # if host arg is not used, use first host from # configuration as default if not host: # check to ensure a host for bugzilla exists in config if len(config['bugzilla'].keys()) == 0: click.echo("No Bugzilla data configuration file. Please " "add configuration data or pass url, user and " "password arguments.") sys.exit(1) else: host = config['bugzilla'].keys()[0] url = config['bugzilla'][host]['url'] user = config['bugzilla'][host]['user'] sslverify = config['bugzilla'][host].get('sslverify', True) for bz_id in list(id): try: bug = utils.get_bz(bz_id, url=url, user=user, password=password, sslverify=sslverify) if len(bug.comments) > 0: bug.description = bug.comments[0]['text'] cards.create_card( trello_key, trello_token, board, bug.summary, constants.BZ_CARD_DESC.format(**bug.__dict__), card_labels=list(labels), card_due="null", list_name=list_name) click.echo('You have successfully imported "%s"' % bug.summary) except Exception as err: click.echo(err) if service == 'debug': ids = list(id) print(ids)
def importer(service, id, url, host, user, password, project, board, labels, list_name): try: config = configuration.get_config() except Exception as err: click.echo(err) sys.exit(1) trello_key = config['trello']['api_key'] trello_token = config['trello']['access_token'] if not board: if 'default_board' not in config['trello']: click.echo("No default_board exists in ~/filch.conf") click.echo("You must either set a default_board in ~/filch.conf " "or use the --board_name option.") sys.exit(1) else: board = config['trello']['default_board'] trello_api = trelloclient.TrelloClient( api_key=config['trello']['api_key'], token=config['trello']['access_token']) board_obj = [b for b in trello_api.list_boards() if b.name == board][0] # ensure labels being used are actually in the board card_labels = [ label for label in board_obj.get_labels() if label.name in list(labels) ] # ensure list name exists in board board_list = [ trello_list for trello_list in board_obj.open_lists() if trello_list.name == list_name ][0] if service == 'gerrit': # default to upstream openstack # if host is present then use that # if url is present then use that gerrit_url = "https://review.openstack.org" if host: gerrit_url = config['gerrit'][host]['url'] if url: gerrit_url = url gerrit_api = GerritRestAPI(url=gerrit_url, auth=None) for change_id in list(id): change = gerrit_api.get("/changes/%s" % change_id) cards.create_card( board_list, change['subject'], constants.GERRIT_CARD_DESC.format(**change), labels=card_labels, due="null", ) click.echo('You have successfully imported "%s"' % change['subject']) if service == 'blueprint': if not project: click.echo('To import a blueprint you must provide a project.') sys.exit(1) for bp_id in list(id): blueprint = utils.get_blueprint(project, bp_id) cards.create_card( board_list, blueprint['title'], constants.BLUEPRINT_CARD_DESC.format(**blueprint), labels=card_labels, due="null", ) click.echo('You have successfully imported "%s"' % blueprint['title']) if service == 'bug': for bug_id in list(id): bug = utils.get_launchpad_bug(bug_id) cards.create_card( board_list, bug['title'], constants.BUG_CARD_DESC.format(**bug), labels=card_labels, due="null", ) click.echo('You have successfully imported "%s"' % bug['title']) if service == 'story': for story_id in list(id): story = utils.get_storyboard_story(story_id) cards.create_card( board_list, story['title'], constants.STORY_CARD_DESC.format(**story), labels=card_labels, due="null", ) click.echo('You have successfully imported "%s"' % story['title']) if service in ['bz', 'bugzilla']: if url: # also need user & password. sslverify is optional if not user or not password: click.echo("If using a url for Bugzilla, you must also " "provide a user and password.") sys.exit(1) # if host arg is not used, use first host from # configuration as default if not host: # check to ensure a host for bugzilla exists in config if len(config['bugzilla'].keys()) == 0: click.echo("No Bugzilla data configuration file. Please " "add configuration data or pass url, user and " "password arguments.") sys.exit(1) else: host = list(config['bugzilla'].keys())[0] url = config['bugzilla'][host]['url'] user = config['bugzilla'][host]['user'] sslverify = config['bugzilla'][host].get('sslverify', True) for bz_id in list(id): try: bug = utils.get_bz(bz_id, url=url, user=user, password=password, sslverify=sslverify) if len(bug.comments) > 0: bug.description = bug.comments[0]['text'] bug_card = cards.create_card( board_list, bug.summary, constants.BZ_CARD_DESC.format(**bug.__dict__), labels=card_labels, due="null", ) # adds comments to a card if len(bug.comments) > 1: for comment in bug.comments[1:]: bug_card.comment( constants.COMMENT_TEXT.format( text=comment['text'], author=comment['author'], create_time=comment['creation_time'], is_private=constants.COMMENT_PRIVACY[ comment['is_private']], )) # adds external trackers to card if len(bug.external_bugs) > 0: external_trackers = [] for ext_bug in bug.external_bugs: external_trackers.append( os.path.join(ext_bug['type']['url'], ext_bug['ext_bz_bug_id'])) bug_card.add_checklist('External Trackers', external_trackers) click.echo('You have successfully imported "%s"' % bug.summary) except Exception as err: click.echo(err) if service == 'debug': ids = list(id) print(ids)