From ca71f8fc478a775721f4a3a88aeb142743803755 Mon Sep 17 00:00:00 2001 From: jerrychuang Date: Sat, 23 Dec 2023 22:43:59 +0800 Subject: [PATCH] Fix the CI error --- tests/test_cli.py | 123 ++++++++++++++++++++++++++++------------------ 1 file changed, 75 insertions(+), 48 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index a816cb2..5f08fd9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -8,91 +8,118 @@ class TestCli(unittest.TestCase): def setUp(self): self.runner = CliRunner() - self.token = 'YgVGZjHTprZdsooj5xOGXBl9vVwLGBEbjyjaBWY1Mbe' + self.token = "YgVGZjHTprZdsooj5xOGXBl9vVwLGBEbjyjaBWY1Mbe" self.bot_origin = "https://notify-bot.line.me" self.api_origin = "https://notify-api.line.me" @responses.activate - @patch('lotify.client.Client') + @patch("lotify.client.Client") def test_check_status(self, mock_client): responses.add( responses.GET, - '{url}/api/status'.format(url=self.api_origin), - json={ - 'status': 200, - 'message': 'ok' - }, - status=200 + "{url}/api/status".format(url=self.api_origin), + json={"status": 200, "message": "ok"}, + status=200, + ) + mock_client.status.return_value = {"status": 200, "message": "ok"} + result = self.runner.invoke( + send_message, ["--check-status", "--access_token", self.token] ) - mock_client.status.return_value = {'status': 200, 'message': 'ok'} - result = self.runner.invoke(send_message, ['--check-status', '--access_token', self.token]) self.assertEqual(result.output, "Status: {'status': 200, 'message': 'ok'}\n") @responses.activate - @patch('lotify.client.Client') + @patch("lotify.client.Client") def test_send_message(self, mock_client): responses.add( responses.POST, - '{url}/api/notify'.format(url=self.api_origin), - json={ - 'status': 200, - 'message': 'ok' - }, - status=200 + "{url}/api/notify".format(url=self.api_origin), + json={"status": 200, "message": "ok"}, + status=200, + ) + mock_client.send_message.return_value = {"status": 200, "message": "ok"} + result = self.runner.invoke( + send_message, ["--access_token", self.token, "--message", "Hello"] ) - mock_client.send_message.return_value = {'status': 200, 'message': 'ok'} - result = self.runner.invoke(send_message, ['--access_token', self.token, '--message', 'Hello']) self.assertEqual(result.output, "Send notification success.\n") @responses.activate - @patch('lotify.client.Client') + @patch("lotify.client.Client") def test_send_image_with_image_url(self, mock_client): responses.add( responses.POST, - '{url}/api/notify'.format(url=self.api_origin), - json={ - 'status': 200, - 'message': 'ok' - }, - status=200 + "{url}/api/notify".format(url=self.api_origin), + json={"status": 200, "message": "ok"}, + status=200, + ) + mock_client.send_message_with_image_url.return_value = { + "status": 200, + "message": "ok", + } + result = self.runner.invoke( + send_message, + [ + "--access_token", + self.token, + "--message", + "Hello", + "--image-url", + "https://example.com/image.png", + ], ) - mock_client.send_message_with_image_url.return_value = {'status': 200, 'message': 'ok'} - result = self.runner.invoke(send_message, ['--access_token', self.token, '--message', 'Hello', '--image-url', 'https://example.com/image.png']) self.assertEqual(result.output, "Send notification success.\n") @responses.activate - @patch('lotify.client.Client') + @patch("lotify.client.Client") def test_send_image_with_image_file(self, mock_client): responses.add( responses.POST, - '{url}/api/notify'.format(url=self.api_origin), - json={ - 'status': 200, - 'message': 'ok' - }, - status=200 + "{url}/api/notify".format(url=self.api_origin), + json={"status": 200, "message": "ok"}, + status=200, ) with self.runner.isolated_filesystem(): - with open('image.png', 'w') as f: - f.write('This is file object') - mock_client.send_message_with_image_file.return_value = {'status': 200, 'message': 'ok'} - result = self.runner.invoke(send_message, ['--access_token', self.token, '--message', 'Hello', '--image-file', 'image.png']) + with open("image.png", "w") as f: + f.write("This is file object") + mock_client.send_message_with_image_file.return_value = { + "status": 200, + "message": "ok", + } + result = self.runner.invoke( + send_message, + [ + "--access_token", + self.token, + "--message", + "Hello", + "--image-file", + "image.png", + ], + ) self.assertEqual(result.output, "Send notification success.\n") @responses.activate - @patch('lotify.client.Client') + @patch("lotify.client.Client") def test_send_sticker_message(self, mock_client): responses.add( responses.POST, - '{url}/api/notify'.format(url=self.api_origin), - json={ - 'status': 200, - 'message': 'ok' - }, - status=200 + "{url}/api/notify".format(url=self.api_origin), + json={"status": 200, "message": "ok"}, + status=200, + ) + mock_client.send_sticker_message.return_value = {"status": 200, "message": "ok"} + result = self.runner.invoke( + send_message, + [ + "--access_token", + self.token, + "--message", + "Hello", + "--sticker-package-id", + "1", + "--sticker-id", + "1", + ], ) - mock_client.send_sticker_message.return_value = {'status': 200, 'message': 'ok'} - result = self.runner.invoke(send_message, ['--access_token', self.token, '--message', 'Hello', '--sticker-package-id', '1', '--sticker-id', '1']) self.assertEqual(result.output, "Send notification success.\n")