diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_create_course.py b/cms/djangoapps/contentstore/management/commands/tests/test_create_course.py index 5ae88a9345..32fff608a4 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_create_course.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_create_course.py @@ -46,9 +46,6 @@ class TestCreateCourse(ModuleStoreTestCase): Unit tests for creating a course in either old mongo or split mongo via command line """ - def setUp(self): - super(TestCreateCourse, self).setUp(create_user=True) - @ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split) def test_all_stores_user_email(self, store): call_command( diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py b/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py index 49805090f4..780b96e99c 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py @@ -59,7 +59,7 @@ class TestMigrateToSplit(ModuleStoreTestCase): """ def setUp(self): - super(TestMigrateToSplit, self).setUp(create_user=True) + super(TestMigrateToSplit, self).setUp() self.course = CourseFactory(default_store=ModuleStoreEnum.Type.mongo) def test_user_email(self): diff --git a/cms/djangoapps/contentstore/tests/test_i18n.py b/cms/djangoapps/contentstore/tests/test_i18n.py index 88b31b3150..2a2880a8e3 100644 --- a/cms/djangoapps/contentstore/tests/test_i18n.py +++ b/cms/djangoapps/contentstore/tests/test_i18n.py @@ -167,6 +167,8 @@ class InternationalizationTest(ModuleStoreTestCase): Tests to validate Internationalization. """ + CREATE_USER = False + def setUp(self): """ These tests need a user in the DB so that the django Test Client @@ -175,7 +177,7 @@ class InternationalizationTest(ModuleStoreTestCase): will be cleared out before each test case execution and deleted afterwards. """ - super(InternationalizationTest, self).setUp(create_user=False) + super(InternationalizationTest, self).setUp() self.uname = 'testuser' self.email = 'test+courses@edx.org' diff --git a/cms/djangoapps/contentstore/tests/test_import.py b/cms/djangoapps/contentstore/tests/test_import.py index a4675632a2..caea0e772d 100644 --- a/cms/djangoapps/contentstore/tests/test_import.py +++ b/cms/djangoapps/contentstore/tests/test_import.py @@ -34,10 +34,10 @@ class ContentStoreImportTest(SignalDisconnectTestMixin, ModuleStoreTestCase): NOTE: refactor using CourseFactory so they do not. """ def setUp(self): - password = super(ContentStoreImportTest, self).setUp() + super(ContentStoreImportTest, self).setUp() self.client = Client() - self.client.login(username=self.user.username, password=password) + self.client.login(username=self.user.username, password=self.user_password) def load_test_import_course(self, target_id=None, create_if_not_present=True, module_store=None): ''' diff --git a/cms/djangoapps/contentstore/tests/test_libraries.py b/cms/djangoapps/contentstore/tests/test_libraries.py index 5558c57625..529396e087 100644 --- a/cms/djangoapps/contentstore/tests/test_libraries.py +++ b/cms/djangoapps/contentstore/tests/test_libraries.py @@ -32,7 +32,7 @@ class LibraryTestCase(ModuleStoreTestCase): Common functionality for content libraries tests """ def setUp(self): - self.user_password = super(LibraryTestCase, self).setUp() + super(LibraryTestCase, self).setUp() self.client = AjaxEnabledTestClient() self._login_as_staff_user(logout_first=False) diff --git a/cms/djangoapps/contentstore/tests/test_permissions.py b/cms/djangoapps/contentstore/tests/test_permissions.py index f509e807f2..7fb8509c39 100644 --- a/cms/djangoapps/contentstore/tests/test_permissions.py +++ b/cms/djangoapps/contentstore/tests/test_permissions.py @@ -22,10 +22,10 @@ class TestCourseAccess(ModuleStoreTestCase): Create a pool of users w/o granting them any permissions """ - user_password = super(TestCourseAccess, self).setUp() + super(TestCourseAccess, self).setUp() self.client = AjaxEnabledTestClient() - self.client.login(username=self.user.username, password=user_password) + self.client.login(username=self.user.username, password=self.user_password) # create a course via the view handler which has a different strategy for permissions than the factory self.course_key = self.store.make_course_key('myu', 'mydept.mycourse', 'myrun') diff --git a/cms/djangoapps/contentstore/tests/tests.py b/cms/djangoapps/contentstore/tests/tests.py index 2a2f267b3a..7bb105d191 100644 --- a/cms/djangoapps/contentstore/tests/tests.py +++ b/cms/djangoapps/contentstore/tests/tests.py @@ -88,9 +88,11 @@ class ContentStoreTestCase(ModuleStoreTestCase): class AuthTestCase(ContentStoreTestCase): """Check that various permissions-related things work""" + + CREATE_USER = False def setUp(self): - super(AuthTestCase, self).setUp(create_user=False) + super(AuthTestCase, self).setUp() self.email = 'a@b.com' self.pw = 'xyz' diff --git a/cms/djangoapps/contentstore/tests/utils.py b/cms/djangoapps/contentstore/tests/utils.py index 237d04a756..2026295c9e 100644 --- a/cms/djangoapps/contentstore/tests/utils.py +++ b/cms/djangoapps/contentstore/tests/utils.py @@ -81,7 +81,7 @@ class CourseTestCase(ProceduralCourseTestMixin, ModuleStoreTestCase): afterwards. """ - self.user_password = super(CourseTestCase, self).setUp() + super(CourseTestCase, self).setUp() self.client = AjaxEnabledTestClient() self.client.login(username=self.user.username, password=self.user_password) diff --git a/cms/djangoapps/contentstore/views/tests/test_library.py b/cms/djangoapps/contentstore/views/tests/test_library.py index 9e1abbbdf0..2a704c002d 100644 --- a/cms/djangoapps/contentstore/views/tests/test_library.py +++ b/cms/djangoapps/contentstore/views/tests/test_library.py @@ -30,10 +30,10 @@ class UnitTestLibraries(ModuleStoreTestCase): """ def setUp(self): - user_password = super(UnitTestLibraries, self).setUp() + super(UnitTestLibraries, self).setUp() self.client = AjaxEnabledTestClient() - self.client.login(username=self.user.username, password=user_password) + self.client.login(username=self.user.username, password=self.user_password) ###################################################### # Tests for /library/ - list and create libraries: diff --git a/cms/lib/xblock/tagging/test.py b/cms/lib/xblock/tagging/test.py index 1b6227e90f..2097ea61b0 100644 --- a/cms/lib/xblock/tagging/test.py +++ b/cms/lib/xblock/tagging/test.py @@ -32,7 +32,7 @@ class StructuredTagsAsideTestCase(ModuleStoreTestCase): """ Preparation for the test execution """ - self.user_password = super(StructuredTagsAsideTestCase, self).setUp() + super(StructuredTagsAsideTestCase, self).setUp() self.aside_name = 'tagging_aside' self.aside_tag_dif = 'difficulty' self.aside_tag_dif_value = 'Hard' diff --git a/common/djangoapps/third_party_auth/tests/utils.py b/common/djangoapps/third_party_auth/tests/utils.py index 588d23dce9..a5ac1e6bc4 100644 --- a/common/djangoapps/third_party_auth/tests/utils.py +++ b/common/djangoapps/third_party_auth/tests/utils.py @@ -26,9 +26,11 @@ class ThirdPartyOAuthTestMixin(ThirdPartyAuthTestMixin): access_token = "test_access_token" client_id = "test_client_id" - def setUp(self, create_user=True): + CREATE_USER = True + + def setUp(self): super(ThirdPartyOAuthTestMixin, self).setUp() - if create_user: + if self.CREATE_USER: self.user = UserFactory() UserSocialAuth.objects.create(user=self.user, provider=self.BACKEND, uid=self.social_uid) self.oauth_client = self._create_client() diff --git a/common/djangoapps/util/tests/test_keyword_sub_utils.py b/common/djangoapps/util/tests/test_keyword_sub_utils.py index e9d2381f5c..978aa794b0 100644 --- a/common/djangoapps/util/tests/test_keyword_sub_utils.py +++ b/common/djangoapps/util/tests/test_keyword_sub_utils.py @@ -17,8 +17,10 @@ from util import keyword_substitution as Ks class KeywordSubTest(ModuleStoreTestCase): """ Tests for the keyword substitution feature """ + CREATE_USER = False + def setUp(self): - super(KeywordSubTest, self).setUp(create_user=False) + super(KeywordSubTest, self).setUp() self.user = UserFactory.create( email="testuser@edx.org", username="testuser", diff --git a/common/djangoapps/util/tests/test_milestones_helpers.py b/common/djangoapps/util/tests/test_milestones_helpers.py index d04193d179..ad43c853b0 100644 --- a/common/djangoapps/util/tests/test_milestones_helpers.py +++ b/common/djangoapps/util/tests/test_milestones_helpers.py @@ -18,11 +18,13 @@ class MilestonesHelpersTestCase(ModuleStoreTestCase): Main test suite for Milestones API client library """ + CREATE_USER = False + def setUp(self): """ Test case scaffolding """ - super(MilestonesHelpersTestCase, self).setUp(create_user=False) + super(MilestonesHelpersTestCase, self).setUp() self.course = CourseFactory.create( metadata={ 'entrance_exam_enabled': True, diff --git a/common/djangoapps/util/tests/test_organizations_helpers.py b/common/djangoapps/util/tests/test_organizations_helpers.py index 3c607401ea..921e801b67 100644 --- a/common/djangoapps/util/tests/test_organizations_helpers.py +++ b/common/djangoapps/util/tests/test_organizations_helpers.py @@ -14,11 +14,13 @@ class OrganizationsHelpersTestCase(ModuleStoreTestCase): Main test suite for Organizations API client library """ + CREATE_USER = False + def setUp(self): """ Test case scaffolding """ - super(OrganizationsHelpersTestCase, self).setUp(create_user=False) + super(OrganizationsHelpersTestCase, self).setUp() self.course = CourseFactory.create() self.organization = { diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py index 8e91f8d920..0b3108bdb9 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py @@ -383,16 +383,16 @@ class ModuleStoreTestCase(TestCase): """ MODULESTORE = mixed_store_config(mkdtemp_clean(), {}) + + CREATE_USER = True + # Tell Django to clean out all databases, not just default multi_db = True - def setUp(self, **kwargs): + def setUp(self): """ - Creates a test User if `create_user` is True. - Returns the password for the test User. - - Args: - create_user - specifies whether or not to create a test User. Default is True. + Creates a test User if `self.CREATE_USER` is True. + Sets the password as self.user_password. """ settings_override = override_settings(MODULESTORE=self.MODULESTORE) settings_override.__enter__() @@ -422,11 +422,11 @@ class ModuleStoreTestCase(TestCase): uname = 'testuser' email = 'test+courses@edx.org' - password = 'foo' + self.user_password = 'foo' - if kwargs.pop('create_user', True): + if self.CREATE_USER: # Create the user so we can log them in. - self.user = User.objects.create_user(uname, email, password) + self.user = User.objects.create_user(uname, email, self.user_password) # Note that we do not actually need to do anything # for registration if we directly mark them active. @@ -436,7 +436,6 @@ class ModuleStoreTestCase(TestCase): self.user.is_staff = True self.user.save() - return password def create_non_staff_user(self): """ diff --git a/lms/djangoapps/course_blocks/tests/test_signals.py b/lms/djangoapps/course_blocks/tests/test_signals.py index 8c232a0f49..9f63279b31 100644 --- a/lms/djangoapps/course_blocks/tests/test_signals.py +++ b/lms/djangoapps/course_blocks/tests/test_signals.py @@ -17,7 +17,7 @@ class CourseBlocksSignalTest(EnableTransformerRegistryMixin, ModuleStoreTestCase """ def setUp(self): - super(CourseBlocksSignalTest, self).setUp(create_user=True) + super(CourseBlocksSignalTest, self).setUp() self.course = CourseFactory.create() self.course_usage_key = self.store.make_course_usage_key(self.course.id) diff --git a/lms/djangoapps/django_comment_client/base/tests.py b/lms/djangoapps/django_comment_client/base/tests.py index 1df1b28ffb..43c0e56aaf 100644 --- a/lms/djangoapps/django_comment_client/base/tests.py +++ b/lms/djangoapps/django_comment_client/base/tests.py @@ -350,9 +350,11 @@ class ViewsTestCaseMixin(object): @disable_signal(views, 'thread_edited') class ViewsQueryCountTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin, ViewsTestCaseMixin): + CREATE_USER = False + @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) def setUp(self): - super(ViewsQueryCountTestCase, self).setUp(create_user=False) + super(ViewsQueryCountTestCase, self).setUp() def clear_caches(self): """Clears caches so that query count numbers are accurate.""" diff --git a/lms/djangoapps/django_comment_client/forum/tests.py b/lms/djangoapps/django_comment_client/forum/tests.py index 66323a1968..8f95be74c3 100644 --- a/lms/djangoapps/django_comment_client/forum/tests.py +++ b/lms/djangoapps/django_comment_client/forum/tests.py @@ -220,8 +220,11 @@ class PartialDictMatcher(object): @patch('requests.request', autospec=True) class SingleThreadTestCase(ModuleStoreTestCase): + + CREATE_USER = False + def setUp(self): - super(SingleThreadTestCase, self).setUp(create_user=False) + super(SingleThreadTestCase, self).setUp() self.course = CourseFactory.create(discussion_topics={'dummy discussion': {'id': 'dummy_discussion_id'}}) self.student = UserFactory.create() @@ -1223,6 +1226,9 @@ class UserProfileTestCase(ModuleStoreTestCase): @patch('requests.request', autospec=True) class CommentsServiceRequestHeadersTestCase(UrlResetMixin, ModuleStoreTestCase): + + CREATE_USER = False + @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) def setUp(self): super(CommentsServiceRequestHeadersTestCase, self).setUp() @@ -1231,7 +1237,7 @@ class CommentsServiceRequestHeadersTestCase(UrlResetMixin, ModuleStoreTestCase): password = "bar" # Invoke UrlResetMixin - super(CommentsServiceRequestHeadersTestCase, self).setUp(create_user=False) + super(CommentsServiceRequestHeadersTestCase, self).setUp() self.course = CourseFactory.create(discussion_topics={'dummy discussion': {'id': 'dummy_discussion_id'}}) self.student = UserFactory.create(username=username, password=password) CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id) diff --git a/lms/djangoapps/django_comment_client/tests/test_utils.py b/lms/djangoapps/django_comment_client/tests/test_utils.py index 1da5e5ea4b..c8d13e8751 100644 --- a/lms/djangoapps/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/django_comment_client/tests/test_utils.py @@ -63,8 +63,10 @@ class AccessUtilsTestCase(ModuleStoreTestCase): Base testcase class for access and roles for the comment client service integration """ + CREATE_USER = False + def setUp(self): - super(AccessUtilsTestCase, self).setUp(create_user=False) + super(AccessUtilsTestCase, self).setUp() self.course = CourseFactory.create() self.course_id = self.course.id @@ -118,7 +120,7 @@ class CoursewareContextTestCase(ModuleStoreTestCase): comment client service integration """ def setUp(self): - super(CoursewareContextTestCase, self).setUp(create_user=True) + super(CoursewareContextTestCase, self).setUp() self.course = CourseFactory.create(org="TestX", number="101", display_name="Test Course") self.discussion1 = ItemFactory.create( @@ -206,7 +208,7 @@ class CachedDiscussionIdMapTestCase(ModuleStoreTestCase): Tests that using the cache of discussion id mappings has the same behavior as searching through the course. """ def setUp(self): - super(CachedDiscussionIdMapTestCase, self).setUp(create_user=True) + super(CachedDiscussionIdMapTestCase, self).setUp() self.course = CourseFactory.create(org='TestX', number='101', display_name='Test Course') self.discussion = ItemFactory.create( @@ -340,7 +342,7 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase): comment client service integration """ def setUp(self): - super(CategoryMapTestCase, self).setUp(create_user=True) + super(CategoryMapTestCase, self).setUp() self.course = CourseFactory.create( org="TestX", number="101", display_name="Test Course", diff --git a/openedx/core/djangoapps/user_api/tests/test_views.py b/openedx/core/djangoapps/user_api/tests/test_views.py index b67a701d25..ad9177e19c 100644 --- a/openedx/core/djangoapps/user_api/tests/test_views.py +++ b/openedx/core/djangoapps/user_api/tests/test_views.py @@ -1729,8 +1729,10 @@ class ThirdPartyRegistrationTestMixin(ThirdPartyOAuthTestMixin): """ Tests for the User API registration endpoint with 3rd party authentication. """ + CREATE_USER = False + def setUp(self): - super(ThirdPartyRegistrationTestMixin, self).setUp(create_user=False) + super(ThirdPartyRegistrationTestMixin, self).setUp() self.url = reverse('user_api_registration') def data(self, user=None):