From 84c09dc9f856a6c654ff0417468462fad906d238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=86=D0=B2=D0=B0=D0=BD=20=D0=9D=D1=94=D0=B4=D1=94=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=96=D1=86=D0=B5=D0=B2?= Date: Tue, 23 Jul 2024 18:19:00 +0300 Subject: [PATCH] style: [FC-0047] fix code style issues --- edx_ace/ace.py | 2 +- edx_ace/channel/__init__.py | 3 +-- .../tests/channel/test_push_notification.py | 20 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/edx_ace/ace.py b/edx_ace/ace.py index 99cce4ec..68ff96ac 100644 --- a/edx_ace/ace.py +++ b/edx_ace/ace.py @@ -52,7 +52,7 @@ def send(msg, limit_to_channels=None): for channel_type in channels_for_message: if limit_to_channels and channel_type not in limit_to_channels: - log.info('Skipping channel %s', channel_type) + log.debug('Skipping channel %s', channel_type) try: channel = get_channel_for_message(channel_type, msg) diff --git a/edx_ace/channel/__init__.py b/edx_ace/channel/__init__.py index 171003c6..4efc1624 100644 --- a/edx_ace/channel/__init__.py +++ b/edx_ace/channel/__init__.py @@ -178,8 +178,7 @@ def get_channel_for_message(channel_type, message): channel_names = [settings.ACE_CHANNEL_TRANSACTIONAL_EMAIL, settings.ACE_CHANNEL_DEFAULT_EMAIL] else: channel_names = [settings.ACE_CHANNEL_DEFAULT_EMAIL] - - if channel_type == ChannelType.PUSH: + elif channel_type == ChannelType.PUSH: channel_names = [settings.ACE_CHANNEL_DEFAULT_PUSH] try: diff --git a/edx_ace/tests/channel/test_push_notification.py b/edx_ace/tests/channel/test_push_notification.py index 37dadd23..e7ccdc3b 100644 --- a/edx_ace/tests/channel/test_push_notification.py +++ b/edx_ace/tests/channel/test_push_notification.py @@ -49,14 +49,14 @@ def test_enabled(self): """ Test that the channel is enabled when the settings are configured. """ - self.assertTrue(PushNotificationChannel.enabled()) + assert PushNotificationChannel.enabled() @override_settings(PUSH_NOTIFICATIONS_SETTINGS=None) def test_disabled(self): """ Test that the channel is disabled when the settings are not configured. """ - self.assertFalse(PushNotificationChannel.enabled()) + assert not PushNotificationChannel.enabled() @patch('edx_ace.channel.push_notification.LOG') @patch('edx_ace.channel.push_notification.PushNotificationChannel.send_message') @@ -89,7 +89,7 @@ def test_deliver_with_device_tokens(self, mock_send_message): channel = PushNotificationChannel() channel.deliver(message, rendered_message) - self.assertEqual(mock_send_message.call_count, 2) + assert mock_send_message.call_count == 2 @override_settings(FCM_APP_NAME='test_app') @patch('edx_ace.channel.push_notification.send_message') @@ -129,7 +129,7 @@ def test_send_message_failure( channel = PushNotificationChannel() - with self.assertRaises(FatalChannelDeliveryError): + with pytest.raises(FatalChannelDeliveryError): channel.send_message(message, 'token', rendered_message) mock_send_message.assert_called_with('token', mock_dict_to_fcm_message.return_value, 'test_app') @@ -143,16 +143,16 @@ def test_collect_apns_config(self): apns_config = PushNotificationChannel.collect_apns_config(notification_data) - self.assertIsInstance(apns_config, APNSConfig) - self.assertEqual(apns_config.headers['apns-priority'], '5') - self.assertEqual(apns_config.headers['apns-push-type'], 'alert') + assert isinstance(apns_config, APNSConfig) + assert apns_config.headers['apns-priority'] == '5' + assert apns_config.headers['apns-push-type'] == 'alert' def test_compress_spaces(self): """ Test that the compress_spaces method removes extra spaces and newlines from a string. """ compressed = PushNotificationChannel.compress_spaces('This is a \n\n test.') - self.assertEqual(compressed, 'This is a test.') + assert compressed == 'This is a test.' def test_get_user_device_tokens(self): """ @@ -162,7 +162,7 @@ def test_get_user_device_tokens(self): channel = PushNotificationChannel() tokens = channel.get_user_device_tokens(self.lms_user_id) - self.assertEqual(tokens, [gcm_device.registration_id]) + assert tokens == [gcm_device.registration_id] def test_get_user_device_tokens_no_tokens(self): """ @@ -170,4 +170,4 @@ def test_get_user_device_tokens_no_tokens(self): """ channel = PushNotificationChannel() tokens = channel.get_user_device_tokens(self.lms_user_id) - self.assertEqual(tokens, []) + assert tokens == []