Commit 19ea9ae9 by attiyaishaque

Unit tests added and changes in enroll_staff view.

parent b1926497
......@@ -1449,13 +1449,6 @@ class DefaultStatesContentTest(CourseOutlineTest):
self.assertEqual(courseware.xblock_component_type(1), 'html')
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')
class UnitNavigationTest(CourseOutlineTest):
......
......@@ -323,47 +323,54 @@ class ViewsTestCase(ModuleStoreTestCase):
self.assertNotIn('Problem 1', 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.save()
self.user.save() # pylint: disable=no-member
self.client.login(username=self.user.username, password=self.password)
# create the course
course = CourseFactory.create()
chapter = ItemFactory.create(parent=course, category='chapter')
section = ItemFactory.create(parent=chapter, category='sequential', display_name="Sequence")
# create the _next parameter
courseware_url = reverse(
'courseware_section',
kwargs={
'course_id': unicode(course.id),
'chapter': chapter.url_name,
'section': section.url_name,
}
) + '?activate_block_id=test_block_id'
courseware_url = reverse('courseware', kwargs={
'course_id': course.id.to_deprecated_string()}) + '?activate_block_id=test_block_id'
# create the url for enroll_staff view
url = "{enroll_staff_url}?next={courseware_url}".format(
enroll_staff_url= reverse('enroll_staff', kwargs={'course_id': unicode(course.id)}),
courseware_url= courseware_url
enroll_staff_url = "{enroll_staff_url}?next={courseware_url}".format(
enroll_staff_url=reverse('enroll_staff', kwargs={'course_id': unicode(course.id)}),
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
response = self.client.get(url)
response = self.client.get(enroll_staff_url)
self.assertEqual(response.status_code, 200)
response_content = response.content
self.assertIn('Enroll' , response_content)
self.assertIn('Continue', response_content)
# Check the POST Method
data = {'enroll' : 'Enroll'}
response_post = self.client.post(url, data=data)
# here we check the status code 302 because of the redirect
self.assertEqual(response_post.status_code, 302)
self.assertIn('Enroll', response_content)
self.assertIn("Don't enroll", response_content)
@ddt.data(
{'enroll': "Enroll"},
{'dont_enroll': "Don't enroll"},
)
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")
@patch.dict(settings.FEATURES, {'ENABLE_PAID_COURSE_REGISTRATION': True})
......
......@@ -354,12 +354,12 @@ def _index_bulk_op(request, course_key, chapter, section, position):
if not registered:
# 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())
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(
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()]))
# see if all pre-requisites (as per the milestones app feature) have been fulfilled
......@@ -878,16 +878,18 @@ def enroll_staff(request, course_id):
'csrftoken': csrf(request)["csrf_token"]
})
elif request.method == 'POST' and 'enroll' in request.POST:
enrollment = CourseEnrollment.get_or_create_enrollment(user, course_key)
enrollment.update_enrollment(is_active=True)
log.info(
u"User %s enrolled in %s via `enroll_staff` view",
user.username,
course_id
)
return redirect(_next)
elif request.method == 'POST':
if 'enroll' in request.POST:
enrollment = CourseEnrollment.get_or_create_enrollment(user, course_key)
enrollment.update_enrollment(is_active=True)
log.info(
u"User %s enrolled in %s via `enroll_staff` view",
user.username,
course_id
)
return redirect(_next)
else:
return redirect(reverse('about_course', args=[course_key.to_deprecated_string()]))
@ensure_csrf_cookie
......
......@@ -3289,6 +3289,7 @@ def validate_request_data_and_get_certificate(certificate_invalidation, course_k
)
student = get_student(user, course_key)
certificate = GeneratedCertificate.certificate_for_student(student, course_key)
if not certificate:
raise ValueError(_(
......
......@@ -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
"""
<<<<<<< HEAD
Submits a task to generate certificates for given students enrolled in the course.
Arguments:
......
<%inherit file="main.html" />
<%namespace name='static' file='static_content.html'/>
<%!
from django.utils.translation import ugettext as _
from courseware.courses import get_course_info_section, get_course_date_summary
from django.utils.translation import ugettext as _
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">
<%static:css group='style-course-vendor'/>
<%static:css group='style-course'/>
<meta property="og:title" content="${course.display_name_with_default_escaped}"/>
<meta property="og:description" content="${get_course_about_section(request, course, 'short_description')}"/>
</%block>
<%block name="bodyclass">view-in-course view-course-info ${course.css_class or ''}</%block>
<div class="login-register">
<section class="form-type">
<section role="main" class="content">
<div id="unenroll_error" class="modal-form-error"></div>
<div id="${course.id.to_deprecated_string()}" >
<h3> ${_("You should Register before trying to access and Unit")}</h3>
<form role="form" id="enroll_staff_form" method="post" action="">
<input type="hidden" name="csrfmiddlewaretoken" value="${ csrftoken }"/>
<div class="submit ">
<input name="enroll" type="submit" value="${_(" Enroll")}" />
<input name="continue" type="submit" value="${_(" Continue")}" />
<%block name="pagetitle">${course.display_name_with_default_escaped}</%block>
<section class="course-info">
<header class="course-profile">
<div class="intro-inner-wrapper">
<div class="table">
<section class="intro">
<div class="heading-group">
<h3> ${_("You should Register before trying to access the Unit")}</h3>
</div>
</form>
<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="">
<input type="hidden" name="csrfmiddlewaretoken" value="${ csrftoken }"/>
<div class="main-cta">
<input class="register" name="enroll" type="submit" value="${_(" Enroll")}"/>
<input class="register" name="dont_enroll" type="submit" value="${_(" Don't enroll")}"/>
</div>
</form>
</section>
</div>
</section>
</section>
</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