From 8869a30bcd89cf05663ef35161f60ad992b55daa Mon Sep 17 00:00:00 2001 From: stvn Date: Tue, 13 Apr 2021 18:37:39 -0700 Subject: [PATCH] refactor: Move UserFactory helper to common/ --- cms/djangoapps/contentstore/tests/test_users_default_role.py | 2 +- common/djangoapps/student/tests/test_roles.py | 3 ++- common/djangoapps/student/tests/test_tasks.py | 2 +- lms/djangoapps/courseware/tests/factories.py | 2 +- lms/djangoapps/courseware/tests/test_access.py | 2 +- lms/djangoapps/courseware/tests/test_entrance_exam.py | 3 ++- lms/djangoapps/courseware/tests/test_group_access.py | 2 +- lms/djangoapps/courseware/tests/test_module_render.py | 2 +- lms/djangoapps/courseware/tests/test_services.py | 3 ++- lms/djangoapps/courseware/tests/test_user_state_client.py | 2 +- lms/djangoapps/instructor/tests/test_api.py | 3 ++- lms/djangoapps/instructor/tests/test_certificates.py | 3 ++- .../instructor/tests/views/test_instructor_dashboard.py | 3 ++- lms/djangoapps/instructor_task/tests/test_api.py | 2 +- lms/djangoapps/mobile_api/testutils.py | 2 +- .../management/commands/tests/test_verify_student.py | 2 -- lms/lib/courseware_search/test/test_lms_result_processor.py | 2 +- 17 files changed, 22 insertions(+), 18 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_users_default_role.py b/cms/djangoapps/contentstore/tests/test_users_default_role.py index 2bd93d94a4..dd4420276b 100644 --- a/cms/djangoapps/contentstore/tests/test_users_default_role.py +++ b/cms/djangoapps/contentstore/tests/test_users_default_role.py @@ -7,7 +7,7 @@ after deleting it creates same course again from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient from cms.djangoapps.contentstore.utils import delete_course, reverse_url from common.djangoapps.student.models import CourseEnrollment -from lms.djangoapps.courseware.tests.factories import UserFactory +from common.djangoapps.student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/common/djangoapps/student/tests/test_roles.py b/common/djangoapps/student/tests/test_roles.py index f900844a72..a79a6d4b63 100644 --- a/common/djangoapps/student/tests/test_roles.py +++ b/common/djangoapps/student/tests/test_roles.py @@ -8,7 +8,7 @@ import six from django.test import TestCase from opaque_keys.edx.keys import CourseKey -from lms.djangoapps.courseware.tests.factories import InstructorFactory, UserFactory +from lms.djangoapps.courseware.tests.factories import InstructorFactory from common.djangoapps.student.roles import ( CourseBetaTesterRole, CourseInstructorRole, @@ -21,6 +21,7 @@ from common.djangoapps.student.roles import ( ) from common.djangoapps.student.tests.factories import AnonymousUserFactory from common.djangoapps.student.tests.factories import StaffFactory +from common.djangoapps.student.tests.factories import UserFactory class RolesTestCase(TestCase): diff --git a/common/djangoapps/student/tests/test_tasks.py b/common/djangoapps/student/tests/test_tasks.py index e4db2b5fca..a02f290d37 100644 --- a/common/djangoapps/student/tests/test_tasks.py +++ b/common/djangoapps/student/tests/test_tasks.py @@ -8,9 +8,9 @@ from django.conf import settings from django.test import TestCase from edx_ace.errors import ChannelError, RecoverableChannelDeliveryError -from lms.djangoapps.courseware.tests.factories import UserFactory from common.djangoapps.student.models import Registration from common.djangoapps.student.tasks import send_activation_email +from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.student.views.management import compose_activation_email diff --git a/lms/djangoapps/courseware/tests/factories.py b/lms/djangoapps/courseware/tests/factories.py index 378942cdf6..a5c137492b 100644 --- a/lms/djangoapps/courseware/tests/factories.py +++ b/lms/djangoapps/courseware/tests/factories.py @@ -23,7 +23,7 @@ from common.djangoapps.student.roles import ( OrgStaffRole ) # Imported to re-export -from common.djangoapps.student.tests.factories import UserFactory # Imported to re-export +from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.student.tests.factories import UserProfileFactory as StudentUserProfileFactory # TODO fix this (course_id and location are invalid names as constants, and course_id should really be COURSE_KEY) diff --git a/lms/djangoapps/courseware/tests/test_access.py b/lms/djangoapps/courseware/tests/test_access.py index 25b8ae87bb..256efc3948 100644 --- a/lms/djangoapps/courseware/tests/test_access.py +++ b/lms/djangoapps/courseware/tests/test_access.py @@ -25,7 +25,6 @@ from lms.djangoapps.courseware.masquerade import CourseMasquerade from lms.djangoapps.courseware.tests.factories import ( BetaTesterFactory, InstructorFactory, - UserFactory ) from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase, masquerade_as_group_member from lms.djangoapps.ccx.models import CustomCourseForEdX @@ -42,6 +41,7 @@ from common.djangoapps.student.tests.factories import ( ) from common.djangoapps.student.tests.factories import GlobalStaffFactory from common.djangoapps.student.tests.factories import StaffFactory +from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.util.milestones_helpers import fulfill_course_milestone, set_prerequisite_courses from xmodule.course_module import ( CATALOG_VISIBILITY_ABOUT, diff --git a/lms/djangoapps/courseware/tests/test_entrance_exam.py b/lms/djangoapps/courseware/tests/test_entrance_exam.py index 807f2cdd53..fb8a6d571e 100644 --- a/lms/djangoapps/courseware/tests/test_entrance_exam.py +++ b/lms/djangoapps/courseware/tests/test_entrance_exam.py @@ -18,13 +18,14 @@ from lms.djangoapps.courseware.entrance_exams import ( ) from lms.djangoapps.courseware.model_data import FieldDataCache from lms.djangoapps.courseware.module_render import get_module, handle_xblock_callback, toc_for_course -from lms.djangoapps.courseware.tests.factories import InstructorFactory, RequestFactoryNoCsrf, UserFactory +from lms.djangoapps.courseware.tests.factories import InstructorFactory, RequestFactoryNoCsrf from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from openedx.core.djangolib.testing.utils import get_mock_request from openedx.features.course_experience import DISABLE_COURSE_OUTLINE_PAGE_FLAG, DISABLE_UNIFIED_COURSE_TAB_FLAG from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import AnonymousUserFactory, CourseEnrollmentFactory from common.djangoapps.student.tests.factories import StaffFactory +from common.djangoapps.student.tests.factories import UserFactory from common.djangoapps.util.milestones_helpers import ( add_course_content_milestone, add_course_milestone, diff --git a/lms/djangoapps/courseware/tests/test_group_access.py b/lms/djangoapps/courseware/tests/test_group_access.py index 3d1a234a18..67b8fff580 100644 --- a/lms/djangoapps/courseware/tests/test_group_access.py +++ b/lms/djangoapps/courseware/tests/test_group_access.py @@ -8,8 +8,8 @@ import ddt from stevedore.extension import Extension, ExtensionManager from common.djangoapps.student.tests.factories import StaffFactory +from common.djangoapps.student.tests.factories import UserFactory import lms.djangoapps.courseware.access as access -from lms.djangoapps.courseware.tests.factories import UserFactory from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index d1f348b745..4725c74acb 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -43,6 +43,7 @@ from xblock.test.tools import TestRuntime # lint-amnesty, pylint: disable=wrong from capa.tests.response_xml_factory import OptionResponseXMLFactory # lint-amnesty, pylint: disable=reimported from common.djangoapps.course_modes.models import CourseMode # lint-amnesty, pylint: disable=reimported from common.djangoapps.student.tests.factories import GlobalStaffFactory +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware import module_render as render from lms.djangoapps.courseware.access_response import AccessResponse from lms.djangoapps.courseware.courses import get_course_info_section, get_course_with_access @@ -54,7 +55,6 @@ from lms.djangoapps.courseware.module_render import get_module_for_descriptor, h from lms.djangoapps.courseware.tests.factories import ( RequestFactoryNoCsrf, StudentModuleFactory, - UserFactory ) from lms.djangoapps.courseware.tests.test_submitting_problems import TestSubmittingProblems from lms.djangoapps.courseware.tests.tests import LoginEnrollmentTestCase diff --git a/lms/djangoapps/courseware/tests/test_services.py b/lms/djangoapps/courseware/tests/test_services.py index 17104f0252..c8f25805d4 100644 --- a/lms/djangoapps/courseware/tests/test_services.py +++ b/lms/djangoapps/courseware/tests/test_services.py @@ -8,8 +8,9 @@ import json import ddt +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.services import UserStateService -from lms.djangoapps.courseware.tests.factories import StudentModuleFactory, UserFactory +from lms.djangoapps.courseware.tests.factories import StudentModuleFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory diff --git a/lms/djangoapps/courseware/tests/test_user_state_client.py b/lms/djangoapps/courseware/tests/test_user_state_client.py index acf5fe9cf0..1a78d52b21 100644 --- a/lms/djangoapps/courseware/tests/test_user_state_client.py +++ b/lms/djangoapps/courseware/tests/test_user_state_client.py @@ -10,7 +10,7 @@ from django.db import connections from edx_user_state_client.tests import UserStateClientTestBase -from lms.djangoapps.courseware.tests.factories import UserFactory +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py index adad7a705b..bad67e932c 100644 --- a/lms/djangoapps/instructor/tests/test_api.py +++ b/lms/djangoapps/instructor/tests/test_api.py @@ -52,9 +52,10 @@ from common.djangoapps.student.roles import ( CourseFinanceAdminRole, CourseInstructorRole, ) -from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory +from common.djangoapps.student.tests.factories import CourseEnrollmentFactory from common.djangoapps.student.tests.factories import GlobalStaffFactory from common.djangoapps.student.tests.factories import StaffFactory +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.bulk_email.models import BulkEmailFlag, CourseEmail, CourseEmailTemplate from lms.djangoapps.certificates.api import generate_user_certificates from lms.djangoapps.certificates.models import CertificateStatuses diff --git a/lms/djangoapps/instructor/tests/test_certificates.py b/lms/djangoapps/instructor/tests/test_certificates.py index 962db41a9e..a4bcce421a 100644 --- a/lms/djangoapps/instructor/tests/test_certificates.py +++ b/lms/djangoapps/instructor/tests/test_certificates.py @@ -21,6 +21,7 @@ from capa.xqueue_interface import XQueueInterface from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.tests.factories import GlobalStaffFactory +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.certificates import api as certs_api from lms.djangoapps.certificates.models import ( CertificateGenerationConfiguration, @@ -34,7 +35,7 @@ from lms.djangoapps.certificates.tests.factories import ( CertificateWhitelistFactory, GeneratedCertificateFactory ) -from lms.djangoapps.courseware.tests.factories import InstructorFactory, UserFactory +from lms.djangoapps.courseware.tests.factories import InstructorFactory from lms.djangoapps.grades.tests.utils import mock_passing_grade from lms.djangoapps.verify_student.services import IDVerificationService from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index 730f61e1c0..5a58599dd6 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -22,9 +22,10 @@ from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.roles import CourseFinanceAdminRole # lint-amnesty, pylint: disable=unused-import from common.djangoapps.student.tests.factories import AdminFactory, CourseAccessRoleFactory, CourseEnrollmentFactory from common.djangoapps.student.tests.factories import StaffFactory +from common.djangoapps.student.tests.factories import UserFactory from common.test.utils import XssTestMixin from lms.djangoapps.courseware.tabs import get_course_tab_list -from lms.djangoapps.courseware.tests.factories import StudentModuleFactory, UserFactory +from lms.djangoapps.courseware.tests.factories import StudentModuleFactory from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase from lms.djangoapps.grades.config.waffle import WRITABLE_GRADEBOOK, waffle_flags from lms.djangoapps.instructor.toggles import DATA_DOWNLOAD_V2 diff --git a/lms/djangoapps/instructor_task/tests/test_api.py b/lms/djangoapps/instructor_task/tests/test_api.py index 1fec1a466d..911c56c847 100644 --- a/lms/djangoapps/instructor_task/tests/test_api.py +++ b/lms/djangoapps/instructor_task/tests/test_api.py @@ -8,10 +8,10 @@ import pytest import ddt from celery.states import FAILURE +from common.djangoapps.student.tests.factories import UserFactory from common.test.utils import normalize_repr from lms.djangoapps.bulk_email.models import SEND_TO_LEARNERS, SEND_TO_MYSELF, SEND_TO_STAFF, CourseEmail from lms.djangoapps.certificates.models import CertificateGenerationHistory, CertificateStatuses -from lms.djangoapps.courseware.tests.factories import UserFactory from lms.djangoapps.instructor_task.api import ( SpecificStudentIdMissingError, generate_certificates_for_students, diff --git a/lms/djangoapps/mobile_api/testutils.py b/lms/djangoapps/mobile_api/testutils.py index 8eeabd9413..328b8425a0 100644 --- a/lms/djangoapps/mobile_api/testutils.py +++ b/lms/djangoapps/mobile_api/testutils.py @@ -25,8 +25,8 @@ from rest_framework.test import APITestCase from common.djangoapps.student import auth from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.courseware.access_response import MobileAvailabilityError, StartDateError, VisibilityError -from lms.djangoapps.courseware.tests.factories import UserFactory from lms.djangoapps.mobile_api.models import IgnoreMobileAvailableFlagConfig from lms.djangoapps.mobile_api.tests.test_milestones import MobileAPIMilestonesMixin from lms.djangoapps.mobile_api.utils import API_V1 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 850100d757..05a26cac65 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,8 +10,6 @@ from django.conf import settings from django.core.management import call_command from testfixtures import LogCapture -from common.djangoapps.student.tests.factories import \ - UserFactory # lint-amnesty, pylint: disable=import-error, unused-import, useless-suppression from common.test.utils import MockS3BotoMixin from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification, SSPVerificationRetryConfig from lms.djangoapps.verify_student.tests import TestVerificationBase diff --git a/lms/lib/courseware_search/test/test_lms_result_processor.py b/lms/lib/courseware_search/test/test_lms_result_processor.py index f390025fa5..cc221952e8 100644 --- a/lms/lib/courseware_search/test/test_lms_result_processor.py +++ b/lms/lib/courseware_search/test/test_lms_result_processor.py @@ -3,7 +3,7 @@ Tests for the lms_result_processor """ import pytest -from lms.djangoapps.courseware.tests.factories import UserFactory +from common.djangoapps.student.tests.factories import UserFactory from lms.lib.courseware_search.lms_result_processor import LmsSearchResultProcessor from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory