TE-2525 nose.tools removal part 1/2
This commit is contained in:
committed by
Jeremy Bowman
parent
70d1ca4740
commit
bcaec3c5bb
@@ -4,10 +4,10 @@ Tests for student enrollment.
|
||||
import unittest
|
||||
|
||||
import ddt
|
||||
import pytest
|
||||
from django.conf import settings
|
||||
from django.test.utils import override_settings
|
||||
from mock import Mock, patch
|
||||
from nose.tools import raises
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
from enrollment import api
|
||||
@@ -84,19 +84,19 @@ class EnrollmentTest(CacheIsolationTestCase):
|
||||
['verified'],
|
||||
['verified', 'professional'],
|
||||
)
|
||||
@raises(CourseModeNotFoundError)
|
||||
def test_enroll_no_mode_error(self, course_modes):
|
||||
# Add a fake course enrollment information to the fake data API
|
||||
fake_data_api.add_course(self.COURSE_ID, course_modes=course_modes)
|
||||
# Enroll in the course and verify that we raise CourseModeNotFoundError
|
||||
api.add_enrollment(self.USERNAME, self.COURSE_ID)
|
||||
with pytest.raises(CourseModeNotFoundError):
|
||||
api.add_enrollment(self.USERNAME, self.COURSE_ID)
|
||||
|
||||
@raises(CourseModeNotFoundError)
|
||||
def test_prof_ed_enroll(self):
|
||||
# Add a fake course enrollment information to the fake data API
|
||||
fake_data_api.add_course(self.COURSE_ID, course_modes=['professional'])
|
||||
# Enroll in the course and verify the URL we get sent to
|
||||
api.add_enrollment(self.USERNAME, self.COURSE_ID, mode='verified')
|
||||
with pytest.raises(CourseModeNotFoundError):
|
||||
api.add_enrollment(self.USERNAME, self.COURSE_ID, mode='verified')
|
||||
|
||||
@ddt.data(
|
||||
# Default (no course modes in the database)
|
||||
@@ -131,11 +131,11 @@ class EnrollmentTest(CacheIsolationTestCase):
|
||||
self.assertEquals(result['mode'], mode)
|
||||
self.assertFalse(result['is_active'])
|
||||
|
||||
@raises(EnrollmentNotFoundError)
|
||||
def test_unenroll_not_enrolled_in_course(self):
|
||||
# Add a fake course enrollment information to the fake data API
|
||||
fake_data_api.add_course(self.COURSE_ID, course_modes=['honor'])
|
||||
api.update_enrollment(self.USERNAME, self.COURSE_ID, mode='honor', is_active=False)
|
||||
with pytest.raises(EnrollmentNotFoundError):
|
||||
api.update_enrollment(self.USERNAME, self.COURSE_ID, mode='honor', is_active=False)
|
||||
|
||||
@ddt.data(
|
||||
# Simple test of honor and verified.
|
||||
@@ -209,10 +209,10 @@ class EnrollmentTest(CacheIsolationTestCase):
|
||||
self.assertEquals(3, len(result['course_modes']))
|
||||
|
||||
@override_settings(ENROLLMENT_DATA_API='foo.bar.biz.baz')
|
||||
@raises(EnrollmentApiLoadError)
|
||||
def test_data_api_config_error(self):
|
||||
# Enroll in the course and verify the URL we get sent to
|
||||
api.add_enrollment(self.USERNAME, self.COURSE_ID, mode='audit')
|
||||
with pytest.raises(EnrollmentApiLoadError):
|
||||
api.add_enrollment(self.USERNAME, self.COURSE_ID, mode='audit')
|
||||
|
||||
def test_caching(self):
|
||||
# Add fake course enrollment information to the fake data API
|
||||
|
||||
@@ -6,9 +6,9 @@ import datetime
|
||||
import unittest
|
||||
|
||||
import ddt
|
||||
import pytest
|
||||
from django.conf import settings
|
||||
from mock import patch
|
||||
from nose.tools import raises
|
||||
from pytz import UTC
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
@@ -300,9 +300,9 @@ class EnrollmentDataTest(ModuleStoreTestCase):
|
||||
enrollment_attr = data.get_enrollment_attributes(self.user.username, unicode(self.course.id))
|
||||
self.assertEqual(enrollment_attr[0], enrollment_attributes[0])
|
||||
|
||||
@raises(CourseNotFoundError)
|
||||
def test_non_existent_course(self):
|
||||
data.get_course_enrollment_info("this/is/bananas")
|
||||
with pytest.raises(CourseNotFoundError):
|
||||
data.get_course_enrollment_info("this/is/bananas")
|
||||
|
||||
def _create_course_modes(self, course_modes, course=None):
|
||||
"""Create the course modes required for a test. """
|
||||
@@ -314,35 +314,35 @@ class EnrollmentDataTest(ModuleStoreTestCase):
|
||||
mode_display_name=mode_slug,
|
||||
)
|
||||
|
||||
@raises(UserNotFoundError)
|
||||
def test_enrollment_for_non_existent_user(self):
|
||||
data.create_course_enrollment("some_fake_user", unicode(self.course.id), 'honor', True)
|
||||
with pytest.raises(UserNotFoundError):
|
||||
data.create_course_enrollment("some_fake_user", unicode(self.course.id), 'honor', True)
|
||||
|
||||
@raises(CourseNotFoundError)
|
||||
def test_enrollment_for_non_existent_course(self):
|
||||
data.create_course_enrollment(self.user.username, "some/fake/course", 'honor', True)
|
||||
with pytest.raises(CourseNotFoundError):
|
||||
data.create_course_enrollment(self.user.username, "some/fake/course", 'honor', True)
|
||||
|
||||
@raises(CourseEnrollmentClosedError)
|
||||
@patch.object(CourseEnrollment, "enroll")
|
||||
def test_enrollment_for_closed_course(self, mock_enroll):
|
||||
mock_enroll.side_effect = EnrollmentClosedError("Bad things happened")
|
||||
data.create_course_enrollment(self.user.username, unicode(self.course.id), 'honor', True)
|
||||
with pytest.raises(CourseEnrollmentClosedError):
|
||||
data.create_course_enrollment(self.user.username, unicode(self.course.id), 'honor', True)
|
||||
|
||||
@raises(CourseEnrollmentFullError)
|
||||
@patch.object(CourseEnrollment, "enroll")
|
||||
def test_enrollment_for_full_course(self, mock_enroll):
|
||||
mock_enroll.side_effect = CourseFullError("Bad things happened")
|
||||
data.create_course_enrollment(self.user.username, unicode(self.course.id), 'honor', True)
|
||||
with pytest.raises(CourseEnrollmentFullError):
|
||||
data.create_course_enrollment(self.user.username, unicode(self.course.id), 'honor', True)
|
||||
|
||||
@raises(CourseEnrollmentExistsError)
|
||||
@patch.object(CourseEnrollment, "enroll")
|
||||
def test_enrollment_for_enrolled_course(self, mock_enroll):
|
||||
mock_enroll.side_effect = AlreadyEnrolledError("Bad things happened")
|
||||
data.create_course_enrollment(self.user.username, unicode(self.course.id), 'honor', True)
|
||||
with pytest.raises(CourseEnrollmentExistsError):
|
||||
data.create_course_enrollment(self.user.username, unicode(self.course.id), 'honor', True)
|
||||
|
||||
@raises(UserNotFoundError)
|
||||
def test_update_for_non_existent_user(self):
|
||||
data.update_course_enrollment("some_fake_user", unicode(self.course.id), is_active=False)
|
||||
with pytest.raises(UserNotFoundError):
|
||||
data.update_course_enrollment("some_fake_user", unicode(self.course.id), is_active=False)
|
||||
|
||||
def test_update_for_non_existent_course(self):
|
||||
enrollment = data.update_course_enrollment(self.user.username, "some/fake/course", is_active=False)
|
||||
|
||||
Reference in New Issue
Block a user