Exemple #1
0
class TrelloCollectionTests(unittest.TestCase):
    def setUp(self):
        self.collection = TrelloElementMock.collection()
        self.trello_collection = TrelloCollection(self.collection)

    def test_it_filters_the_closed_elements(self):
        collection = TrelloElementMock.collection()
        collection[0].closed = True
        trello_collection = TrelloCollection(collection)
        self.assertEqual(len(trello_collection.elements), len(collection) - 1)

    def test_names_returns_every_name_from_the_collection(self):
        self.assertEqual(self.trello_collection.names(), ["first", "second"])

    def test_find_gets_an_element_from_the_collection_by_index(self):
        self.assertEqual(self.trello_collection.find(1), self.collection[1])

    def test_on_init_it_gets_the_property_from_the_trello_element(self):
        trello_element = TrelloElementMock("card")
        trello_element.collection = TrelloElementMock.collection()
        collection = TrelloCollection(trello_element, "collection")
        self.assertEqual(collection.elements, trello_element.collection)
class TrelloCollectionTests(unittest.TestCase):
    def setUp(self):
        self.collection = TrelloElementMock.collection()
        self.trello_collection = TrelloCollection(self.collection)

    def test_it_filters_the_closed_elements(self):
        collection = TrelloElementMock.collection()
        collection[0].closed = True
        trello_collection = TrelloCollection(collection)
        self.assertEqual(len(trello_collection.elements), len(collection) - 1)

    def test_names_returns_every_name_from_the_collection(self):
        self.assertEqual(self.trello_collection.names(), ["first", "second"])

    def test_find_gets_an_element_from_the_collection_by_index(self):
        self.assertEqual(self.trello_collection.find(1), self.collection[1])

    def test_on_init_it_gets_the_property_from_the_trello_element(self):
        trello_element = TrelloElementMock("card")
        trello_element.collection = TrelloElementMock.collection()
        collection = TrelloCollection(trello_element, "collection") 
        self.assertEqual(collection.elements, trello_element.collection)
Exemple #3
0
class CardOptions(Executable):
    def __init__(self, card, previous_operation=None):
        self.options = [{
            'name': "..",
            'action': self.go_back
        }, {
            'name': "Open in browser",
            'action': self.open_in_browser
        }, {
            'name': "Insert link",
            'action': self.insert_link
        }, {
            'name': "Show",
            'action': self.show,
            'single_step': True
        }, {
            'name': "Comments",
            'action': self.comments,
            'single_step': True
        }, {
            'name': "Comment",
            'action': self.comment
        }, {
            'name': "Add label",
            'action': self.set_label
        }, {
            'name': "Remove label",
            'action': self.clear_label
        }, {
            'name': "Move to another list",
            'action': self.move
        }, {
            'name': "Archive",
            'action': self.close,
            'single_step': True
        }, {
            'name': "Exit",
            'action': self.noop
        }]
        self.trello_element = self.card = card
        self.previous_operation = previous_operation

    def items(self):
        return [option['name'] for option in self.options]

    def callback(self, index):
        option = self.options[index]
        if not option is None:
            self.command.defer(option['action'])
            if 'single_step' in option:
                self.reexecute()

    # Actions
    def show(self):
        self.command.output(Output.card(self.card))

    def insert_link(self):
        self.command.insert_text(Output.link(self.card.short_url))

    def comments(self):
        self.command.output(Output.comments(self.card.comments()))

    def comment(self):
        self.run_action_with_callback("Comment text", self.card.add_comment)

    def set_label(self):
        self.run_action_with_callback(self.label_input_text(),
                                      self.card.set_label)

    def clear_label(self):
        self.run_action_with_callback(self.label_input_text(),
                                      self.card.clear_label)

    def run_action_with_callback(self, input_text, callback):
        def action(text=None):
            if text is None:
                self.command.input(input_text, action)
            else:
                self.command.defer(lambda: callback(text))
                self.card.reload()
                self.reexecute()

        action()

    def move(self, index=None):
        if index is None:
            self.list_collection = TrelloCollection(self.card.board, "lists")
            self.command.display(self.list_collection.names(), self.move)
        else:
            selected_list = self.list_collection.find(index)
            self.command.defer(lambda: self.card.move_to_list(selected_list))
            selected_list.reload()
            self.reexecute()

    def close(self):
        self.card.close()
        self.card.list.reload()

    def noop(self):
        pass

    def label_input_text(self):
        valid_label_colors = [
            'green', 'yellow', 'orange', 'red', 'purple', 'blue'
        ]
        current_colors = [label['color'] for label in self.card.labels]
        available_choices = [
            label + ("*" if label in current_colors else "")
            for label in valid_label_colors
        ]

        return "Colors (* is active): " + ", ".join(available_choices)
class CardOptions(Executable):
    def __init__(self, card, previous_operation = None):
        self.options = [
            { 'name': "..", 'action': self.go_back },
            { 'name': "Open in Browser", 'action': self.open_in_browser },
            { 'name': "Show", 'action': self.show, 'single_step': True },
            { 'name': "Comments", 'action': self.comments, 'single_step': True },
            { 'name': "Comment", 'action': self.comment },
            { 'name': "Add label", 'action': self.set_label },
            { 'name': "Remove label", 'action': self.clear_label },
            { 'name': "Move to another List", 'action': self.move },
            { 'name': "Archive", 'action': self.close, 'single_step': True },
            { 'name': "Exit", 'action': self.noop }
        ]
        self.trello_element = self.card = card
        self.previous_operation = previous_operation

    def items(self):
        return [option['name'] for option in self.options]

    def callback(self, index):
        option = self.options[index]
        if not option is None:
            self.command.defer(option['action'])
            if 'single_step' in option:
                self.reexecute()

    # Actions
    def show(self):
        self.command.output(Output.card(self.card))

    def comments(self):
        self.command.output(Output.comments(self.card.comments()))

    def comment(self):
        self.run_action_with_callback("Comment text", self.card.add_comment)

    def set_label(self):
        self.run_action_with_callback(self.label_input_text(), self.card.set_label)

    def clear_label(self):
        self.run_action_with_callback(self.label_input_text(), self.card.clear_label)

    def run_action_with_callback(self, input_text, callback):
        def action(text = None):
            if text is None:
                self.command.input(input_text, action)
            else:
                self.command.defer(lambda: callback(text))
                self.card.reload()
                self.reexecute()

        action()

    def move(self, index = None):
        if index is None:
            self.list_collection = TrelloCollection(self.card.board, "lists")
            self.command.display(self.list_collection.names(), self.move)
        else:
            selected_list = self.list_collection.find(index)
            self.command.defer(lambda: self.card.move_to_list(selected_list))
            selected_list.reload()
            self.reexecute()

    def close(self):
        self.card.close()
        self.card.list.reload()

    def noop(self):
        pass

    def label_input_text(self):
        valid_label_colors = ['green', 'yellow', 'orange', 'red', 'purple', 'blue']
        current_colors = [label['color'] for label in self.card.labels]
        available_choices = [label + ("*" if label in current_colors else "") for label in valid_label_colors]
        
        return "Colors (* is active): " + ", ".join(available_choices)