Beispiel #1
0
    def test_inactive_cards_url_when_http_error(self, mock_url_open):
        """ Test that when there is an HTTP error during retrieval, it returns an empty list as inactive cards. """
        mock_url_open.side_effect = urllib.error.HTTPError(
            None, None, None, None, None)
        trello_board = TrelloBoard('appkeyX', 'tokenX')

        self.assertEqual([], trello_board.inactive_cards_url('board_id'))
Beispiel #2
0
    def test_inactive_cards_url_without_last_activity(self, mock_url_read):
        """ Test that it raises key error exception when there is no dateLastActivity. """

        mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                     '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": ' \
                                     '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", "due": null}]}'
        trello_board = TrelloBoard('appkeyX', 'tokenX')

        self.assertRaises(KeyError, lambda: trello_board.inactive_cards_url('board_id'))
Beispiel #3
0
    def test_inactive_cards_url_without_last_activity(self, mock_url_read):
        """ Test that it raises key error exception when there is no dateLastActivity. """

        mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                     '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": ' \
                                     '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", "due": null}]}'
        trello_board = TrelloBoard('appkeyX', 'tokenX')

        self.assertRaises(KeyError,
                          lambda: trello_board.inactive_cards_url('board_id'))
Beispiel #4
0
    def test_inactive_cards_url_when_empty(self, mock_url_read):
        """ Test that when there are no cards at all it returns an empty list as inactive. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 9)
            mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                         '"url": "", "lists": [], "cards": []}'
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('board_id')

        self.assertEqual([], result)
Beispiel #5
0
    def test_inactive_cards_url_when_empty(self, mock_url_read):
        """ Test that when there are no cards at all it returns an empty list as inactive. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 9)
            mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                         '"url": "", "lists": [], "cards": []}'
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('board_id')

        self.assertEqual([], result)
Beispiel #6
0
    def test_inactive_cards_url_with_last_activity_null(self, mock_url_read):
        """ Test that the card with dateLastActivity equal to null is not counted as inactive. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 21)
            mock_date.max = datetime.max

            mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                         '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": ' \
                                         '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", ' \
                                         '"dateLastActivity": null, "due": null}]}'
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('board_id')

        self.assertEqual([], result)
Beispiel #7
0
    def test_inactive_cards_url_invalid_last_activity_date(self, mock_url_read):
        """ Test the cards without due date and invalid last activity date are not considered inactive. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 21)
            mock_date.max = datetime.max

            mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                         '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": ' \
                                         '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", ' \
                                         '"dateLastActivity": "2018-99-88T11:00:00.000Z"}]}'
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('board_id')

        self.assertEqual([], result)
Beispiel #8
0
    def test_inactive_cards_url_less_without_due_date(self, mock_url_read):
        """ Test the urls for the over due cards. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 21)
            mock_date.side_effect = lambda *args, **kw: datetime(*args, **kw)

            mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                         '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": ' \
                                         '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", ' \
                                         '"dateLastActivity": "2018-03-15T11:00:00.000Z"}]}'
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('board_id')

        self.assertEqual([], result)
Beispiel #9
0
    def test_inactive_cards_url_less_without_due_date(self, mock_url_read):
        """ Test the urls for the over due cards. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 21)
            mock_date.side_effect = lambda *args, **kw: datetime(*args, **kw)

            mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                         '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": ' \
                                         '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", ' \
                                         '"dateLastActivity": "2018-03-15T11:00:00.000Z"}]}'
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('board_id')

        self.assertEqual([], result)
Beispiel #10
0
    def test_inactive_cards_url_custom_term(self, mock_url_read):
        """ Test the card is considered active or inactive according to the custom interval. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 21)
            mock_date.side_effect = lambda *args, **kw: datetime(*args, **kw)

            mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                         '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": ' \
                                         '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", ' \
                                         '"dateLastActivity": "2018-03-06T11:00:00.000Z", "due": null}]}'
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('board_id', days=15)

        self.assertEqual([], result)
Beispiel #11
0
    def test_inactive_cards_url_with_last_activity_null(self, mock_url_read):
        """ Test that the card with dateLastActivity equal to null is not counted as inactive. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 21)
            mock_date.max = datetime.max

            mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                         '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": ' \
                                         '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", ' \
                                         '"dateLastActivity": null, "due": null}]}'
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('board_id')

        self.assertEqual([], result)
