diff --git a/cms/djangoapps/contentstore/rest_api/v0/tests/test_assets.py b/cms/djangoapps/contentstore/rest_api/v0/tests/test_assets.py index 38429910edd1..46b636916df8 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/tests/test_assets.py +++ b/cms/djangoapps/contentstore/rest_api/v0/tests/test_assets.py @@ -5,12 +5,11 @@ not the underlying Xblock service. It checks that the assets_handler method of the Xblock service is called with the expected parameters. """ -from unittest.mock import patch +from unittest.mock import patch, MagicMock + from django.core.files import File from django.http import JsonResponse - from django.urls import reverse -from mock import MagicMock from rest_framework import status from rest_framework.test import APITestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py index 971b2b996ab9..66b5f46128c8 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py @@ -1,8 +1,9 @@ """ Unit tests for Contentstore Proctored Exam Settings. """ +from unittest.mock import patch + import ddt -from mock import patch from django.conf import settings from django.test.utils import override_settings from django.urls import reverse diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_settings.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_settings.py index 2c867ad0947c..5365443c47d9 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_settings.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_settings.py @@ -1,10 +1,11 @@ """ Unit tests for course settings views. """ +from unittest.mock import patch + import ddt from django.conf import settings from django.urls import reverse -from mock import patch from rest_framework import status from cms.djangoapps.contentstore.tests.utils import CourseTestCase diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py index 993072e0717f..1d086cb9fda0 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py @@ -1,6 +1,8 @@ """ Unit tests for course settings views. """ +from unittest.mock import patch + import ddt from django.conf import settings from django.contrib.staticfiles.storage import staticfiles_storage @@ -12,7 +14,6 @@ get_transcript_credentials_state_for_org, get_transcript_preferences, ) -from mock import patch from rest_framework import status from cms.djangoapps.contentstore.video_storage_handlers import get_all_transcript_languages diff --git a/common/test/utils.py b/common/test/utils.py index d772f61edd56..ceddf775691a 100644 --- a/common/test/utils.py +++ b/common/test/utils.py @@ -1,6 +1,7 @@ """ General testing utilities. """ +from unittest.mock import Mock, patch import functools @@ -9,7 +10,6 @@ from django.dispatch import Signal from markupsafe import escape -from mock import Mock, patch @contextmanager diff --git a/lms/djangoapps/course_goals/tests/test_user_activity.py b/lms/djangoapps/course_goals/tests/test_user_activity.py index 0946ba158b95..04eb267152d4 100644 --- a/lms/djangoapps/course_goals/tests/test_user_activity.py +++ b/lms/djangoapps/course_goals/tests/test_user_activity.py @@ -3,7 +3,7 @@ """ from datetime import datetime, timedelta -from unittest.mock import Mock +from unittest.mock import Mock, patch import ddt from django.contrib.auth import get_user_model @@ -12,7 +12,6 @@ from edx_django_utils.cache import TieredCache from edx_toggles.toggles.testutils import override_waffle_flag from freezegun import freeze_time -from mock import patch from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory diff --git a/lms/djangoapps/course_home_api/course_metadata/tests/test_views.py b/lms/djangoapps/course_home_api/course_metadata/tests/test_views.py index 4b3524eb1ee2..23052e5e7d90 100644 --- a/lms/djangoapps/course_home_api/course_metadata/tests/test_views.py +++ b/lms/djangoapps/course_home_api/course_metadata/tests/test_views.py @@ -1,14 +1,13 @@ """ Tests for the Course Home Course Metadata API in the Course Home API """ +import json +from unittest.mock import patch import ddt -import json -import mock from django.db import transaction from django.urls import reverse from edx_toggles.toggles.testutils import override_waffle_flag -from unittest.mock import patch from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment @@ -108,7 +107,7 @@ def test_streak_data_in_response(self): CourseEnrollment.enroll(self.user, self.course.id, 'audit') with override_waffle_flag(COURSEWARE_MFE_MILESTONES_STREAK_DISCOUNT, active=True): UPDATES_METHOD_NAME = 'common.djangoapps.student.models.user.UserCelebration.perform_streak_updates' - with mock.patch(UPDATES_METHOD_NAME, return_value=3): + with patch(UPDATES_METHOD_NAME, return_value=3): response = self.client.get(self.url, content_type='application/json') celebrations = response.json()['celebrations'] assert celebrations['streak_length_to_celebrate'] == 3 @@ -187,7 +186,7 @@ def test_course_access( self.update_masquerade(role=masquerade_role) consent_url = 'dump/consent/url' if dsc_required else None - with mock.patch('openedx.features.enterprise_support.api.get_enterprise_consent_url', return_value=consent_url): + with patch('openedx.features.enterprise_support.api.get_enterprise_consent_url', return_value=consent_url): response = self.client.get(self.url) self._assert_course_access_response(response, expect_course_access, error_code) diff --git a/lms/djangoapps/discussion/django_comment_client/base/tests.py b/lms/djangoapps/discussion/django_comment_client/base/tests.py index 6aa9c3e8e9fd..f8242efa0c9c 100644 --- a/lms/djangoapps/discussion/django_comment_client/base/tests.py +++ b/lms/djangoapps/discussion/django_comment_client/base/tests.py @@ -6,15 +6,15 @@ import json import logging from contextlib import contextmanager +from unittest import mock +from unittest.mock import ANY, Mock, patch import ddt -import mock from django.contrib.auth.models import User from django.core.management import call_command from django.test.client import RequestFactory from django.urls import reverse from eventtracking.processors.exceptions import EventEmissionExit -from mock import ANY, Mock, patch from opaque_keys.edx.keys import CourseKey from openedx_events.learning.signals import FORUM_THREAD_CREATED, FORUM_THREAD_RESPONSE_CREATED, FORUM_RESPONSE_COMMENT_CREATED diff --git a/lms/djangoapps/instructor/tests/test_tools.py b/lms/djangoapps/instructor/tests/test_tools.py index 0141ac9e8381..b9f754dbfff1 100644 --- a/lms/djangoapps/instructor/tests/test_tools.py +++ b/lms/djangoapps/instructor/tests/test_tools.py @@ -7,6 +7,7 @@ import json import unittest from unittest import mock +from unittest.mock import MagicMock, patch import pytest from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user @@ -14,7 +15,6 @@ from django.test import TestCase from edx_when.api import get_dates_for_course, set_dates_for_course from edx_when.field_data import DateLookupFieldData -from mock.mock import MagicMock, patch from opaque_keys.edx.keys import CourseKey from pytz import UTC from xmodule.fields import Date diff --git a/lms/djangoapps/mobile_api/tests/test_course_info_serializers.py b/lms/djangoapps/mobile_api/tests/test_course_info_serializers.py index 6c50f68d6811..51d9acba54cc 100644 --- a/lms/djangoapps/mobile_api/tests/test_course_info_serializers.py +++ b/lms/djangoapps/mobile_api/tests/test_course_info_serializers.py @@ -1,11 +1,11 @@ """ Tests for serializers for the Mobile Course Info """ +from unittest.mock import MagicMock, Mock, patch +from typing import Dict, List, Tuple, Union import ddt from django.test import TestCase -from mock import MagicMock, Mock, patch -from typing import Dict, List, Tuple, Union from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.mobile_api.course_info.serializers import ( diff --git a/lms/djangoapps/mobile_api/tests/test_course_info_views.py b/lms/djangoapps/mobile_api/tests/test_course_info_views.py index 67d2c79f9017..25fe08980379 100644 --- a/lms/djangoapps/mobile_api/tests/test_course_info_views.py +++ b/lms/djangoapps/mobile_api/tests/test_course_info_views.py @@ -1,6 +1,7 @@ """ Tests for course_info """ +from unittest.mock import patch import ddt @@ -11,7 +12,6 @@ from django.urls import reverse from edx_toggles.toggles.testutils import override_waffle_flag from milestones.tests.utils import MilestonesTestCaseMixin -from mock import patch from rest_framework import status from common.djangoapps.student.tests.factories import UserFactory # pylint: disable=unused-import diff --git a/openedx/core/djangoapps/catalog/tests/test_api.py b/openedx/core/djangoapps/catalog/tests/test_api.py index ed657d992d57..318111547e89 100644 --- a/openedx/core/djangoapps/catalog/tests/test_api.py +++ b/openedx/core/djangoapps/catalog/tests/test_api.py @@ -1,7 +1,7 @@ """ Tests for the Catalog apps `api.py` functions. """ -from mock import patch +from unittest.mock import patch from django.test import TestCase diff --git a/openedx/core/djangoapps/content/course_overviews/tests/test_api.py b/openedx/core/djangoapps/content/course_overviews/tests/test_api.py index d98c6f0d016f..568322f82d98 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/test_api.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/test_api.py @@ -1,7 +1,7 @@ """ course_overview api tests """ -from mock import patch +from unittest.mock import patch from django.http.response import Http404 from opaque_keys.edx.keys import CourseKey diff --git a/openedx/core/djangoapps/discussions/tests/test_tasks.py b/openedx/core/djangoapps/discussions/tests/test_tasks.py index fa04713ae426..00b715c945e6 100644 --- a/openedx/core/djangoapps/discussions/tests/test_tasks.py +++ b/openedx/core/djangoapps/discussions/tests/test_tasks.py @@ -1,8 +1,9 @@ """ Tests for discussions tasks. """ +from unittest import mock + import ddt -import mock from edx_toggles.toggles.testutils import override_waffle_flag from openedx_events.learning.data import DiscussionTopicContext diff --git a/openedx/core/djangoapps/theming/tests/test_commands.py b/openedx/core/djangoapps/theming/tests/test_commands.py deleted file mode 100644 index 7ca56f604a41..000000000000 --- a/openedx/core/djangoapps/theming/tests/test_commands.py +++ /dev/null @@ -1,24 +0,0 @@ -""" -Tests for Management commands of comprehensive theming. -""" - -from django.core.management import call_command -from django.test import TestCase, override_settings -from unittest.mock import patch - -import pavelib.assets - - -class TestUpdateAssets(TestCase): - """ - Test comprehensive theming helper functions. - """ - - @patch.object(pavelib.assets, 'sh') - @override_settings(COMPREHENSIVE_THEME_DIRS='common/test') - def test_deprecated_wrapper(self, mock_sh): - call_command('compile_sass', '--themes', 'fake-theme1', 'fake-theme2') - assert mock_sh.called_once_with( - "npm run compile-sass -- " + - "--theme-dir common/test --theme fake-theme-1 --theme fake-theme-2" - ) diff --git a/scripts/user_retirement/tests/test_get_learners_to_retire.py b/scripts/user_retirement/tests/test_get_learners_to_retire.py index 480de92185db..557398a2720f 100644 --- a/scripts/user_retirement/tests/test_get_learners_to_retire.py +++ b/scripts/user_retirement/tests/test_get_learners_to_retire.py @@ -1,11 +1,11 @@ """ Test the get_learners_to_retire.py script """ +from unittest.mock import DEFAULT, patch import os from click.testing import CliRunner -from mock import DEFAULT, patch from requests.exceptions import HTTPError from scripts.user_retirement.get_learners_to_retire import get_learners_to_retire diff --git a/scripts/user_retirement/tests/test_retire_one_learner.py b/scripts/user_retirement/tests/test_retire_one_learner.py index a78b6b787acb..844325ea3ed0 100644 --- a/scripts/user_retirement/tests/test_retire_one_learner.py +++ b/scripts/user_retirement/tests/test_retire_one_learner.py @@ -1,9 +1,9 @@ """ Test the retire_one_learner.py script """ +from unittest.mock import DEFAULT, patch from click.testing import CliRunner -from mock import DEFAULT, patch from scripts.user_retirement.retire_one_learner import ( END_STATES, diff --git a/scripts/user_retirement/tests/test_retirement_archive_and_cleanup.py b/scripts/user_retirement/tests/test_retirement_archive_and_cleanup.py index 3a6a847e1d6e..aa6715ba7d6c 100644 --- a/scripts/user_retirement/tests/test_retirement_archive_and_cleanup.py +++ b/scripts/user_retirement/tests/test_retirement_archive_and_cleanup.py @@ -4,12 +4,12 @@ import datetime import os +from unittest.mock import DEFAULT, call, patch import boto3 import pytest from botocore.exceptions import ClientError from click.testing import CliRunner -from mock import DEFAULT, call, patch from moto import mock_ec2, mock_s3 from scripts.user_retirement.retirement_archive_and_cleanup import ( diff --git a/scripts/user_retirement/tests/test_retirement_bulk_status_update.py b/scripts/user_retirement/tests/test_retirement_bulk_status_update.py index d2a8bab60ba3..0cfbeeef3d7a 100644 --- a/scripts/user_retirement/tests/test_retirement_bulk_status_update.py +++ b/scripts/user_retirement/tests/test_retirement_bulk_status_update.py @@ -1,9 +1,9 @@ """ Test the retirement_bulk_status_update.py script """ +from unittest.mock import DEFAULT, patch from click.testing import CliRunner -from mock import DEFAULT, patch from scripts.user_retirement.retirement_bulk_status_update import ( ERR_BAD_CONFIG, diff --git a/scripts/user_retirement/tests/test_retirement_partner_report.py b/scripts/user_retirement/tests/test_retirement_partner_report.py index c9d05a974396..886f2d9e4073 100644 --- a/scripts/user_retirement/tests/test_retirement_partner_report.py +++ b/scripts/user_retirement/tests/test_retirement_partner_report.py @@ -8,9 +8,9 @@ import time import unicodedata from datetime import date +from unittest.mock import DEFAULT, patch from click.testing import CliRunner -from mock import DEFAULT, patch from six import PY2, itervalues from scripts.user_retirement.retirement_partner_report import \ diff --git a/scripts/user_retirement/tests/utils/test_edx_api.py b/scripts/user_retirement/tests/utils/test_edx_api.py index 1c1aa78c39bd..706b1ce6d4a7 100644 --- a/scripts/user_retirement/tests/utils/test_edx_api.py +++ b/scripts/user_retirement/tests/utils/test_edx_api.py @@ -2,12 +2,12 @@ Tests for edX API calls. """ import unittest +from unittest.mock import DEFAULT, patch from urllib.parse import urljoin import requests import responses from ddt import data, ddt, unpack -from mock import DEFAULT, patch from requests.exceptions import ConnectionError, HTTPError from responses import GET, PATCH, POST, matchers from responses.registries import OrderedRegistry diff --git a/scripts/user_retirement/tests/utils/test_jenkins.py b/scripts/user_retirement/tests/utils/test_jenkins.py index 8d32ee24c2df..bd51c0f5d779 100644 --- a/scripts/user_retirement/tests/utils/test_jenkins.py +++ b/scripts/user_retirement/tests/utils/test_jenkins.py @@ -6,11 +6,11 @@ import re import unittest from itertools import islice +from unittest.mock import Mock, call, mock_open, patch import backoff import ddt import requests_mock -from mock import Mock, call, mock_open, patch import scripts.user_retirement.utils.jenkins as jenkins from scripts.user_retirement.utils.exception import BackendError diff --git a/scripts/user_retirement/tests/utils/thirdparty_apis/test_salesforce.py b/scripts/user_retirement/tests/utils/thirdparty_apis/test_salesforce.py index 47770439533e..2267f38369b9 100644 --- a/scripts/user_retirement/tests/utils/thirdparty_apis/test_salesforce.py +++ b/scripts/user_retirement/tests/utils/thirdparty_apis/test_salesforce.py @@ -3,8 +3,8 @@ """ import logging from contextlib import contextmanager +from unittest import mock -import mock import pytest from simple_salesforce import SalesforceError diff --git a/scripts/user_retirement/tests/utils/thirdparty_apis/test_segment_api.py b/scripts/user_retirement/tests/utils/thirdparty_apis/test_segment_api.py index 8d413c7d3282..c52a5c5074b1 100644 --- a/scripts/user_retirement/tests/utils/thirdparty_apis/test_segment_api.py +++ b/scripts/user_retirement/tests/utils/thirdparty_apis/test_segment_api.py @@ -2,8 +2,8 @@ Tests for the Segment API functionality """ import json +from unittest import mock -import mock import pytest import requests from six import text_type diff --git a/xmodule/capa/tests/helpers.py b/xmodule/capa/tests/helpers.py index 41fd485aef46..540d459c5ab2 100644 --- a/xmodule/capa/tests/helpers.py +++ b/xmodule/capa/tests/helpers.py @@ -6,10 +6,10 @@ import os import os.path import xml.sax.saxutils as saxutils +from unittest.mock import MagicMock, Mock import fs.osfs from mako.lookup import TemplateLookup -from mock import MagicMock, Mock from path import Path from xmodule.capa.capa_problem import LoncapaProblem, LoncapaSystem diff --git a/xmodule/capa/tests/test_capa_problem.py b/xmodule/capa/tests/test_capa_problem.py index 88a06b4c7ed7..74cf4d096fd1 100644 --- a/xmodule/capa/tests/test_capa_problem.py +++ b/xmodule/capa/tests/test_capa_problem.py @@ -3,6 +3,7 @@ """ import textwrap import unittest +from unittest.mock import patch, MagicMock from django.conf import settings from django.test import override_settings @@ -10,7 +11,6 @@ import ddt from lxml import etree from markupsafe import Markup -from mock import patch, MagicMock from xmodule.capa.correctmap import CorrectMap from xmodule.capa.responsetypes import LoncapaProblemError diff --git a/xmodule/capa/tests/test_html_render.py b/xmodule/capa/tests/test_html_render.py index 91500a0fdf56..2a9a7867718f 100644 --- a/xmodule/capa/tests/test_html_render.py +++ b/xmodule/capa/tests/test_html_render.py @@ -6,9 +6,9 @@ import os import textwrap import unittest +from unittest import mock import ddt -import mock from lxml import etree from xmodule.capa.tests.helpers import new_loncapa_problem, test_capa_system from openedx.core.djangolib.markup import HTML diff --git a/xmodule/capa/tests/test_inputtypes.py b/xmodule/capa/tests/test_inputtypes.py index 1d7e43b650a2..e7cc09eb572e 100644 --- a/xmodule/capa/tests/test_inputtypes.py +++ b/xmodule/capa/tests/test_inputtypes.py @@ -23,12 +23,12 @@ import unittest import xml.sax.saxutils as saxutils from collections import OrderedDict +from unittest.mock import ANY, patch import pytest import six from lxml import etree from lxml.html import fromstring -from mock import ANY, patch from pyparsing import ParseException from six.moves import zip diff --git a/xmodule/capa/tests/test_responsetypes.py b/xmodule/capa/tests/test_responsetypes.py index 936093aa6e21..37a6647ce7d0 100644 --- a/xmodule/capa/tests/test_responsetypes.py +++ b/xmodule/capa/tests/test_responsetypes.py @@ -9,10 +9,10 @@ import unittest import zipfile from datetime import datetime +from unittest import mock import pytest import calc -import mock import pyparsing import random2 as random import requests diff --git a/xmodule/tests/test_capa_block.py b/xmodule/tests/test_capa_block.py index 42494547822e..96ec64de61e5 100644 --- a/xmodule/tests/test_capa_block.py +++ b/xmodule/tests/test_capa_block.py @@ -6,12 +6,11 @@ import datetime import json -import mock import os import random import textwrap import unittest -from unittest.mock import DEFAULT, Mock, patch +from unittest.mock import DEFAULT, Mock, PropertyMock, patch import pytest import ddt @@ -820,7 +819,7 @@ def test_submit_problem_grading_method_disable_to_enable( # Disabled grading method with patch( 'xmodule.capa_block.ProblemBlock.is_grading_method_enabled', - new_callable=mock.PropertyMock, + new_callable=PropertyMock, return_value=False ): # First Attempt @@ -846,7 +845,7 @@ def test_submit_problem_grading_method_disable_to_enable( # Enabled grading method with patch( 'xmodule.capa_block.ProblemBlock.is_grading_method_enabled', - new_callable=mock.PropertyMock, + new_callable=PropertyMock, return_value=True ): # Third Attempt @@ -887,7 +886,7 @@ def test_submit_problem_grading_method_enable_to_disable( # Enabled grading method with patch( 'xmodule.capa_block.ProblemBlock.is_grading_method_enabled', - new_callable=mock.PropertyMock, + new_callable=PropertyMock, return_value=True ): # First Attempt @@ -913,7 +912,7 @@ def test_submit_problem_grading_method_enable_to_disable( # Disabled grading method with patch( 'xmodule.capa_block.ProblemBlock.is_grading_method_enabled', - new_callable=mock.PropertyMock, + new_callable=PropertyMock, return_value=False ): # Third Attempt @@ -1636,7 +1635,7 @@ def test_rescore_problem_grading_method_disable_to_enable(self, mock_publish_gra # Disabled grading method with patch( 'xmodule.capa_block.ProblemBlock.is_grading_method_enabled', - new_callable=mock.PropertyMock, + new_callable=PropertyMock, return_value=False ): # Score is the last score @@ -1652,12 +1651,12 @@ def test_rescore_problem_grading_method_disable_to_enable(self, mock_publish_gra # Enabled grading method with patch( 'xmodule.capa_block.ProblemBlock.is_grading_method_enabled', - new_callable=mock.PropertyMock, + new_callable=PropertyMock, return_value=True ): with patch( 'xmodule.capa.capa_problem.LoncapaProblem.is_grading_method_enabled', - new_callable=mock.PropertyMock, + new_callable=PropertyMock, return_value=True ): # Change grading method to 'first_score' @@ -1706,12 +1705,12 @@ def test_rescore_problem_grading_method_enable_to_disable(self, mock_publish_gra # Enabled grading method with patch( 'xmodule.capa_block.ProblemBlock.is_grading_method_enabled', - new_callable=mock.PropertyMock, + new_callable=PropertyMock, return_value=True ): with patch( 'xmodule.capa.capa_problem.LoncapaProblem.is_grading_method_enabled', - new_callable=mock.PropertyMock, + new_callable=PropertyMock, return_value=True ): # Grading method is 'last_score' @@ -1745,7 +1744,7 @@ def test_rescore_problem_grading_method_enable_to_disable(self, mock_publish_gra # Disabled grading method with patch( 'xmodule.capa_block.ProblemBlock.is_grading_method_enabled', - new_callable=mock.PropertyMock, + new_callable=PropertyMock, return_value=False ): block.rescore(only_if_higher=False)