Remove the create_user argument to setUp.
Instead, use a class attribute to define test behavior. This allows for easier addition of new mixins over time.
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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):
|
||||
'''
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user