Beispiel #12
0
    def test_inactive_cards_url_custom_term(self, mock_url_read):
        """ Test the card is considered active or inactive according to the custom interval. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 21)
            mock_date.side_effect = lambda *args, **kw: datetime(*args, **kw)

            mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                         '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": ' \
                                         '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", ' \
                                         '"dateLastActivity": "2018-03-06T11:00:00.000Z", "due": null}]}'
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('board_id', days=15)

        self.assertEqual([], result)
Beispiel #13
0
    def test_inactive_cards_url_invalid_last_activity_date(
            self, mock_url_read):
        """ Test the cards without due date and invalid last activity date are not considered inactive. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 21)
            mock_date.max = datetime.max

            mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                         '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": ' \
                                         '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", ' \
                                         '"dateLastActivity": "2018-99-88T11:00:00.000Z"}]}'
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('board_id')

        self.assertEqual([], result)
Beispiel #14
0
    def test_inactive_cards_url_already_due(self, mock_url_read):
        """ Test the card already due and with last activity before (default) 14 days is considered as inactive. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 21)
            mock_date.side_effect = lambda *args, **kw: datetime(*args, **kw)

            mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                         '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": ' \
                                         '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", ' \
                                         '"dateLastActivity": "2018-03-05T11:00:00.000Z", ' \
                                         '"due": "2018-03-20T11:00:00.000Z"}]}'
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('board_id')

        self.assertEqual([('http://shortUrl', "Test card!", '15 dagen')], result)
Beispiel #15
0
    def test_inactive_cards_url_already_due(self, mock_url_read):
        """ Test the card already due and with last activity before (default) 14 days is considered as inactive. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 21)
            mock_date.side_effect = lambda *args, **kw: datetime(*args, **kw)

            mock_url_read.return_value = '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", ' \
                                         '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": ' \
                                         '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", ' \
                                         '"dateLastActivity": "2018-03-05T11:00:00.000Z", ' \
                                         '"due": "2018-03-20T11:00:00.000Z"}]}'
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('board_id')

        self.assertEqual([('http://shortUrl', "Test card!", '15 dagen')],
                         result)
Beispiel #16
0
    def test_inactive_cards_url_more_boards(self, mock_url_read):
        """ Test the inactive cards of more than one board are returned together. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 21)
            mock_date.side_effect = lambda *args, **kw: datetime(*args, **kw)

            mock_url_read.side_effect = ['{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", '
                                         '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": '
                                         '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", '
                                         '"dateLastActivity": "2018-03-05T11:00:00.000Z"}]}',
                                         '{"id": "x2", "dateLastActivity":"2018-03-05T11:00:00.000Z", '
                                         '"url": "", "lists": [], "cards": [{"id": "card_2", "idList": '
                                         '"l2", "name": "Card 2", "shortUrl": "http://shortUrl2", '
                                         '"dateLastActivity": "2018-03-01T11:00:00.000Z"}]}']
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('x', 'x2')

        self.assertEqual([('http://shortUrl', "Test card!", '15 dagen'),
                          ('http://shortUrl2', "Card 2", '19 dagen')], result)
Beispiel #17
0
    def test_inactive_cards_url_more_boards(self, mock_url_read):
        """ Test the inactive cards of more than one board are returned together. """
        from datetime import datetime
        with patch(__name__ + '.datetime.datetime') as mock_date:
            mock_date.now.return_value = datetime(2018, 3, 21)
            mock_date.side_effect = lambda *args, **kw: datetime(*args, **kw)

            mock_url_read.side_effect = [
                '{"id": "x", "dateLastActivity":"2018-03-05T11:00:00.000Z", '
                '"url": "", "lists": [], "cards": [{"id": "card_id", "idList": '
                '"xx", "name": "Test card!", "shortUrl": "http://shortUrl", '
                '"dateLastActivity": "2018-03-05T11:00:00.000Z"}]}',
                '{"id": "x2", "dateLastActivity":"2018-03-05T11:00:00.000Z", '
                '"url": "", "lists": [], "cards": [{"id": "card_2", "idList": '
                '"l2", "name": "Card 2", "shortUrl": "http://shortUrl2", '
                '"dateLastActivity": "2018-03-01T11:00:00.000Z"}]}'
            ]
            trello_board = TrelloBoard('appkeyX', 'tokenX')

            result = trello_board.inactive_cards_url('x', 'x2')

        self.assertEqual([('http://shortUrl', "Test card!", '15 dagen'),
                          ('http://shortUrl2', "Card 2", '19 dagen')], result)
Beispiel #18
0
    def test_inactive_cards_url_when_http_error(self, mock_url_open):
        """ Test that when there is an HTTP error during retrieval, it returns an empty list as inactive cards. """
        mock_url_open.side_effect = urllib.error.HTTPError(None, None, None, None, None)
        trello_board = TrelloBoard('appkeyX', 'tokenX')

        self.assertEqual([], trello_board.inactive_cards_url('board_id'))