mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	Generated by `pyupgrade --py3-plus --keep-percent-format` on all our Python code except `zthumbor` and `zulip-ec2-configure-interfaces`, followed by manual indentation fixes. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
		
			
				
	
	
		
			134 lines
		
	
	
		
			8.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			134 lines
		
	
	
		
			8.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from mock import MagicMock, patch
 | 
						|
 | 
						|
from zerver.lib.test_classes import WebhookTestCase
 | 
						|
 | 
						|
 | 
						|
class TrelloHookTests(WebhookTestCase):
 | 
						|
    STREAM_NAME = 'trello'
 | 
						|
    URL_TEMPLATE = "/api/v1/external/trello?stream={stream}&api_key={api_key}"
 | 
						|
    FIXTURE_DIR_NAME = 'trello'
 | 
						|
 | 
						|
    def test_trello_confirmation_request(self) -> None:
 | 
						|
        response = self.client_head(self.build_webhook_url())
 | 
						|
        self.assertEqual(response.status_code, 200, response)
 | 
						|
 | 
						|
    def test_trello_webhook_when_card_was_moved_to_another_list(self) -> None:
 | 
						|
        expected_message = "TomaszKolek moved [This is a card.](https://trello.com/c/r33ylX2Z) from Basics to Intermediate."
 | 
						|
        self.send_and_test_stream_message('changing_cards_list', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_card_was_renamed(self) -> None:
 | 
						|
        expected_message = "TomaszKolek renamed the card from \"Old name\" to [New name](https://trello.com/c/r33ylX2Z)."
 | 
						|
        self.send_and_test_stream_message('renaming_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_label_was_added_to_card(self) -> None:
 | 
						|
        expected_message = "TomaszKolek added a green label with \"text value\" to [Card name](https://trello.com/c/r33ylX2Z)."
 | 
						|
        self.send_and_test_stream_message('adding_label_to_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_label_was_removing_from_card(self) -> None:
 | 
						|
        expected_message = "TomaszKolek removed a green label with \"text value\" from [New Card](https://trello.com/c/r33ylX2Z)."
 | 
						|
        self.send_and_test_stream_message('removing_label_from_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_member_was_added_to_card(self) -> None:
 | 
						|
        expected_message = "TomaszKolek added TomaszKolek to [Card name](https://trello.com/c/9BduUcVQ)."
 | 
						|
        self.send_and_test_stream_message('adding_member_to_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_member_was_removed_from_card(self) -> None:
 | 
						|
        expected_message = "TomaszKolek removed Trello from [Card name](https://trello.com/c/9BduUcVQ)."
 | 
						|
        self.send_and_test_stream_message('removing_member_from_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_due_date_was_set(self) -> None:
 | 
						|
        expected_message = "TomaszKolek set due date for [Card name](https://trello.com/c/9BduUcVQ) to 2016-05-11 10:00:00 UTC."
 | 
						|
        self.send_and_test_stream_message('setting_due_date_to_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_due_date_was_changed(self) -> None:
 | 
						|
        expected_message = "TomaszKolek changed due date for [Card name](https://trello.com/c/9BduUcVQ) from 2016-05-11 10:00:00 UTC to 2016-05-24 10:00:00 UTC."
 | 
						|
        self.send_and_test_stream_message('changing_due_date_on_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_due_date_was_removed(self) -> None:
 | 
						|
        expected_message = "TomaszKolek removed the due date from [Card name](https://trello.com/c/9BduUcVQ)."
 | 
						|
        self.send_and_test_stream_message('removing_due_date_from_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_card_was_archived(self) -> None:
 | 
						|
        expected_message = "TomaszKolek archived [Card name](https://trello.com/c/9BduUcVQ)."
 | 
						|
        self.send_and_test_stream_message('archiving_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_card_was_reopened(self) -> None:
 | 
						|
        expected_message = "TomaszKolek reopened [Card name](https://trello.com/c/9BduUcVQ)."
 | 
						|
        self.send_and_test_stream_message('reopening_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_card_was_created(self) -> None:
 | 
						|
        expected_message = "TomaszKolek created [New card](https://trello.com/c/5qrgGdD5)."
 | 
						|
        self.send_and_test_stream_message('creating_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_attachment_was_added_to_card(self) -> None:
 | 
						|
        expected_message = "TomaszKolek added [attachment_name](http://url.com) to [New card](https://trello.com/c/xPKXoSTQ)."
 | 
						|
        self.send_and_test_stream_message('adding_attachment_to_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_checklist_was_added_to_card(self) -> None:
 | 
						|
        expected_message = "TomaszKolek added the Checklist checklist to [New card](https://trello.com/c/xPKXoSTQ)."
 | 
						|
        self.send_and_test_stream_message('adding_checklist_to_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_check_item_is_checked(self) -> None:
 | 
						|
        expected_message = "Eeshan Garg checked **Tomatoes** in **Checklist** ([Something something](https://trello.com/c/R2thJK3P))."
 | 
						|
        self.send_and_test_stream_message('check_item_on_card_checklist', "Zulip", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_check_item_is_unchecked(self) -> None:
 | 
						|
        expected_message = "Eeshan Garg unchecked **Tomatoes** in **Checklist** ([Something something](https://trello.com/c/R2thJK3P))."
 | 
						|
        self.send_and_test_stream_message('uncheck_item_on_card_checklist', "Zulip", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_member_was_removed_from_board(self) -> None:
 | 
						|
        expected_message = "TomaszKolek removed Trello from [Welcome Board](https://trello.com/b/iqXXzYEj)."
 | 
						|
        self.send_and_test_stream_message('removing_member_from_board', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_member_was_added_to_board(self) -> None:
 | 
						|
        expected_message = "TomaszKolek added Trello to [Welcome Board](https://trello.com/b/iqXXzYEj)."
 | 
						|
        self.send_and_test_stream_message('adding_member_to_board', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_list_was_added_to_board(self) -> None:
 | 
						|
        expected_message = "TomaszKolek added New list list to [Welcome Board](https://trello.com/b/iqXXzYEj)."
 | 
						|
        self.send_and_test_stream_message('adding_new_list_to_board', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_comment_was_added_to_card(self) -> None:
 | 
						|
        expected_message = "TomaszKolek commented on [New card](https://trello.com/c/xPKXoSTQ):\n~~~ quote\nNew comment\n~~~"
 | 
						|
        self.send_and_test_stream_message('adding_comment_to_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_board_was_renamed(self) -> None:
 | 
						|
        expected_message = "TomaszKolek renamed the board from Welcome Board to [New name](https://trello.com/b/iqXXzYEj)."
 | 
						|
        self.send_and_test_stream_message('renaming_board', "New name", expected_message)
 | 
						|
 | 
						|
    @patch('zerver.webhooks.trello.view.check_send_webhook_message')
 | 
						|
    def test_trello_webhook_when_card_is_moved_within_single_list_ignore(
 | 
						|
            self, check_send_webhook_message_mock: MagicMock) -> None:
 | 
						|
        payload = self.get_body('moving_card_within_single_list')
 | 
						|
        result = self.client_post(self.url, payload, content_type="application/json")
 | 
						|
        self.assertFalse(check_send_webhook_message_mock.called)
 | 
						|
        self.assert_json_success(result)
 | 
						|
 | 
						|
    @patch('zerver.webhooks.trello.view.check_send_webhook_message')
 | 
						|
    def test_trello_webhook_when_board_background_is_changed_ignore(
 | 
						|
            self, check_send_webhook_message_mock: MagicMock) -> None:
 | 
						|
        payload = self.get_body('change_board_background_image')
 | 
						|
        result = self.client_post(self.url, payload, content_type="application/json")
 | 
						|
        self.assertFalse(check_send_webhook_message_mock.called)
 | 
						|
        self.assert_json_success(result)
 | 
						|
 | 
						|
    @patch('zerver.webhooks.trello.view.check_send_webhook_message')
 | 
						|
    def test_create_card_check_item_ignore(
 | 
						|
            self, check_send_webhook_message_mock: MagicMock) -> None:
 | 
						|
        payload = self.get_body('create_check_item')
 | 
						|
        result = self.client_post(self.url, payload, content_type="application/json")
 | 
						|
        self.assertFalse(check_send_webhook_message_mock.called)
 | 
						|
        self.assert_json_success(result)
 | 
						|
 | 
						|
    def test_trello_webhook_when_description_was_added_to_card(self) -> None:
 | 
						|
        expected_message = "Marco Matarazzo set description for [New Card](https://trello.com/c/P2r0z66z) to:\n~~~ quote\nNew Description\n~~~"
 | 
						|
        self.send_and_test_stream_message('adding_description_to_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_description_was_removed_from_card(self) -> None:
 | 
						|
        expected_message = "Marco Matarazzo removed description from [New Card](https://trello.com/c/P2r0z66z)."
 | 
						|
        self.send_and_test_stream_message('removing_description_from_card', "Welcome Board", expected_message)
 | 
						|
 | 
						|
    def test_trello_webhook_when_description_was_changed_on_card(self) -> None:
 | 
						|
        expected_message = "Marco Matarazzo changed description for [New Card](https://trello.com/c/P2r0z66z) from\n~~~ quote\nNew Description\n~~~\nto\n~~~ quote\nChanged Description\n~~~"
 | 
						|
        self.send_and_test_stream_message('changing_description_on_card', "Welcome Board", expected_message)
 |