chore: Replaced boto usage with boto3. (#31886)
* chore: Replaced boto usage with boto3.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -11,7 +11,7 @@ from django.conf import settings
|
||||
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 @@ class DjangoStorageReportStoreLocalTestCase(ReportStoreTestMixin, TestReportMixi
|
||||
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.
|
||||
"""
|
||||
|
||||
@@ -16,7 +16,7 @@ from django.utils.timezone import now
|
||||
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 @@ LOGGER_NAME = 'lms.djangoapps.verify_student.management.commands.send_verificati
|
||||
|
||||
@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):
|
||||
|
||||
@@ -10,7 +10,7 @@ from django.core.management import call_command
|
||||
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 @@ from lms.djangoapps.verify_student.tests.test_models import (
|
||||
@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
|
||||
|
||||
@@ -10,7 +10,7 @@ from django.conf import settings
|
||||
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 @@ LOGGER_NAME = 'retry_photo_verification'
|
||||
# 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
|
||||
"""
|
||||
|
||||
@@ -910,7 +910,7 @@ class SoftwareSecurePhotoVerification(PhotoVerification):
|
||||
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
|
||||
|
||||
@@ -14,7 +14,7 @@ from django.utils.timezone import now
|
||||
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):
|
||||
"""
|
||||
|
||||
@@ -6,7 +6,7 @@ from unittest.mock import patch
|
||||
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 @@ LOGGER_NAME = 'lms.djangoapps.verify_student.tasks'
|
||||
|
||||
@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):
|
||||
|
||||
@@ -29,7 +29,7 @@ from common.djangoapps.course_modes.tests.factories import CourseModeFactory
|
||||
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 @@ class TestCheckoutWithEcommerceService(ModuleStoreTestCase):
|
||||
|
||||
@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 @@ class TestReverifyView(TestVerificationBase):
|
||||
"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 @@ class TestPhotoURLView(TestVerificationBase):
|
||||
"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
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user