Skip to content

Commit

Permalink
Merge pull request #11467 from edx/perf/speed-up-student-tests
Browse files Browse the repository at this point in the history
Switch to SharedModuleStoreTestCase in the 'student' app where possible.
  • Loading branch information
tobz committed Feb 17, 2016
2 parents e4b59c3 + 0d040bc commit 80c68e4
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 27 deletions.
10 changes: 7 additions & 3 deletions common/djangoapps/student/tests/test_admin_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
"""
from django.core.urlresolvers import reverse

from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import UserFactory


class AdminCourseRolesPageTest(ModuleStoreTestCase):
class AdminCourseRolesPageTest(SharedModuleStoreTestCase):
"""Test the django admin course roles form saving data in db.
"""
@classmethod
def setUpClass(cls):
super(AdminCourseRolesPageTest, cls).setUpClass()
cls.course = CourseFactory.create(org='edx')

def setUp(self):
super(AdminCourseRolesPageTest, self).setUp()
self.user = UserFactory.create(is_staff=True, is_superuser=True)
self.user.save()
self.course = CourseFactory.create(org='edx')

def test_save_valid_data(self):

Expand Down
12 changes: 7 additions & 5 deletions common/djangoapps/student/tests/test_bulk_email_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from opaque_keys.edx.locations import SlashSeparatedCourseKey

from student.tests.factories import UserFactory, CourseEnrollmentFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_TOY_MODULESTORE
from xmodule.modulestore.tests.factories import CourseFactory

Expand All @@ -22,16 +22,18 @@


@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestStudentDashboardEmailView(ModuleStoreTestCase):
class TestStudentDashboardEmailView(SharedModuleStoreTestCase):
"""
Check for email view displayed with flag
"""
@classmethod
def setUpClass(cls):
super(TestStudentDashboardEmailView, cls).setUpClass()
cls.course = CourseFactory.create()

def setUp(self):
super(TestStudentDashboardEmailView, self).setUp()

self.course = CourseFactory.create()

# Create student account
student = UserFactory.create()
CourseEnrollmentFactory.create(user=student, course_id=self.course.id)
Expand Down Expand Up @@ -84,7 +86,7 @@ def test_email_authorized(self):


@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestStudentDashboardEmailViewXMLBacked(ModuleStoreTestCase):
class TestStudentDashboardEmailViewXMLBacked(SharedModuleStoreTestCase):
"""
Check for email view on student dashboard, with XML backed course.
"""
Expand Down
18 changes: 12 additions & 6 deletions common/djangoapps/student/tests/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from django.core.urlresolvers import reverse
from mock import patch
from django.test.utils import override_settings
from xmodule.modulestore import ModuleStoreEnum

from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import UserFactory, CourseEnrollmentFactory
from certificates.tests.factories import GeneratedCertificateFactory # pylint: disable=import-error
Expand All @@ -30,23 +31,28 @@ def _fake_is_request_in_microsite():

@ddt.ddt
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class CertificateDisplayTest(ModuleStoreTestCase):
class CertificateDisplayTest(SharedModuleStoreTestCase):
"""Tests display of certificates on the student dashboard. """

USERNAME = "test_user"
PASSWORD = "password"
DOWNLOAD_URL = "http://www.example.com/certificate.pdf"

@classmethod
def setUpClass(cls):
super(CertificateDisplayTest, cls).setUpClass()
cls.course = CourseFactory()
cls.course.certificates_display_behavior = "early_with_info"

with cls.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, cls.course.id):
cls.store.update_item(cls.course, cls.USERNAME)

def setUp(self):
super(CertificateDisplayTest, self).setUp()
self.user = UserFactory.create(username=self.USERNAME, password=self.PASSWORD)
result = self.client.login(username=self.USERNAME, password=self.PASSWORD)
self.assertTrue(result, msg="Could not log in")

self.course = CourseFactory()
self.course.certificates_display_behavior = "early_with_info"
self.update_course(self.course, self.user.username)

@ddt.data('verified', 'professional')
@patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': False})
def test_display_verified_certificate(self, enrollment_mode):
Expand Down
10 changes: 7 additions & 3 deletions common/djangoapps/student/tests/test_enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.conf import settings
from django.core.urlresolvers import reverse
from course_modes.models import CourseMode
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from util.testing import UrlResetMixin
from embargo.test_utils import restrict_course
Expand All @@ -18,7 +18,7 @@

@ddt.ddt
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class EnrollmentTest(UrlResetMixin, ModuleStoreTestCase):
class EnrollmentTest(UrlResetMixin, SharedModuleStoreTestCase):
"""
Test student enrollment, especially with different course modes.
"""
Expand All @@ -27,11 +27,15 @@ class EnrollmentTest(UrlResetMixin, ModuleStoreTestCase):
EMAIL = "[email protected]"
PASSWORD = "edx"

@classmethod
def setUpClass(cls):
super(EnrollmentTest, cls).setUpClass()
cls.course = CourseFactory.create()

@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
""" Create a course and user, then log in. """
super(EnrollmentTest, self).setUp('embargo')
self.course = CourseFactory.create()
self.user = UserFactory.create(username=self.USERNAME, email=self.EMAIL, password=self.PASSWORD)
self.client.login(username=self.USERNAME, password=self.PASSWORD)

Expand Down
21 changes: 15 additions & 6 deletions common/djangoapps/student/tests/test_login_registration_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from util.testing import UrlResetMixin
from xmodule.modulestore.tests.factories import CourseFactory
from third_party_auth.tests.testutil import ThirdPartyAuthTestMixin
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase

from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase

# This relies on third party auth being enabled in the test
# settings with the feature flag `ENABLE_THIRD_PARTY_AUTH`
Expand All @@ -38,14 +37,19 @@ def _finish_auth_url(params):

@ddt.ddt
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class LoginFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, ModuleStoreTestCase):
class LoginFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, SharedModuleStoreTestCase):
"""Test rendering of the login form. """

@classmethod
def setUpClass(cls):
super(LoginFormTest, cls).setUpClass()
cls.course = CourseFactory.create()

@patch.dict(settings.FEATURES, {"ENABLE_COMBINED_LOGIN_REGISTRATION": False})
def setUp(self):
super(LoginFormTest, self).setUp('lms.urls')

self.url = reverse("signin_user")
self.course = CourseFactory.create()
self.course_id = unicode(self.course.id)
self.courseware_url = reverse("courseware", args=[self.course_id])
self.configure_google_provider(enabled=True)
Expand Down Expand Up @@ -148,14 +152,19 @@ def test_params(self, opt_in_value):

@ddt.ddt
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class RegisterFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, ModuleStoreTestCase):
class RegisterFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, SharedModuleStoreTestCase):
"""Test rendering of the registration form. """

@classmethod
def setUpClass(cls):
super(RegisterFormTest, cls).setUpClass()
cls.course = CourseFactory.create()

@patch.dict(settings.FEATURES, {"ENABLE_COMBINED_LOGIN_REGISTRATION": False})
def setUp(self):
super(RegisterFormTest, self).setUp('lms.urls')

self.url = reverse("register_user")
self.course = CourseFactory.create()
self.course_id = unicode(self.course.id)
self.configure_google_provider(enabled=True)
self.configure_facebook_provider(enabled=True)
Expand Down
6 changes: 5 additions & 1 deletion common/djangoapps/student/tests/test_refunds.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ class RefundableTest(SharedModuleStoreTestCase):
Tests for dashboard utility functions
"""

