Skip to content

Commit

Permalink
style: [FC-0047] fix code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedielnitsevIvan committed Jul 23, 2024
1 parent 5f52163 commit b18c55a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion edx_ace/ace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions edx_ace/channel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 10 additions & 10 deletions edx_ace/tests/channel/test_push_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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):
"""
Expand All @@ -162,12 +162,12 @@ 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):
"""
Test that the get_user_device_tokens method returns an empty list when the user has no device tokens.
"""
channel = PushNotificationChannel()
tokens = channel.get_user_device_tokens(self.lms_user_id)
self.assertEqual(tokens, [])
assert tokens == []
2 changes: 1 addition & 1 deletion edx_ace/tests/test_ace.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_ace_send_skip_limited_channel(self, mock_channels_for, mock_log):
ace.send(msg, limit_to_channels=[ChannelType.EMAIL])

mock_channels_for.assert_called_once_with(msg)
mock_log.info.assert_called_once_with('Skipping channel %s', ChannelType.PUSH)
mock_log.debug.assert_called_once_with('Skipping channel %s', ChannelType.PUSH)

@patch('edx_ace.ace.presentation.render', side_effect=TemplateDoesNotExist('template not found'))
def test_ace_send_template_does_not_exists(self, *_args):
Expand Down

0 comments on commit b18c55a

Please sign in to comment.