Commit 19ea9ae9 by attiyaishaque

Unit tests added and changes in enroll_staff view.

parent b1926497
...@@ -1449,13 +1449,6 @@ class DefaultStatesContentTest(CourseOutlineTest): ...@@ -1449,13 +1449,6 @@ class DefaultStatesContentTest(CourseOutlineTest):
self.assertEqual(courseware.xblock_component_type(1), 'html') self.assertEqual(courseware.xblock_component_type(1), 'html')
self.assertEqual(courseware.xblock_component_type(2), 'discussion') self.assertEqual(courseware.xblock_component_type(2), 'discussion')
def test_unenroll_course(self):
self.course_outline_page.visit()
self.course_outline_page.view_live()
courseware = CoursewarePage(self.browser, self.course_id)
courseware.wait_for_page()
self.assertEqual(courseware.num_xblock_components, 3)
@attr('shard_3') @attr('shard_3')
class UnitNavigationTest(CourseOutlineTest): class UnitNavigationTest(CourseOutlineTest):
......
...@@ -323,47 +323,54 @@ class ViewsTestCase(ModuleStoreTestCase): ...@@ -323,47 +323,54 @@ class ViewsTestCase(ModuleStoreTestCase):
self.assertNotIn('Problem 1', response.content) self.assertNotIn('Problem 1', response.content)
self.assertNotIn('Problem 2', response.content) self.assertNotIn('Problem 2', response.content)
def test_enroll_staff(self): def _create_url_for_enroll_staff(self):
""" """
Here we check two methods GET and POST and should be a staff user User will have satff access and creates the url for enroll_staff view
""" """
self.user.is_staff = True self.user.is_staff = True
self.user.save() self.user.save() # pylint: disable=no-member
self.client.login(username=self.user.username, password=self.password) self.client.login(username=self.user.username, password=self.password)
# create the course # create the course
course = CourseFactory.create() course = CourseFactory.create()
chapter = ItemFactory.create(parent=course, category='chapter')
section = ItemFactory.create(parent=chapter, category='sequential', display_name="Sequence")
# create the _next parameter # create the _next parameter
courseware_url = reverse( courseware_url = reverse('courseware', kwargs={
'courseware_section', 'course_id': course.id.to_deprecated_string()}) + '?activate_block_id=test_block_id'
kwargs={
'course_id': unicode(course.id),
'chapter': chapter.url_name,
'section': section.url_name,
}
) + '?activate_block_id=test_block_id'
# create the url for enroll_staff view # create the url for enroll_staff view
url = "{enroll_staff_url}?next={courseware_url}".format( enroll_staff_url = "{enroll_staff_url}?next={courseware_url}".format(
enroll_staff_url= reverse('enroll_staff', kwargs={'course_id': unicode(course.id)}), enroll_staff_url=reverse('enroll_staff', kwargs={'course_id': unicode(course.id)}),
courseware_url= courseware_url courseware_url=courseware_url
) )
return enroll_staff_url
def test_redirection_unenrolled_staff(self):
"""
Verify unenrolled staff is not redirected to the 'about' section of the chapter
"""
enroll_staff_url = self._create_url_for_enroll_staff()
# Check the GET method # Check the GET method
response = self.client.get(url) response = self.client.get(enroll_staff_url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
response_content = response.content response_content = response.content
self.assertIn('Enroll' , response_content) self.assertIn('Enroll', response_content)
self.assertIn('Continue', response_content) self.assertIn("Don't enroll", response_content)
# Check the POST Method @ddt.data(
data = {'enroll' : 'Enroll'} {'enroll': "Enroll"},
response_post = self.client.post(url, data=data) {'dont_enroll': "Don't enroll"},
# here we check the status code 302 because of the redirect )
self.assertEqual(response_post.status_code, 302) def test_redirection_unenrolled_staff_post_data(self, data):
"""
Verify unenrolled staff is redirected to the page according to data passed.
"""
enroll_staff_url = self._create_url_for_enroll_staff()
response = self.client.post(enroll_staff_url, data=data)
# Here we check the status code 302 because of the redirect
self.assertEqual(response.status_code, 302)
@unittest.skipUnless(settings.FEATURES.get('ENABLE_SHOPPING_CART'), "Shopping Cart not enabled in settings") @unittest.skipUnless(settings.FEATURES.get('ENABLE_SHOPPING_CART'), "Shopping Cart not enabled in settings")
@patch.dict(settings.FEATURES, {'ENABLE_PAID_COURSE_REGISTRATION': True}) @patch.dict(settings.FEATURES, {'ENABLE_PAID_COURSE_REGISTRATION': True})
......
...@@ -354,12 +354,12 @@ def _index_bulk_op(request, course_key, chapter, section, position): ...@@ -354,12 +354,12 @@ def _index_bulk_op(request, course_key, chapter, section, position):
if not registered: if not registered:
# TODO (vshnayder): do course instructors need to be registered to see course? # TODO (vshnayder): do course instructors need to be registered to see course?
log.debug(u'User %s tried to view course %s but is not enrolled', user, course.location.to_deprecated_string()) log.debug(u'User %s tried to view course %s but is not enrolled', user, course.location.to_deprecated_string())
if not bool(staff_access): if bool(staff_access):
usage_key = UsageKey.from_string(course.location.to_deprecated_string()).replace(course_key=course_key)
redirect_url = get_redirect_url(course_key, usage_key)
return redirect("{url}?{redirect}".format( return redirect("{url}?{redirect}".format(
url=reverse(enroll_staff, args=[course_key.to_deprecated_string()]), url=reverse(enroll_staff, args=[course_key.to_deprecated_string()]),
redirect=request.GET.urlencode() redirect=redirect_url))
)
)
return redirect(reverse('about_course', args=[course_key.to_deprecated_string()])) return redirect(reverse('about_course', args=[course_key.to_deprecated_string()]))
# see if all pre-requisites (as per the milestones app feature) have been fulfilled # see if all pre-requisites (as per the milestones app feature) have been fulfilled
...@@ -878,7 +878,8 @@ def enroll_staff(request, course_id): ...@@ -878,7 +878,8 @@ def enroll_staff(request, course_id):
'csrftoken': csrf(request)["csrf_token"] 'csrftoken': csrf(request)["csrf_token"]
}) })
elif request.method == 'POST' and 'enroll' in request.POST: elif request.method == 'POST':
if 'enroll' in request.POST:
enrollment = CourseEnrollment.get_or_create_enrollment(user, course_key) enrollment = CourseEnrollment.get_or_create_enrollment(user, course_key)
enrollment.update_enrollment(is_active=True) enrollment.update_enrollment(is_active=True)
log.info( log.info(
...@@ -886,8 +887,9 @@ def enroll_staff(request, course_id): ...@@ -886,8 +887,9 @@ def enroll_staff(request, course_id):
user.username, user.username,
course_id course_id
) )
return redirect(_next) return redirect(_next)
else:
return redirect(reverse('about_course', args=[course_key.to_deprecated_string()]))
@ensure_csrf_cookie @ensure_csrf_cookie
......
...@@ -3289,6 +3289,7 @@ def validate_request_data_and_get_certificate(certificate_invalidation, course_k ...@@ -3289,6 +3289,7 @@ def validate_request_data_and_get_certificate(certificate_invalidation, course_k
) )
student = get_student(user, course_key) student = get_student(user, course_key)
certificate = GeneratedCertificate.certificate_for_student(student, course_key) certificate = GeneratedCertificate.certificate_for_student(student, course_key)
if not certificate: if not certificate:
raise ValueError(_( raise ValueError(_(
......
...@@ -446,7 +446,6 @@ def submit_export_ora2_data(request, course_key): ...@@ -446,7 +446,6 @@ def submit_export_ora2_data(request, course_key):
def generate_certificates_for_students(request, course_key, student_set=None, specific_student_id=None): # pylint: disable=invalid-name def generate_certificates_for_students(request, course_key, student_set=None, specific_student_id=None): # pylint: disable=invalid-name
""" """
<<<<<<< HEAD
Submits a task to generate certificates for given students enrolled in the course. Submits a task to generate certificates for given students enrolled in the course.
Arguments: Arguments:
......
<%inherit file="main.html" /> <%inherit file="main.html" />
<%namespace name='static' file='static_content.html'/> <%namespace name='static' file='static_content.html'/>
<%! <%!
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from courseware.courses import get_course_info_section, get_course_date_summary from courseware.courses import get_course_about_section
%> %>
<%block name="pagetitle">${_("{course_number} Course Info").format(course_number=course.display_number_with_default)}</%block>
<%block name="headextra"> <%block name="headextra">
<%static:css group='style-course-vendor'/> <meta property="og:title" content="${course.display_name_with_default_escaped}"/>
<%static:css group='style-course'/> <meta property="og:description" content="${get_course_about_section(request, course, 'short_description')}"/>
</%block> </%block>
<%block name="bodyclass">view-in-course view-course-info ${course.css_class or ''}</%block> <%block name="pagetitle">${course.display_name_with_default_escaped}</%block>
<div class="login-register">
<section class="form-type"> <section class="course-info">
<section role="main" class="content"> <header class="course-profile">
<div id="unenroll_error" class="modal-form-error"></div> <div class="intro-inner-wrapper">
<div id="${course.id.to_deprecated_string()}" > <div class="table">
<h3> ${_("You should Register before trying to access and Unit")}</h3> <section class="intro">
<div class="heading-group">
<h3> ${_("You should Register before trying to access the Unit")}</h3>
</div>
<div class="heading-group">
<h1>
${course.display_name_with_default_escaped}
<a href="#">${course.display_org_with_default | h}</a>
</h1>
</div>
<form role="form" id="enroll_staff_form" method="post" action=""> <form role="form" id="enroll_staff_form" method="post" action="">
<input type="hidden" name="csrfmiddlewaretoken" value="${ csrftoken }"/> <input type="hidden" name="csrfmiddlewaretoken" value="${ csrftoken }"/>
<div class="submit "> <div class="main-cta">
<input name="enroll" type="submit" value="${_(" Enroll")}" /> <input class="register" name="enroll" type="submit" value="${_(" Enroll")}"/>
<input name="continue" type="submit" value="${_(" Continue")}" /> <input class="register" name="dont_enroll" type="submit" value="${_(" Don't enroll")}"/>
</div> </div>
</form> </form>
</div>
</section> </section>
</section> </div>
</div>
</div> </header>
</section>
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