@classmethod
def setUpClass(cls):
super(RefundableTest, cls).setUpClass()
cls.course = CourseFactory.create()

def setUp(self):
""" Setup components used by each refund test."""
super(RefundableTest, self).setUp()
self.course = CourseFactory.create()
self.user = UserFactory.create(username="jack", email="[email protected]", password='test')
self.verified_mode = CourseModeFactory.create(
course_id=self.course.id,
Expand Down
10 changes: 7 additions & 3 deletions common/djangoapps/student/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
from student.tests.factories import UserFactory, CourseEnrollmentFactory
from student.models import CourseEnrollment
from student.helpers import DISABLE_UNENROLL_CERT_STATES
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory


@ddt.ddt
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestStudentDashboardUnenrollments(ModuleStoreTestCase):
class TestStudentDashboardUnenrollments(SharedModuleStoreTestCase):
"""
Test to ensure that the student dashboard does not show the unenroll button for users with certificates.
"""
Expand All @@ -27,10 +27,14 @@ class TestStudentDashboardUnenrollments(ModuleStoreTestCase):
PASSWORD = "edx"
UNENROLL_ELEMENT_ID = "#actions-item-unenroll-0"

@classmethod
def setUpClass(cls):
super(TestStudentDashboardUnenrollments, cls).setUpClass()
cls.course = CourseFactory.create()

def setUp(self):
""" Create a course and user, then log in. """
super(TestStudentDashboardUnenrollments, self).setUp()
self.course = CourseFactory.create()
self.user = UserFactory.create(username=self.USERNAME, email=self.EMAIL, password=self.PASSWORD)
CourseEnrollmentFactory(course_id=self.course.id, user=self.user)
self.cert_status = None
Expand Down

0 comments on commit 80c68e4

Please sign in to comment.