Commit 57f7271b by Calen Pennington

Use the Django TestClient for courseware unit tests, so that middleware is cleaned up properly

parent 437b249d
...@@ -30,7 +30,6 @@ from courseware.tests.factories import ( ...@@ -30,7 +30,6 @@ from courseware.tests.factories import (
) )
import courseware.views.views as views import courseware.views.views as views
from courseware.tests.helpers import LoginEnrollmentTestCase from courseware.tests.helpers import LoginEnrollmentTestCase
from edxmako.tests import mako_middleware_process_request
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from student.models import CourseEnrollment from student.models import CourseEnrollment
from student.roles import CourseCcxCoachRole from student.roles import CourseCcxCoachRole
...@@ -137,21 +136,13 @@ class CoachAccessTestCaseCCX(SharedModuleStoreTestCase, LoginEnrollmentTestCase) ...@@ -137,21 +136,13 @@ class CoachAccessTestCaseCCX(SharedModuleStoreTestCase, LoginEnrollmentTestCase)
CourseEnrollment.enroll(student, ccx_locator) CourseEnrollment.enroll(student, ccx_locator)
# Test for access of a coach # Test for access of a coach
request = self.request_factory.get(reverse('about_course', args=[unicode(ccx_locator)])) resp = self.client.get(reverse('student_progress', args=[unicode(ccx_locator), student.id]))
request.user = self.coach
mako_middleware_process_request(request)
resp = views.progress(request, course_id=unicode(ccx_locator), student_id=student.id)
self.assertEqual(resp.status_code, 200) self.assertEqual(resp.status_code, 200)
# Assert access of a student # Assert access of a student
request = self.request_factory.get(reverse('about_course', args=[unicode(ccx_locator)])) self.client.login(username=student.username, password='test')
request.user = student resp = self.client.get(reverse('student_progress', args=[unicode(ccx_locator), self.coach.id]))
mako_middleware_process_request(request) self.assertEqual(resp.status_code, 404)
with self.assertRaises(Http404) as context:
views.progress(request, course_id=unicode(ccx_locator), student_id=self.coach.id)
self.assertIsNotNone(context.exception)
@attr('shard_1') @attr('shard_1')
......
...@@ -658,7 +658,6 @@ def course_about(request, course_id): ...@@ -658,7 +658,6 @@ def course_about(request, course_id):
@ensure_valid_course_key @ensure_valid_course_key
def progress(request, course_id, student_id=None): def progress(request, course_id, student_id=None):
""" Display the progress page. """ """ Display the progress page. """
course_key = CourseKey.from_string(course_id) course_key = CourseKey.from_string(course_id)
with modulestore().bulk_operations(course_key): with modulestore().bulk_operations(course_key):
...@@ -673,6 +672,14 @@ def _progress(request, course_key, student_id): ...@@ -673,6 +672,14 @@ def _progress(request, course_key, student_id):
Course staff are allowed to see the progress of students in their class. Course staff are allowed to see the progress of students in their class.
""" """
if student_id is not None:
try:
student_id = int(student_id)
# Check for ValueError if 'student_id' cannot be converted to integer.
except ValueError:
raise Http404
course = get_course_with_access(request.user, 'load', course_key, depth=None, check_if_enrolled=True) course = get_course_with_access(request.user, 'load', course_key, depth=None, check_if_enrolled=True)
# check to see if there is a required survey that must be taken before # check to see if there is a required survey that must be taken before
...@@ -697,8 +704,7 @@ def _progress(request, course_key, student_id): ...@@ -697,8 +704,7 @@ def _progress(request, course_key, student_id):
raise Http404 raise Http404
try: try:
student = User.objects.get(id=student_id) student = User.objects.get(id=student_id)
# Check for ValueError if 'student_id' cannot be converted to integer. except User.DoesNotExist:
except (ValueError, User.DoesNotExist):
raise Http404 raise Http404
# NOTE: To make sure impersonation by instructor works, use # NOTE: To make sure impersonation by instructor works, use
......
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