Commit 18e16100 by Calen Pennington

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.
parent 39ff841d
...@@ -46,9 +46,6 @@ class TestCreateCourse(ModuleStoreTestCase): ...@@ -46,9 +46,6 @@ class TestCreateCourse(ModuleStoreTestCase):
Unit tests for creating a course in either old mongo or split mongo via command line 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) @ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_all_stores_user_email(self, store): def test_all_stores_user_email(self, store):
call_command( call_command(
......
...@@ -59,7 +59,7 @@ class TestMigrateToSplit(ModuleStoreTestCase): ...@@ -59,7 +59,7 @@ class TestMigrateToSplit(ModuleStoreTestCase):
""" """
def setUp(self): def setUp(self):
super(TestMigrateToSplit, self).setUp(create_user=True) super(TestMigrateToSplit, self).setUp()
self.course = CourseFactory(default_store=ModuleStoreEnum.Type.mongo) self.course = CourseFactory(default_store=ModuleStoreEnum.Type.mongo)
def test_user_email(self): def test_user_email(self):
......
...@@ -167,6 +167,8 @@ class InternationalizationTest(ModuleStoreTestCase): ...@@ -167,6 +167,8 @@ class InternationalizationTest(ModuleStoreTestCase):
Tests to validate Internationalization. Tests to validate Internationalization.
""" """
CREATE_USER = False
def setUp(self): def setUp(self):
""" """
These tests need a user in the DB so that the django Test Client These tests need a user in the DB so that the django Test Client
...@@ -175,7 +177,7 @@ class InternationalizationTest(ModuleStoreTestCase): ...@@ -175,7 +177,7 @@ class InternationalizationTest(ModuleStoreTestCase):
will be cleared out before each test case execution and deleted will be cleared out before each test case execution and deleted
afterwards. afterwards.
""" """
super(InternationalizationTest, self).setUp(create_user=False) super(InternationalizationTest, self).setUp()
self.uname = 'testuser' self.uname = 'testuser'
self.email = 'test+courses@edx.org' self.email = 'test+courses@edx.org'
......
...@@ -34,10 +34,10 @@ class ContentStoreImportTest(SignalDisconnectTestMixin, ModuleStoreTestCase): ...@@ -34,10 +34,10 @@ class ContentStoreImportTest(SignalDisconnectTestMixin, ModuleStoreTestCase):
NOTE: refactor using CourseFactory so they do not. NOTE: refactor using CourseFactory so they do not.
""" """
def setUp(self): def setUp(self):
password = super(ContentStoreImportTest, self).setUp() super(ContentStoreImportTest, self).setUp()
self.client = Client() 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): def load_test_import_course(self, target_id=None, create_if_not_present=True, module_store=None):
''' '''
......
...@@ -32,7 +32,7 @@ class LibraryTestCase(ModuleStoreTestCase): ...@@ -32,7 +32,7 @@ class LibraryTestCase(ModuleStoreTestCase):
Common functionality for content libraries tests Common functionality for content libraries tests
""" """
def setUp(self): def setUp(self):
self.user_password = super(LibraryTestCase, self).setUp() super(LibraryTestCase, self).setUp()
self.client = AjaxEnabledTestClient() self.client = AjaxEnabledTestClient()
self._login_as_staff_user(logout_first=False) self._login_as_staff_user(logout_first=False)
......
...@@ -22,10 +22,10 @@ class TestCourseAccess(ModuleStoreTestCase): ...@@ -22,10 +22,10 @@ class TestCourseAccess(ModuleStoreTestCase):
Create a pool of users w/o granting them any permissions 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 = 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 # 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') self.course_key = self.store.make_course_key('myu', 'mydept.mycourse', 'myrun')
......
...@@ -88,9 +88,11 @@ class ContentStoreTestCase(ModuleStoreTestCase): ...@@ -88,9 +88,11 @@ class ContentStoreTestCase(ModuleStoreTestCase):
class AuthTestCase(ContentStoreTestCase): class AuthTestCase(ContentStoreTestCase):
"""Check that various permissions-related things work""" """Check that various permissions-related things work"""
CREATE_USER = False
def setUp(self): def setUp(self):
super(AuthTestCase, self).setUp(create_user=False) super(AuthTestCase, self).setUp()
self.email = 'a@b.com' self.email = 'a@b.com'
self.pw = 'xyz' self.pw = 'xyz'
......
...@@ -81,7 +81,7 @@ class CourseTestCase(ProceduralCourseTestMixin, ModuleStoreTestCase): ...@@ -81,7 +81,7 @@ class CourseTestCase(ProceduralCourseTestMixin, ModuleStoreTestCase):
afterwards. afterwards.
""" """
self.user_password = super(CourseTestCase, self).setUp() super(CourseTestCase, self).setUp()
self.client = AjaxEnabledTestClient() self.client = AjaxEnabledTestClient()
self.client.login(username=self.user.username, password=self.user_password) self.client.login(username=self.user.username, password=self.user_password)
......
...@@ -30,10 +30,10 @@ class UnitTestLibraries(ModuleStoreTestCase): ...@@ -30,10 +30,10 @@ class UnitTestLibraries(ModuleStoreTestCase):
""" """
def setUp(self): def setUp(self):
user_password = super(UnitTestLibraries, self).setUp() super(UnitTestLibraries, self).setUp()
self.client = AjaxEnabledTestClient() 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: # Tests for /library/ - list and create libraries:
......
...@@ -32,7 +32,7 @@ class StructuredTagsAsideTestCase(ModuleStoreTestCase): ...@@ -32,7 +32,7 @@ class StructuredTagsAsideTestCase(ModuleStoreTestCase):
""" """
Preparation for the test execution Preparation for the test execution
""" """
self.user_password = super(StructuredTagsAsideTestCase, self).setUp() super(StructuredTagsAsideTestCase, self).setUp()
self.aside_name = 'tagging_aside' self.aside_name = 'tagging_aside'
self.aside_tag_dif = 'difficulty' self.aside_tag_dif = 'difficulty'
self.aside_tag_dif_value = 'Hard' self.aside_tag_dif_value = 'Hard'
......
...@@ -26,9 +26,11 @@ class ThirdPartyOAuthTestMixin(ThirdPartyAuthTestMixin): ...@@ -26,9 +26,11 @@ class ThirdPartyOAuthTestMixin(ThirdPartyAuthTestMixin):
access_token = "test_access_token" access_token = "test_access_token"
client_id = "test_client_id" client_id = "test_client_id"
def setUp(self, create_user=True): CREATE_USER = True
def setUp(self):
super(ThirdPartyOAuthTestMixin, self).setUp() super(ThirdPartyOAuthTestMixin, self).setUp()
if create_user: if self.CREATE_USER:
self.user = UserFactory() self.user = UserFactory()
UserSocialAuth.objects.create(user=self.user, provider=self.BACKEND, uid=self.social_uid) UserSocialAuth.objects.create(user=self.user, provider=self.BACKEND, uid=self.social_uid)
self.oauth_client = self._create_client() self.oauth_client = self._create_client()
......
...@@ -17,8 +17,10 @@ from util import keyword_substitution as Ks ...@@ -17,8 +17,10 @@ from util import keyword_substitution as Ks
class KeywordSubTest(ModuleStoreTestCase): class KeywordSubTest(ModuleStoreTestCase):
""" Tests for the keyword substitution feature """ """ Tests for the keyword substitution feature """
CREATE_USER = False
def setUp(self): def setUp(self):
super(KeywordSubTest, self).setUp(create_user=False) super(KeywordSubTest, self).setUp()
self.user = UserFactory.create( self.user = UserFactory.create(
email="testuser@edx.org", email="testuser@edx.org",
username="testuser", username="testuser",
......
...@@ -18,11 +18,13 @@ class MilestonesHelpersTestCase(ModuleStoreTestCase): ...@@ -18,11 +18,13 @@ class MilestonesHelpersTestCase(ModuleStoreTestCase):
Main test suite for Milestones API client library Main test suite for Milestones API client library
""" """
CREATE_USER = False
def setUp(self): def setUp(self):
""" """
Test case scaffolding Test case scaffolding
""" """
super(MilestonesHelpersTestCase, self).setUp(create_user=False) super(MilestonesHelpersTestCase, self).setUp()
self.course = CourseFactory.create( self.course = CourseFactory.create(
metadata={ metadata={
'entrance_exam_enabled': True, 'entrance_exam_enabled': True,
......
...@@ -14,11 +14,13 @@ class OrganizationsHelpersTestCase(ModuleStoreTestCase): ...@@ -14,11 +14,13 @@ class OrganizationsHelpersTestCase(ModuleStoreTestCase):
Main test suite for Organizations API client library Main test suite for Organizations API client library
""" """
CREATE_USER = False
def setUp(self): def setUp(self):
""" """
Test case scaffolding Test case scaffolding
""" """
super(OrganizationsHelpersTestCase, self).setUp(create_user=False) super(OrganizationsHelpersTestCase, self).setUp()
self.course = CourseFactory.create() self.course = CourseFactory.create()
self.organization = { self.organization = {
......
...@@ -383,16 +383,16 @@ class ModuleStoreTestCase(TestCase): ...@@ -383,16 +383,16 @@ class ModuleStoreTestCase(TestCase):
""" """
MODULESTORE = mixed_store_config(mkdtemp_clean(), {}) MODULESTORE = mixed_store_config(mkdtemp_clean(), {})
CREATE_USER = True
# Tell Django to clean out all databases, not just default # Tell Django to clean out all databases, not just default
multi_db = True multi_db = True
def setUp(self, **kwargs): def setUp(self):
""" """
Creates a test User if `create_user` is True. Creates a test User if `self.CREATE_USER` is True.
Returns the password for the test User. Sets the password as self.user_password.
Args:
create_user - specifies whether or not to create a test User. Default is True.
""" """
settings_override = override_settings(MODULESTORE=self.MODULESTORE) settings_override = override_settings(MODULESTORE=self.MODULESTORE)
settings_override.__enter__() settings_override.__enter__()
...@@ -422,11 +422,11 @@ class ModuleStoreTestCase(TestCase): ...@@ -422,11 +422,11 @@ class ModuleStoreTestCase(TestCase):
uname = 'testuser' uname = 'testuser'
email = 'test+courses@edx.org' 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. # 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 # Note that we do not actually need to do anything
# for registration if we directly mark them active. # for registration if we directly mark them active.
...@@ -436,7 +436,6 @@ class ModuleStoreTestCase(TestCase): ...@@ -436,7 +436,6 @@ class ModuleStoreTestCase(TestCase):
self.user.is_staff = True self.user.is_staff = True
self.user.save() self.user.save()
return password
def create_non_staff_user(self): def create_non_staff_user(self):
""" """
......
...@@ -17,7 +17,7 @@ class CourseBlocksSignalTest(EnableTransformerRegistryMixin, ModuleStoreTestCase ...@@ -17,7 +17,7 @@ class CourseBlocksSignalTest(EnableTransformerRegistryMixin, ModuleStoreTestCase
""" """
def setUp(self): def setUp(self):
super(CourseBlocksSignalTest, self).setUp(create_user=True) super(CourseBlocksSignalTest, self).setUp()
self.course = CourseFactory.create() self.course = CourseFactory.create()
self.course_usage_key = self.store.make_course_usage_key(self.course.id) self.course_usage_key = self.store.make_course_usage_key(self.course.id)
......
...@@ -350,9 +350,11 @@ class ViewsTestCaseMixin(object): ...@@ -350,9 +350,11 @@ class ViewsTestCaseMixin(object):
@disable_signal(views, 'thread_edited') @disable_signal(views, 'thread_edited')
class ViewsQueryCountTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin, ViewsTestCaseMixin): class ViewsQueryCountTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin, ViewsTestCaseMixin):
CREATE_USER = False
@patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
def setUp(self): def setUp(self):
super(ViewsQueryCountTestCase, self).setUp(create_user=False) super(ViewsQueryCountTestCase, self).setUp()
def clear_caches(self): def clear_caches(self):
"""Clears caches so that query count numbers are accurate.""" """Clears caches so that query count numbers are accurate."""
......
...@@ -220,8 +220,11 @@ class PartialDictMatcher(object): ...@@ -220,8 +220,11 @@ class PartialDictMatcher(object):
@patch('requests.request', autospec=True) @patch('requests.request', autospec=True)
class SingleThreadTestCase(ModuleStoreTestCase): class SingleThreadTestCase(ModuleStoreTestCase):
CREATE_USER = False
def setUp(self): 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.course = CourseFactory.create(discussion_topics={'dummy discussion': {'id': 'dummy_discussion_id'}})
self.student = UserFactory.create() self.student = UserFactory.create()
...@@ -1223,6 +1226,9 @@ class UserProfileTestCase(ModuleStoreTestCase): ...@@ -1223,6 +1226,9 @@ class UserProfileTestCase(ModuleStoreTestCase):
@patch('requests.request', autospec=True) @patch('requests.request', autospec=True)
class CommentsServiceRequestHeadersTestCase(UrlResetMixin, ModuleStoreTestCase): class CommentsServiceRequestHeadersTestCase(UrlResetMixin, ModuleStoreTestCase):
CREATE_USER = False
@patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True}) @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
def setUp(self): def setUp(self):
super(CommentsServiceRequestHeadersTestCase, self).setUp() super(CommentsServiceRequestHeadersTestCase, self).setUp()
...@@ -1231,7 +1237,7 @@ class CommentsServiceRequestHeadersTestCase(UrlResetMixin, ModuleStoreTestCase): ...@@ -1231,7 +1237,7 @@ class CommentsServiceRequestHeadersTestCase(UrlResetMixin, ModuleStoreTestCase):
password = "bar" password = "bar"
# Invoke UrlResetMixin # 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.course = CourseFactory.create(discussion_topics={'dummy discussion': {'id': 'dummy_discussion_id'}})
self.student = UserFactory.create(username=username, password=password) self.student = UserFactory.create(username=username, password=password)
CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id) CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id)
......
...@@ -63,8 +63,10 @@ class AccessUtilsTestCase(ModuleStoreTestCase): ...@@ -63,8 +63,10 @@ class AccessUtilsTestCase(ModuleStoreTestCase):
Base testcase class for access and roles for the Base testcase class for access and roles for the
comment client service integration comment client service integration
""" """
CREATE_USER = False
def setUp(self): def setUp(self):
super(AccessUtilsTestCase, self).setUp(create_user=False) super(AccessUtilsTestCase, self).setUp()
self.course = CourseFactory.create() self.course = CourseFactory.create()
self.course_id = self.course.id self.course_id = self.course.id
...@@ -118,7 +120,7 @@ class CoursewareContextTestCase(ModuleStoreTestCase): ...@@ -118,7 +120,7 @@ class CoursewareContextTestCase(ModuleStoreTestCase):
comment client service integration comment client service integration
""" """
def setUp(self): 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.course = CourseFactory.create(org="TestX", number="101", display_name="Test Course")
self.discussion1 = ItemFactory.create( self.discussion1 = ItemFactory.create(
...@@ -206,7 +208,7 @@ class CachedDiscussionIdMapTestCase(ModuleStoreTestCase): ...@@ -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. Tests that using the cache of discussion id mappings has the same behavior as searching through the course.
""" """
def setUp(self): 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.course = CourseFactory.create(org='TestX', number='101', display_name='Test Course')
self.discussion = ItemFactory.create( self.discussion = ItemFactory.create(
...@@ -340,7 +342,7 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase): ...@@ -340,7 +342,7 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase):
comment client service integration comment client service integration
""" """
def setUp(self): def setUp(self):
super(CategoryMapTestCase, self).setUp(create_user=True) super(CategoryMapTestCase, self).setUp()
self.course = CourseFactory.create( self.course = CourseFactory.create(
org="TestX", number="101", display_name="Test Course", org="TestX", number="101", display_name="Test Course",
......
...@@ -1729,8 +1729,10 @@ class ThirdPartyRegistrationTestMixin(ThirdPartyOAuthTestMixin): ...@@ -1729,8 +1729,10 @@ class ThirdPartyRegistrationTestMixin(ThirdPartyOAuthTestMixin):
""" """
Tests for the User API registration endpoint with 3rd party authentication. Tests for the User API registration endpoint with 3rd party authentication.
""" """
CREATE_USER = False
def setUp(self): def setUp(self):
super(ThirdPartyRegistrationTestMixin, self).setUp(create_user=False) super(ThirdPartyRegistrationTestMixin, self).setUp()
self.url = reverse('user_api_registration') self.url = reverse('user_api_registration')
def data(self, user=None): def data(self, user=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment