From 20ef29da53c979190ee98ced7241b481f33317a9 Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Tue, 7 Mar 2023 15:47:48 +0500 Subject: [PATCH] chore: Replaced boto usage with boto3. (#31886) * chore: Replaced boto usage with boto3. --- common/test/utils.py | 8 ++++---- lms/djangoapps/instructor_task/tests/test_models.py | 4 ++-- .../tests/test_send_verification_expiry_email.py | 4 ++-- ...oftwaresecurephotoverifications_post_save_signal.py | 4 ++-- .../management/commands/tests/test_verify_student.py | 4 ++-- lms/djangoapps/verify_student/models.py | 2 +- lms/djangoapps/verify_student/tests/test_models.py | 4 ++-- lms/djangoapps/verify_student/tests/test_tasks.py | 4 ++-- lms/djangoapps/verify_student/tests/test_views.py | 10 +++++----- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/common/test/utils.py b/common/test/utils.py index 2c55df7d1e5b..d772f61edd56 100644 --- a/common/test/utils.py +++ b/common/test/utils.py @@ -115,16 +115,16 @@ def skip_signal(signal, **kwargs): signal.connect(**kwargs) -class MockS3BotoMixin: +class MockS3Boto3Mixin: """ - TestCase mixin that mocks the S3BotoStorage save method and s3 connection. + TestCase mixin that mocks the S3Boto3Storage save method and s3 connection. """ def setUp(self): super().setUp() - self._mocked_connection = patch('boto.connect_s3', return_value=Mock()) + self._mocked_connection = patch('boto3.resource', return_value=Mock()) self.mocked_connection = self._mocked_connection.start() - self.patcher = patch('storages.backends.s3boto.S3BotoStorage.save') + self.patcher = patch('storages.backends.s3boto3.S3Boto3Storage.save') self.patcher.start() def tearDown(self): diff --git a/lms/djangoapps/instructor_task/tests/test_models.py b/lms/djangoapps/instructor_task/tests/test_models.py index 4d59eae16006..16e4e9486bde 100644 --- a/lms/djangoapps/instructor_task/tests/test_models.py +++ b/lms/djangoapps/instructor_task/tests/test_models.py @@ -11,7 +11,7 @@ from django.test import SimpleTestCase, TestCase, override_settings from opaque_keys.edx.locator import CourseLocator -from common.test.utils import MockS3BotoMixin +from common.test.utils import MockS3Boto3Mixin from lms.djangoapps.instructor_task.models import TASK_INPUT_LENGTH, InstructorTask, ReportStore from lms.djangoapps.instructor_task.tests.test_base import TestReportMixin @@ -95,7 +95,7 @@ def create_report_store(self): return ReportStore.from_config(config_name='GRADES_DOWNLOAD') -class DjangoStorageReportStoreS3TestCase(MockS3BotoMixin, ReportStoreTestMixin, TestReportMixin, SimpleTestCase): +class DjangoStorageReportStoreS3TestCase(MockS3Boto3Mixin, ReportStoreTestMixin, TestReportMixin, SimpleTestCase): """ Test the DjangoStorageReportStore implementation using S3 stubs. """ diff --git a/lms/djangoapps/verify_student/management/commands/tests/test_send_verification_expiry_email.py b/lms/djangoapps/verify_student/management/commands/tests/test_send_verification_expiry_email.py index c4cde9f649a2..874051c0c8d2 100644 --- a/lms/djangoapps/verify_student/management/commands/tests/test_send_verification_expiry_email.py +++ b/lms/djangoapps/verify_student/management/commands/tests/test_send_verification_expiry_email.py @@ -16,7 +16,7 @@ from testfixtures import LogCapture from common.djangoapps.student.tests.factories import UserFactory -from common.test.utils import MockS3BotoMixin +from common.test.utils import MockS3Boto3Mixin from lms.djangoapps.verify_student.models import ManualVerification, SoftwareSecurePhotoVerification, SSOVerification from lms.djangoapps.verify_student.tests.test_models import FAKE_SETTINGS, mock_software_secure_post @@ -25,7 +25,7 @@ @patch.dict(settings.VERIFY_STUDENT, FAKE_SETTINGS) @patch('lms.djangoapps.verify_student.models.requests.post', new=mock_software_secure_post) -class TestSendVerificationExpiryEmail(MockS3BotoMixin, TestCase): +class TestSendVerificationExpiryEmail(MockS3Boto3Mixin, TestCase): """ Tests for django admin command `send_verification_expiry_email` in the verify_student module """ def setUp(self): diff --git a/lms/djangoapps/verify_student/management/commands/tests/test_trigger_softwaresecurephotoverifications_post_save_signal.py b/lms/djangoapps/verify_student/management/commands/tests/test_trigger_softwaresecurephotoverifications_post_save_signal.py index f6a95ed0d7c0..99fd4ecd3a5f 100644 --- a/lms/djangoapps/verify_student/management/commands/tests/test_trigger_softwaresecurephotoverifications_post_save_signal.py +++ b/lms/djangoapps/verify_student/management/commands/tests/test_trigger_softwaresecurephotoverifications_post_save_signal.py @@ -10,7 +10,7 @@ from freezegun import freeze_time from unittest.mock import call, patch, ANY # lint-amnesty, pylint: disable=wrong-import-order -from common.test.utils import MockS3BotoMixin +from common.test.utils import MockS3Boto3Mixin from lms.djangoapps.verify_student.tests import TestVerificationBase from lms.djangoapps.verify_student.tests.test_models import ( FAKE_SETTINGS, @@ -22,7 +22,7 @@ @patch.dict(settings.VERIFY_STUDENT, FAKE_SETTINGS) @patch.dict(settings.FEATURES, {'AUTOMATIC_VERIFY_STUDENT_IDENTITY_FOR_TESTING': True}) @patch('lms.djangoapps.verify_student.models.requests.post', new=mock_software_secure_post) -class TestTriggerSoftwareSecurePhotoVerificationsPostSaveSignal(MockS3BotoMixin, TestVerificationBase): +class TestTriggerSoftwareSecurePhotoVerificationsPostSaveSignal(MockS3Boto3Mixin, TestVerificationBase): """ Tests for django admin command `trigger_softwaresecurephotoverifications_post_save_signal` in the verify_student module diff --git a/lms/djangoapps/verify_student/management/commands/tests/test_verify_student.py b/lms/djangoapps/verify_student/management/commands/tests/test_verify_student.py index bf7ab735ec84..2294230d916d 100644 --- a/lms/djangoapps/verify_student/management/commands/tests/test_verify_student.py +++ b/lms/djangoapps/verify_student/management/commands/tests/test_verify_student.py @@ -10,7 +10,7 @@ from django.core.management import call_command from testfixtures import LogCapture -from common.test.utils import MockS3BotoMixin +from common.test.utils import MockS3Boto3Mixin from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification, SSPVerificationRetryConfig from lms.djangoapps.verify_student.tests import TestVerificationBase from lms.djangoapps.verify_student.tests.test_models import ( @@ -25,7 +25,7 @@ # Lots of patching to stub in our own settings, and HTTP posting @patch.dict(settings.VERIFY_STUDENT, FAKE_SETTINGS) @patch('lms.djangoapps.verify_student.models.requests.post', new=mock_software_secure_post) -class TestVerifyStudentCommand(MockS3BotoMixin, TestVerificationBase): +class TestVerifyStudentCommand(MockS3Boto3Mixin, TestVerificationBase): """ Tests for django admin commands in the verify_student module """ diff --git a/lms/djangoapps/verify_student/models.py b/lms/djangoapps/verify_student/models.py index 0e51593c31c6..b3a09260d158 100644 --- a/lms/djangoapps/verify_student/models.py +++ b/lms/djangoapps/verify_student/models.py @@ -910,7 +910,7 @@ def _storage(self): config = settings.VERIFY_STUDENT["SOFTWARE_SECURE"] # Default to the S3 backend for backward compatibility - storage_class = config.get("STORAGE_CLASS", "storages.backends.s3boto.S3BotoStorage") + storage_class = config.get("STORAGE_CLASS", "storages.backends.s3boto3.S3Boto3Storage") storage_kwargs = config.get("STORAGE_KWARGS", {}) # Map old settings to the parameters expected by the storage backend diff --git a/lms/djangoapps/verify_student/tests/test_models.py b/lms/djangoapps/verify_student/tests/test_models.py index 65e865f582ba..9ea45463011d 100644 --- a/lms/djangoapps/verify_student/tests/test_models.py +++ b/lms/djangoapps/verify_student/tests/test_models.py @@ -14,7 +14,7 @@ from freezegun import freeze_time from common.djangoapps.student.tests.factories import UserFactory -from common.test.utils import MockS3BotoMixin +from common.test.utils import MockS3Boto3Mixin from lms.djangoapps.verify_student.models import ( ManualVerification, PhotoVerification, @@ -94,7 +94,7 @@ def mock_software_secure_post_unavailable(url, headers=None, data=None, **kwargs @patch.dict(settings.VERIFY_STUDENT, FAKE_SETTINGS) @patch('lms.djangoapps.verify_student.models.requests.post', new=mock_software_secure_post) @ddt.ddt -class TestPhotoVerification(TestVerificationBase, MockS3BotoMixin, ModuleStoreTestCase): # lint-amnesty, pylint: disable=missing-class-docstring +class TestPhotoVerification(TestVerificationBase, MockS3Boto3Mixin, ModuleStoreTestCase): # lint-amnesty, pylint: disable=missing-class-docstring def test_state_transitions(self): """ diff --git a/lms/djangoapps/verify_student/tests/test_tasks.py b/lms/djangoapps/verify_student/tests/test_tasks.py index 7107d5ddb85e..ec6c9e6ffa51 100644 --- a/lms/djangoapps/verify_student/tests/test_tasks.py +++ b/lms/djangoapps/verify_student/tests/test_tasks.py @@ -6,7 +6,7 @@ import ddt from django.conf import settings -from common.test.utils import MockS3BotoMixin +from common.test.utils import MockS3Boto3Mixin from lms.djangoapps.verify_student.tests import TestVerificationBase from lms.djangoapps.verify_student.tests.test_models import FAKE_SETTINGS, mock_software_secure_post_unavailable from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order @@ -16,7 +16,7 @@ @patch.dict(settings.VERIFY_STUDENT, FAKE_SETTINGS) @ddt.ddt -class TestPhotoVerificationTasks(TestVerificationBase, MockS3BotoMixin, ModuleStoreTestCase): # lint-amnesty, pylint: disable=missing-class-docstring +class TestPhotoVerificationTasks(TestVerificationBase, MockS3Boto3Mixin, ModuleStoreTestCase): # lint-amnesty, pylint: disable=missing-class-docstring @mock.patch('lms.djangoapps.verify_student.tasks.log') def test_logs_for_retry_until_failure(self, mock_log): diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index c5809ec91bd3..ea2ccb891988 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -29,7 +29,7 @@ from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory from common.djangoapps.util.testing import UrlResetMixin -from common.test.utils import MockS3BotoMixin, XssTestMixin +from common.test.utils import MockS3Boto3Mixin, XssTestMixin from lms.djangoapps.commerce.models import CommerceConfiguration from lms.djangoapps.commerce.tests import TEST_API_URL, TEST_PAYMENT_DATA, TEST_PUBLIC_URL_ROOT from lms.djangoapps.commerce.tests.mocks import mock_payment_processors @@ -1227,7 +1227,7 @@ def test_create_basket(self): @ddt.ddt @patch.dict(settings.FEATURES, {'AUTOMATIC_VERIFY_STUDENT_IDENTITY_FOR_TESTING': True}) -class TestSubmitPhotosForVerification(MockS3BotoMixin, TestVerificationBase): +class TestSubmitPhotosForVerification(MockS3Boto3Mixin, TestVerificationBase): """ Tests for submitting photos for verification. """ @@ -1853,7 +1853,7 @@ def _assert_reverify(self): "CERT_VERIFICATION_PATH": False, }, "DAYS_GOOD_FOR": 10, - "STORAGE_CLASS": 'storages.backends.s3boto.S3BotoStorage', + "STORAGE_CLASS": 'storages.backends.s3boto3.S3Boto3Storage', "STORAGE_KWARGS": { 'bucket': 'test-idv', }, @@ -1917,14 +1917,14 @@ def test_403_for_non_staff(self): "CERT_VERIFICATION_PATH": False, }, "DAYS_GOOD_FOR": 10, - "STORAGE_CLASS": 'storages.backends.s3boto.S3BotoStorage', + "STORAGE_CLASS": 'storages.backends.s3boto3.S3Boto3Storage', "STORAGE_KWARGS": { 'bucket': 'test-idv', }, } ) @ddt.ddt -class TestDecodeImageViews(MockS3BotoMixin, TestVerificationBase): +class TestDecodeImageViews(MockS3Boto3Mixin, TestVerificationBase): """ Test for both face and photo id image decoding views """