Commit b1926497 by attiyaishaque

Adding unit test

parent 94b58c2d
......@@ -323,6 +323,48 @@ class ViewsTestCase(ModuleStoreTestCase):
self.assertNotIn('Problem 1', response.content)
self.assertNotIn('Problem 2', response.content)
def test_enroll_staff(self):
"""
Here we check two methods GET and POST and should be a staff user
"""
self.user.is_staff = True
self.user.save()
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'
# 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
)
# Check the GET method
response = self.client.get(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)
@unittest.skipUnless(settings.FEATURES.get('ENABLE_SHOPPING_CART'), "Shopping Cart not enabled in settings")
@patch.dict(settings.FEATURES, {'ENABLE_PAID_COURSE_REGISTRATION': True})
def test_course_about_in_cart(self):
......
......@@ -840,16 +840,18 @@ def get_cosmetic_display_price(course, registration_price):
@require_global_staff
@require_http_methods(['POST', 'GET'])
@ensure_valid_course_key
def enroll_staff(request, course_id):
'''
"""
1. Should be staff
2. should be a valid course_id
3. shouldn't be enrolled before
4. The requested view url to redirect
URL-ABC-GOTO-HERE-
GET
html: return enroll staff page
POST
1. You want to register for this course?
Confirm:
1. User is valid staff user who wants to enroll.
......@@ -860,7 +862,7 @@ def enroll_staff(request, course_id):
:param request:
:param course_id:
:return:
'''
"""
user = request.user
course_key = CourseKey.from_string(course_id)
_next = urllib.quote_plus(request.GET.get('next', 'info'), safe='/:?=')
......@@ -876,8 +878,8 @@ def enroll_staff(request, course_id):
'csrftoken': csrf(request)["csrf_token"]
})
elif request.method == 'POST' and 'enroll' in request.POST.dict():
enrollment = CourseEnrollment.get_or_create_enrollment(request.user, course_key)
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",
......
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