diff --git a/lms/djangoapps/courseware/tests/test_course_info.py b/lms/djangoapps/courseware/tests/test_course_info.py index f19ab2dabf..dc9ba0ff37 100644 --- a/lms/djangoapps/courseware/tests/test_course_info.py +++ b/lms/djangoapps/courseware/tests/test_course_info.py @@ -9,6 +9,7 @@ from opaque_keys.edx.locations import SlashSeparatedCourseKey from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_CLOSED_MODULESTORE from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from student.models import CourseEnrollment from .helpers import LoginEnrollmentTestCase @@ -45,6 +46,20 @@ class CourseInfoTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase): self.assertEqual(resp.status_code, 200) self.assertNotIn("OOGIE BLOOGIE", resp.content) + def test_logged_in_not_enrolled(self): + self.setup_user() + url = reverse('info', args=[self.course.id.to_deprecated_string()]) + self.client.get(url) + + # Check whether the user has been enrolled in the course. + # There was a bug in which users would be automatically enrolled + # with is_active=False (same as if they enrolled and immediately unenrolled). + # This verifies that the user doesn't have *any* enrollment record. + enrollment_exists = CourseEnrollment.objects.filter( + user=self.user, course_id=self.course.id + ).exists() + self.assertFalse(enrollment_exists) + class CourseInfoTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): """ diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index a51a1215f9..ad5064eefb 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -665,7 +665,6 @@ def course_info(request, course_id): Assumes the course_id is in a valid format. """ - course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id) with modulestore().bulk_operations(course_key): @@ -1078,11 +1077,12 @@ def fetch_reverify_banner_info(request, course_key): user = request.user if not user.id: return reverifications - enrollment = CourseEnrollment.get_or_create_enrollment(request.user, course_key) - course = modulestore().get_course(course_key) - info = single_course_reverification_info(user, course, enrollment) - if info: - reverifications[info.status].append(info) + enrollment = CourseEnrollment.get_enrollment(request.user, course_key) + if enrollment is not None: + course = modulestore().get_course(course_key) + info = single_course_reverification_info(user, course, enrollment) + if info: + reverifications[info.status].append(info) return reverifications