Skip to content

Commit

Permalink
chore: Replaced boto usage with boto3. (#31886)
Browse files Browse the repository at this point in the history
* chore: Replaced boto usage with boto3.
  • Loading branch information
awais786 authored Mar 7, 2023
1 parent c51f0da commit 20ef29d
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions common/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/instructor_task/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
"""
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/verify_student/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/verify_student/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
"""
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/verify_student/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions lms/djangoapps/verify_student/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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
"""
Expand Down

0 comments on commit 20ef29d

Please sign in to comment.