Commit a07f53e0 by Calen Pennington

Run middleware on a RequestFactory generated request in tests

parent 09dc884c
...@@ -329,6 +329,8 @@ class ViewsTestCase(ModuleStoreTestCase): ...@@ -329,6 +329,8 @@ class ViewsTestCase(ModuleStoreTestCase):
course = CourseFactory.create(org="new", number="unenrolled", display_name="course") course = CourseFactory.create(org="new", number="unenrolled", display_name="course")
request = self.request_factory.get(reverse('about_course', args=[unicode(course.id)])) request = self.request_factory.get(reverse('about_course', args=[unicode(course.id)]))
request.user = AnonymousUser() request.user = AnonymousUser()
# Set up the edxmako middleware for this request to create the RequestContext
mako_middleware_process_request(request) mako_middleware_process_request(request)
response = views.course_about(request, unicode(course.id)) response = views.course_about(request, unicode(course.id))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
...@@ -367,6 +369,8 @@ class ViewsTestCase(ModuleStoreTestCase): ...@@ -367,6 +369,8 @@ class ViewsTestCase(ModuleStoreTestCase):
request = self.request_factory.get(reverse('about_course', args=[unicode(course.id)])) request = self.request_factory.get(reverse('about_course', args=[unicode(course.id)]))
request.user = AnonymousUser() if is_anonymous else self.user request.user = AnonymousUser() if is_anonymous else self.user
# Set up the edxmako middleware for this request to create the RequestContext
mako_middleware_process_request(request) mako_middleware_process_request(request)
# Construct the link for each of the four possibilities: # Construct the link for each of the four possibilities:
...@@ -771,6 +775,8 @@ class ViewsTestCase(ModuleStoreTestCase): ...@@ -771,6 +775,8 @@ class ViewsTestCase(ModuleStoreTestCase):
# Middleware is not supported by the request factory. Simulate a # Middleware is not supported by the request factory. Simulate a
# logged-in user by setting request.user manually. # logged-in user by setting request.user manually.
request.user = self.user request.user = self.user
# Set up the edxmako middleware for this request to create the RequestContext
mako_middleware_process_request(request) mako_middleware_process_request(request)
self.assertFalse(self.course.bypass_home) self.assertFalse(self.course.bypass_home)
...@@ -933,6 +939,7 @@ class TestProgressDueDate(BaseDueDateTests): ...@@ -933,6 +939,7 @@ class TestProgressDueDate(BaseDueDateTests):
def get_text(self, course): def get_text(self, course):
""" Returns the HTML for the progress page """ """ Returns the HTML for the progress page """
# Set up the edxmako middleware for this request to create the RequestContext
mako_middleware_process_request(self.request) mako_middleware_process_request(self.request)
return views.progress(self.request, course_id=unicode(course.id), student_id=self.user.id).content return views.progress(self.request, course_id=unicode(course.id), student_id=self.user.id).content
...@@ -963,6 +970,9 @@ class StartDateTests(ModuleStoreTestCase): ...@@ -963,6 +970,9 @@ class StartDateTests(ModuleStoreTestCase):
self.request_factory = RequestFactory() self.request_factory = RequestFactory()
self.user = UserFactory.create() self.user = UserFactory.create()
self.request = self.request_factory.get("foo") self.request = self.request_factory.get("foo")
# Set up the edxmako middleware for this request to create the RequestContext
mako_middleware_process_request(self.request)
self.request.user = self.user self.request.user = self.user
def set_up_course(self): def set_up_course(self):
...@@ -1023,6 +1033,7 @@ class ProgressPageTests(ModuleStoreTestCase): ...@@ -1023,6 +1033,7 @@ class ProgressPageTests(ModuleStoreTestCase):
self.request = self.request_factory.get("foo") self.request = self.request_factory.get("foo")
self.request.user = self.user self.request.user = self.user
# Set up the edxmako middleware for this request to create the RequestContext
mako_middleware_process_request(self.request) mako_middleware_process_request(self.request)
self.setup_course() self.setup_course()
...@@ -1522,6 +1533,8 @@ class TestIndexView(ModuleStoreTestCase): ...@@ -1522,6 +1533,8 @@ class TestIndexView(ModuleStoreTestCase):
) )
) )
request.user = user request.user = user
# Set up the edxmako middleware for this request to create the RequestContext
mako_middleware_process_request(request) mako_middleware_process_request(request)
# Trigger the assertions embedded in the ViewCheckerBlocks # Trigger the assertions embedded in the ViewCheckerBlocks
...@@ -1553,6 +1566,8 @@ class TestIndexView(ModuleStoreTestCase): ...@@ -1553,6 +1566,8 @@ class TestIndexView(ModuleStoreTestCase):
) + '?activate_block_id=test_block_id' ) + '?activate_block_id=test_block_id'
) )
request.user = user request.user = user
# Set up the edxmako middleware for this request to create the RequestContext
mako_middleware_process_request(request) mako_middleware_process_request(request)
response = CoursewareIndex.as_view()( response = CoursewareIndex.as_view()(
...@@ -1602,6 +1617,8 @@ class TestIndexViewWithGating(ModuleStoreTestCase, MilestonesTestCaseMixin): ...@@ -1602,6 +1617,8 @@ class TestIndexViewWithGating(ModuleStoreTestCase, MilestonesTestCaseMixin):
) )
) )
request.user = self.user request.user = self.user
# Set up the edxmako middleware for this request to create the RequestContext
mako_middleware_process_request(request) mako_middleware_process_request(request)
with self.assertRaises(Http404): with self.assertRaises(Http404):
......
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