feat!: Update from boto to boto3 storage backend. (#31759)

* feat!: Update from boto to boto3 storage backend
This commit is contained in:
Awais Qureshi
2023-02-21 14:26:54 +05:00
committed by GitHub
parent d694b70439
commit 31002ab0d5
6 changed files with 15 additions and 11 deletions

View File

@@ -3,7 +3,7 @@ Celery tasks used by cms_user_tasks
"""
import json
from boto.exception import NoAuthHandlerFound
import botocore
from celery import shared_task
from celery.exceptions import MaxRetriesExceededError
from celery.utils.log import get_task_logger
@@ -52,7 +52,7 @@ def send_task_complete_email(self, task_name, task_state_text, dest_addr, detail
try:
mail.send_mail(subject, message, from_address, [dest_addr], fail_silently=False)
LOGGER.info("Task complete email has been sent to User %s", dest_addr)
except NoAuthHandlerFound:
except botocore.exceptions.ClientError:
LOGGER.info(
'Retrying sending email to user %s, attempt # %s of %s',
dest_addr,

View File

@@ -7,8 +7,8 @@ from unittest import mock
from unittest.mock import patch
from uuid import uuid4
import botocore
import ddt
from boto.exception import NoAuthHandlerFound
from django.conf import settings
from django.core import mail
from django.test import override_settings
@@ -303,7 +303,9 @@ class TestUserTaskStopped(APITestCase):
Make sure we can succeed on retries
"""
with mock.patch('django.core.mail.send_mail') as mock_exception:
mock_exception.side_effect = NoAuthHandlerFound()
mock_exception.side_effect = botocore.exceptions.ClientError(
{'error_response': 'error occurred'}, {'operation_name': 'test'}
)
with mock.patch('cms.djangoapps.cms_user_tasks.tasks.send_task_complete_email.retry') as mock_retry:
user_task_stopped.send(sender=UserTaskStatus, status=self.status)
@@ -315,7 +317,9 @@ class TestUserTaskStopped(APITestCase):
logger.addHandler(hdlr)
with mock.patch('cms.djangoapps.cms_user_tasks.tasks.send_task_complete_email.delay') as mock_delay:
mock_delay.side_effect = NoAuthHandlerFound()
mock_delay.side_effect = botocore.exceptions.ClientError(
{'error_response': 'error occurred'}, {'operation_name': 'test'}
)
user_task_stopped.send(sender=UserTaskStatus, status=self.status)
self.assertTrue(mock_delay.called)
self.assertEqual(hdlr.messages['error'][0], 'Unable to queue send_task_complete_email')

View File

@@ -5,11 +5,11 @@ Storage backend for course import and export.
from django.conf import settings
from django.core.files.storage import get_storage_class
from storages.backends.s3boto import S3BotoStorage
from storages.backends.s3boto3 import S3Boto3Storage
from storages.utils import setting
class ImportExportS3Storage(S3BotoStorage): # pylint: disable=abstract-method
class ImportExportS3Storage(S3Boto3Storage): # pylint: disable=abstract-method
"""
S3 backend for course import and export OLX files.
"""

View File

@@ -5,10 +5,10 @@ Storage backend for course metadata export.
from django.conf import settings
from django.core.files.storage import get_storage_class
from storages.backends.s3boto import S3BotoStorage
from storages.backends.s3boto3 import S3Boto3Storage
class CourseMetadataExportS3Storage(S3BotoStorage): # pylint: disable=abstract-method
class CourseMetadataExportS3Storage(S3Boto3Storage): # pylint: disable=abstract-method
"""
S3 backend for course metadata export
"""

View File

@@ -29,5 +29,5 @@ def export_course_metadata_task(self, course_key_string): # pylint: disable=unu
"""
course_key = CourseKey.from_string(course_key_string)
highlights = get_all_course_highlights(course_key)
highlights_content = ContentFile(json.dumps({'highlights': highlights}))
highlights_content = ContentFile(json.dumps({'highlights': highlights}).encode('utf-8'))
course_metadata_export_storage.save(f'course_metadata_export/{course_key}.json', highlights_content)

View File

@@ -48,7 +48,7 @@ class TestExportCourseMetadata(SharedModuleStoreTestCase):
SignalHandler.course_published.connect(export_course_metadata)
SignalHandler.course_published.send(sender=None, course_key=self.course_key)
patched_content.assert_called_once_with(
'{"highlights": [["week1highlight1", "week1highlight2"], ["week1highlight1", "week1highlight2"], [], []]}'
b'{"highlights": [["week1highlight1", "week1highlight2"], ["week1highlight1", "week1highlight2"], [], []]}'
)
patched_storage.save.assert_called_once_with(
f'course_metadata_export/{self.course_key}.json', patched_content.return_value