Commit ad43c25c by Adam

Merge pull request #4188 from edx/adam/fix-skiptests

Explicitly skip tests in common unless we know we're running the LMS unittest suite
parents c4a5299e b584c1a8
...@@ -7,8 +7,8 @@ Course Auth is turned on. ...@@ -7,8 +7,8 @@ Course Auth is turned on.
from django.test.utils import override_settings from django.test.utils import override_settings
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse, NoReverseMatch from django.core.urlresolvers import reverse
from unittest.case import SkipTest import unittest
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from student.tests.factories import UserFactory, CourseEnrollmentFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory
...@@ -23,6 +23,7 @@ from mock import patch ...@@ -23,6 +23,7 @@ from mock import patch
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestStudentDashboardEmailView(ModuleStoreTestCase): class TestStudentDashboardEmailView(ModuleStoreTestCase):
""" """
Check for email view displayed with flag Check for email view displayed with flag
...@@ -35,11 +36,7 @@ class TestStudentDashboardEmailView(ModuleStoreTestCase): ...@@ -35,11 +36,7 @@ class TestStudentDashboardEmailView(ModuleStoreTestCase):
CourseEnrollmentFactory.create(user=student, course_id=self.course.id) CourseEnrollmentFactory.create(user=student, course_id=self.course.id)
self.client.login(username=student.username, password="test") self.client.login(username=student.username, password="test")
try: self.url = reverse('dashboard')
# URL for dashboard
self.url = reverse('dashboard')
except NoReverseMatch:
raise SkipTest("Skip this test if url cannot be found (ie running from CMS tests)")
# URL for email settings modal # URL for email settings modal
self.email_modal_link = ( self.email_modal_link = (
('<a href="#email-settings-modal" class="email-settings" rel="leanModal" ' ('<a href="#email-settings-modal" class="email-settings" rel="leanModal" '
...@@ -92,6 +89,7 @@ class TestStudentDashboardEmailView(ModuleStoreTestCase): ...@@ -92,6 +89,7 @@ class TestStudentDashboardEmailView(ModuleStoreTestCase):
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestStudentDashboardEmailViewXMLBacked(ModuleStoreTestCase): class TestStudentDashboardEmailViewXMLBacked(ModuleStoreTestCase):
""" """
Check for email view on student dashboard, with XML backed course. Check for email view on student dashboard, with XML backed course.
...@@ -107,11 +105,7 @@ class TestStudentDashboardEmailViewXMLBacked(ModuleStoreTestCase): ...@@ -107,11 +105,7 @@ class TestStudentDashboardEmailViewXMLBacked(ModuleStoreTestCase):
) )
self.client.login(username=student.username, password="test") self.client.login(username=student.username, password="test")
try: self.url = reverse('dashboard')
# URL for dashboard
self.url = reverse('dashboard')
except NoReverseMatch:
raise SkipTest("Skip this test if url cannot be found (ie running from CMS tests)")
# URL for email settings modal # URL for email settings modal
self.email_modal_link = ( self.email_modal_link = (
......
...@@ -3,15 +3,17 @@ Unit tests for change_name view of student. ...@@ -3,15 +3,17 @@ Unit tests for change_name view of student.
""" """
import json import json
from django.core.urlresolvers import reverse, NoReverseMatch from django.conf import settings
from django.core.urlresolvers import reverse
from django.test.client import Client from django.test.client import Client
from django.test import TestCase from django.test import TestCase
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from student.models import UserProfile from student.models import UserProfile
from unittest.case import SkipTest import unittest
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestChangeName(TestCase): class TestChangeName(TestCase):
""" """
Check the change_name view of student. Check the change_name view of student.
...@@ -22,14 +24,14 @@ class TestChangeName(TestCase): ...@@ -22,14 +24,14 @@ class TestChangeName(TestCase):
def test_change_name_get_request(self): def test_change_name_get_request(self):
"""Get requests are not allowed in this view.""" """Get requests are not allowed in this view."""
change_name_url = self.get_url() change_name_url = reverse('change_name')
resp = self.client.get(change_name_url) resp = self.client.get(change_name_url)
self.assertEquals(resp.status_code, 405) self.assertEquals(resp.status_code, 405)
def test_change_name_post_request(self): def test_change_name_post_request(self):
"""Name will be changed when provided with proper data.""" """Name will be changed when provided with proper data."""
self.client.login(username=self.student.username, password='test') self.client.login(username=self.student.username, password='test')
change_name_url = self.get_url() change_name_url = reverse('change_name')
resp = self.client.post(change_name_url, { resp = self.client.post(change_name_url, {
'new_name': 'waqas', 'new_name': 'waqas',
'rationale': 'change identity' 'rationale': 'change identity'
...@@ -44,7 +46,7 @@ class TestChangeName(TestCase): ...@@ -44,7 +46,7 @@ class TestChangeName(TestCase):
def test_change_name_without_name(self): def test_change_name_without_name(self):
"""Empty string for name is not allowed in this view.""" """Empty string for name is not allowed in this view."""
self.client.login(username=self.student.username, password='test') self.client.login(username=self.student.username, password='test')
change_name_url = self.get_url() change_name_url = reverse('change_name')
resp = self.client.post(change_name_url, { resp = self.client.post(change_name_url, {
'new_name': '', 'new_name': '',
'rationale': 'change identity' 'rationale': 'change identity'
...@@ -54,17 +56,9 @@ class TestChangeName(TestCase): ...@@ -54,17 +56,9 @@ class TestChangeName(TestCase):
def test_unauthenticated(self): def test_unauthenticated(self):
"""Unauthenticated user is not allowed to call this view.""" """Unauthenticated user is not allowed to call this view."""
change_name_url = self.get_url() change_name_url = reverse('change_name')
resp = self.client.post(change_name_url, { resp = self.client.post(change_name_url, {
'new_name': 'waqas', 'new_name': 'waqas',
'rationale': 'change identity' 'rationale': 'change identity'
}) })
self.assertEquals(resp.status_code, 404) self.assertEquals(resp.status_code, 404)
def get_url(self):
"""Get the url of change_name view."""
try:
change_name_url = reverse('change_name')
return change_name_url
except NoReverseMatch:
raise SkipTest("Skip this test if url cannot be found (ie running from CMS tests)")
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
These are tests for disabling and enabling student accounts, and for making sure These are tests for disabling and enabling student accounts, and for making sure
that students with disabled accounts are unable to access the courseware. that students with disabled accounts are unable to access the courseware.
""" """
import unittest
from student.tests.factories import UserFactory, UserStandingFactory from student.tests.factories import UserFactory, UserStandingFactory
from student.models import UserStanding from student.models import UserStanding
from django.conf import settings
from django.test import TestCase, Client from django.test import TestCase, Client
from django.core.urlresolvers import reverse, NoReverseMatch from django.core.urlresolvers import reverse
from nose.plugins.skip import SkipTest
class UserStandingTest(TestCase): class UserStandingTest(TestCase):
...@@ -48,27 +50,21 @@ class UserStandingTest(TestCase): ...@@ -48,27 +50,21 @@ class UserStandingTest(TestCase):
changed_by=self.admin changed_by=self.admin
) )
# set different stock urls for lms and cms # set stock url to test disabled accounts' access to site
# to test disabled accounts' access to site self.some_url = '/'
try:
self.some_url = reverse('dashboard')
except NoReverseMatch:
self.some_url = '/course/'
# since it's only possible to disable accounts from lms, we're going # since it's only possible to disable accounts from lms, we're going
# to skip tests for cms # to skip tests for cms
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_disable_account(self): def test_disable_account(self):
self.assertEqual( self.assertEqual(
UserStanding.objects.filter(user=self.good_user).count(), 0 UserStanding.objects.filter(user=self.good_user).count(), 0
) )
try: response = self.admin_client.post(reverse('disable_account_ajax'), {
response = self.admin_client.post(reverse('disable_account_ajax'), { 'username': self.good_user.username,
'username': self.good_user.username, 'account_action': 'disable',
'account_action': 'disable', })
})
except NoReverseMatch:
raise SkipTest()
self.assertEqual( self.assertEqual(
UserStanding.objects.get(user=self.good_user).account_status, UserStanding.objects.get(user=self.good_user).account_status,
UserStanding.ACCOUNT_DISABLED UserStanding.ACCOUNT_DISABLED
...@@ -78,37 +74,31 @@ class UserStandingTest(TestCase): ...@@ -78,37 +74,31 @@ class UserStandingTest(TestCase):
response = self.bad_user_client.get(self.some_url) response = self.bad_user_client.get(self.some_url)
self.assertEqual(response.status_code, 403) self.assertEqual(response.status_code, 403)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_reenable_account(self): def test_reenable_account(self):
try: response = self.admin_client.post(reverse('disable_account_ajax'), {
response = self.admin_client.post(reverse('disable_account_ajax'), { 'username': self.bad_user.username,
'username': self.bad_user.username, 'account_action': 'reenable'
'account_action': 'reenable' })
})
except NoReverseMatch:
raise SkipTest()
self.assertEqual( self.assertEqual(
UserStanding.objects.get(user=self.bad_user).account_status, UserStanding.objects.get(user=self.bad_user).account_status,
UserStanding.ACCOUNT_ENABLED UserStanding.ACCOUNT_ENABLED
) )
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_non_staff_cant_access_disable_view(self): def test_non_staff_cant_access_disable_view(self):
try: response = self.non_staff_client.get(reverse('manage_user_standing'), {
response = self.non_staff_client.get(reverse('manage_user_standing'), { 'user': self.non_staff,
'user': self.non_staff, })
})
except NoReverseMatch:
raise SkipTest()
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_non_staff_cant_disable_account(self): def test_non_staff_cant_disable_account(self):
try: response = self.non_staff_client.post(reverse('disable_account_ajax'), {
response = self.non_staff_client.post(reverse('disable_account_ajax'), { 'username': self.good_user.username,
'username': self.good_user.username, 'user': self.non_staff,
'user': self.non_staff, 'account_action': 'disable'
'account_action': 'disable' })
})
except NoReverseMatch:
raise SkipTest()
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
self.assertEqual( self.assertEqual(
UserStanding.objects.filter(user=self.good_user).count(), 0 UserStanding.objects.filter(user=self.good_user).count(), 0
......
...@@ -153,15 +153,13 @@ class DashboardTest(TestCase): ...@@ -153,15 +153,13 @@ class DashboardTest(TestCase):
) )
self.client = Client() self.client = Client()
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def check_verification_status_on(self, mode, value): def check_verification_status_on(self, mode, value):
""" """
Check that the css class and the status message are in the dashboard html. Check that the css class and the status message are in the dashboard html.
""" """
CourseEnrollment.enroll(self.user, self.course.location.course_key, mode=mode) CourseEnrollment.enroll(self.user, self.course.location.course_key, mode=mode)
try: response = self.client.get(reverse('dashboard'))
response = self.client.get(reverse('dashboard'))
except NoReverseMatch:
raise SkipTest("Skip this test if url cannot be found (ie running from CMS tests)")
self.assertContains(response, "class=\"course {0}\"".format(mode)) self.assertContains(response, "class=\"course {0}\"".format(mode))
self.assertContains(response, value) self.assertContains(response, value)
...@@ -175,15 +173,13 @@ class DashboardTest(TestCase): ...@@ -175,15 +173,13 @@ class DashboardTest(TestCase):
self.check_verification_status_on('honor', 'You\'re enrolled as an honor code student') self.check_verification_status_on('honor', 'You\'re enrolled as an honor code student')
self.check_verification_status_on('audit', 'You\'re auditing this course') self.check_verification_status_on('audit', 'You\'re auditing this course')
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def check_verification_status_off(self, mode, value): def check_verification_status_off(self, mode, value):
""" """
Check that the css class and the status message are not in the dashboard html. Check that the css class and the status message are not in the dashboard html.
""" """
CourseEnrollment.enroll(self.user, self.course.location.course_key, mode=mode) CourseEnrollment.enroll(self.user, self.course.location.course_key, mode=mode)
try: response = self.client.get(reverse('dashboard'))
response = self.client.get(reverse('dashboard'))
except NoReverseMatch:
raise SkipTest("Skip this test if url cannot be found (ie running from CMS tests)")
self.assertNotContains(response, "class=\"course {0}\"".format(mode)) self.assertNotContains(response, "class=\"course {0}\"".format(mode))
self.assertNotContains(response, value) self.assertNotContains(response, value)
...@@ -232,7 +228,6 @@ class DashboardTest(TestCase): ...@@ -232,7 +228,6 @@ class DashboardTest(TestCase):
self.assertFalse(enrollment.refundable()) self.assertFalse(enrollment.refundable())
class EnrollInCourseTest(TestCase): class EnrollInCourseTest(TestCase):
"""Tests enrolling and unenrolling in courses.""" """Tests enrolling and unenrolling in courses."""
......
"""Tests for student tracking""" """Tests that tracking data are successfully logged"""
import mock import mock
import unittest
from django.test import TestCase from django.test import TestCase
from django.core.urlresolvers import reverse, NoReverseMatch from django.core.urlresolvers import reverse, NoReverseMatch
from django.conf import settings
from track.models import TrackingLog from track.models import TrackingLog
from track.views import user_track from track.views import user_track
from nose.plugins.skip import SkipTest
@unittest.skip("TODO: these tests were not being run before, and now that they are they're failing")
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TrackingTest(TestCase): class TrackingTest(TestCase):
""" """
Tests that tracking logs correctly handle events Tests that tracking logs correctly handle events
...@@ -24,10 +27,7 @@ class TrackingTest(TestCase): ...@@ -24,10 +27,7 @@ class TrackingTest(TestCase):
] ]
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_SQL_TRACKING_LOGS': True}): with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_SQL_TRACKING_LOGS': True}):
for request_params in requests: for request_params in requests:
try: # because /event maps to two different views in lms and cms, we're only going to test lms here response = self.client.post(reverse(user_track), request_params)
response = self.client.post(reverse(user_track), request_params)
except NoReverseMatch:
raise SkipTest()
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'success') self.assertEqual(response.content, 'success')
tracking_logs = TrackingLog.objects.order_by('-dtcreated') tracking_logs = TrackingLog.objects.order_by('-dtcreated')
...@@ -47,10 +47,7 @@ class TrackingTest(TestCase): ...@@ -47,10 +47,7 @@ class TrackingTest(TestCase):
] ]
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_SQL_TRACKING_LOGS': True}): with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_SQL_TRACKING_LOGS': True}):
for request_params in requests: for request_params in requests:
try: # because /event maps to two different views in lms and cms, we're only going to test lms here response = self.client.get(reverse(user_track), request_params)
response = self.client.get(reverse(user_track), request_params)
except NoReverseMatch:
raise SkipTest()
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'success') self.assertEqual(response.content, 'success')
tracking_logs = TrackingLog.objects.order_by('-dtcreated') tracking_logs = TrackingLog.objects.order_by('-dtcreated')
......
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