Commit 275a31ec by attiyaishaque

Change in Bokchoy test according to new design.

parent 19ea9ae9
......@@ -290,7 +290,7 @@ class CoursewareSequentialTabPage(CoursePage):
class AboutPage(CoursePage):
"""
Course about.
Course about page.
"""
url_path = "about/"
......@@ -301,6 +301,6 @@ class AboutPage(CoursePage):
@property
def is_register_button_present(self):
"""
Returns True if the timed/proctored exam timer bar is visible on the courseware.
Returns True if the Enrollment button is visible on the about page.
"""
return self.q(css=".register").is_present()
......@@ -65,7 +65,7 @@ class DashboardPage(PageObject):
"""
Clicks the "View Live" link and switches to the new tab
"""
self.mouse_hover(self.browser.find_element_by_css_selector('.view-button'))
self.mouse_hover(self.browser.find_element_by_css_selector('.course-item'))
click_css(self, '.view-button', require_notification=False)
self.browser.switch_to_window(self.browser.window_handles[-1])
click_css(self, element, require_notification=False)
......
......@@ -203,12 +203,12 @@ class CourseNotEnrollTest(WebAppTest):
Returns the serialized course_key for the test
"""
# TODO - is there a better way to make this agnostic to the underlying default module store?
default_store = os.environ.get('DEFAULT_STORE', 'draft')
default_store = os.environ.get('DEFAULT_STORE', 'split')
course_key = CourseLocator(
self.course_org,
self.course_number,
self.course_run,
deprecated=(default_store == 'draft')
deprecated=(default_store == 'split')
)
return unicode(course_key)
......@@ -221,8 +221,8 @@ class CourseNotEnrollTest(WebAppTest):
Login with the staff user which is not enrolled in the course
click the view live button of the course
Here are two scenario:
First click the continue button
Second click the Enroll button and see the response.
-First click the Don't Enroll button
-Second click the Enroll button and see the response.
"""
self.auth_page.visit()
self.dashboard_page.visit()
......@@ -241,7 +241,7 @@ class CourseNotEnrollTest(WebAppTest):
AutoAuthPage(self.browser, course_id=None, staff=True).visit()
self.dashboard_page.visit()
self.dashboard_page.view_live('.submit>input:last-child')
self.dashboard_page.view_live('input[name= "dont_enroll"]')
about_page = AboutPage(self.browser, self.course_id)
about_page.wait_for_page()
......@@ -249,7 +249,7 @@ class CourseNotEnrollTest(WebAppTest):
self.assertTrue(about_page.is_register_button_present)
self.dashboard_page.visit()
self.dashboard_page.view_live('.submit>input:first-child')
self.dashboard_page.view_live('input[name= "enroll"]')
course_ware = CoursewarePage(self.browser, self.course_id)
course_ware.wait_for_page()
self.assertTrue(course_ware.is_browser_on_page())
......@@ -336,41 +336,50 @@ class ViewsTestCase(ModuleStoreTestCase):
# create the _next parameter
courseware_url = reverse('courseware', kwargs={
'course_id': course.id.to_deprecated_string()}) + '?activate_block_id=test_block_id'
'course_id': unicode(course.id)}) + '?activate_block_id=test_block_id'
# create the url for enroll_staff view
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
return enroll_staff_url, course.id
def test_redirection_unenrolled_staff(self):
"""
Verify unenrolled staff is not redirected to the 'about' section of the chapter
Test that staff is not redirected to the 'about' page when visiting an unregistered course
"""
enroll_staff_url = self._create_url_for_enroll_staff()
enroll_staff_url, __ = self._create_url_for_enroll_staff()
# Check the GET method
response = self.client.get(enroll_staff_url)
self.assertEqual(response.status_code, 200)
response_content = response.content
self.assertIn('Enroll', response_content)
self.assertIn("Don't enroll", response_content)
self.assertIn("dont_enroll", response_content)
@ddt.data(
{'enroll': "Enroll"},
{'dont_enroll': "Don't enroll"},
)
def test_redirection_unenrolled_staff_post_data(self, data):
({'enroll': "Enroll"}, 'courses/{}/courseware?activate_block_id=test_block_id'),
({'dont_enroll': "Don't enroll"}, '/courses/{}/about'))
@ddt.unpack
def test_enroll_staff_redirection(self, data, expected_url):
"""
Verify unenrolled staff is redirected to the page according to data passed.
"""
enroll_staff_url = self._create_url_for_enroll_staff()
enroll_staff_url, course_id = 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)
self.assertRedirects(response, expected_url.format(unicode(course_id)))
def test_enroll_staff_redirection_invalid_data(self):
"""
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={'test': "test"})
self.assertEqual(response.status_code, 404)
@unittest.skipUnless(settings.FEATURES.get('ENABLE_SHOPPING_CART'), "Shopping Cart not enabled in settings")
@patch.dict(settings.FEATURES, {'ENABLE_PAID_COURSE_REGISTRATION': True})
......
......@@ -50,3 +50,19 @@ def get_redirect_url(course_key, usage_key):
redirect_url += "?{}".format(urlencode({'activate_block_id': unicode(final_target_id)}))
return redirect_url
def get_redirect_url_for_global_staff(course_key, location):
"""
Returns the redirect url
Args:
course_key(str): Course key string
location(str): The location id of course component
"""
_next = get_redirect_url(course_key, location)
redirect_url = "{url}?next={redirect}".format(
url=reverse('enroll_staff', args=[unicode(course_key)]),
redirect=_next)
return redirect_url
......@@ -18,11 +18,13 @@ from django.db import transaction
from django.db.models import Q
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden
from django.shortcuts import redirect
from django.utils.decorators import method_decorator
from django.utils.timezone import UTC
from django.utils.translation import ugettext as _
from django.views.decorators.cache import cache_control
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.decorators.http import require_GET, require_POST, require_http_methods
from django.views.generic import View
from eventtracking import tracker
from ipware.ip import get_ip
from markupsafe import escape
......@@ -59,7 +61,7 @@ from courseware.courses import (
from courseware.masquerade import setup_masquerade
from courseware.model_data import FieldDataCache, ScoresClient
from courseware.models import StudentModule, BaseStudentModuleHistory
from courseware.url_helpers import get_redirect_url
from courseware.url_helpers import get_redirect_url, get_redirect_url_for_global_staff
from courseware.user_state_client import DjangoXBlockUserStateClient
from edxmako.shortcuts import render_to_response, render_to_string, marketing_link
from instructor.enrollment import uses_shib
......@@ -79,6 +81,7 @@ from student.roles import GlobalStaff
from student.views import is_course_blocked
from util.cache import cache, cache_if_anonymous
from util.course_key_utils import from_string_or_404
from util.date_utils import strftime_localized
from util.db import outer_atomic
from util.milestones_helpers import get_prerequisite_courses_display
......@@ -354,13 +357,10 @@ 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 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=redirect_url))
return redirect(reverse('about_course', args=[course_key.to_deprecated_string()]))
if GlobalStaff().has_user(user):
redirect_url = get_redirect_url_for_global_staff(course_key, course.location)
return redirect(redirect_url)
return redirect(reverse('about_course', args=[unicode(course_key)]))
# see if all pre-requisites (as per the milestones app feature) have been fulfilled
# Note that if the pre-requisite feature flag has been turned off (default) then this check will
......@@ -630,10 +630,7 @@ def jump_to(_request, course_id, location):
user = _request.user
redirect_url = get_redirect_url(course_key, usage_key)
if GlobalStaff().has_user(user) and not CourseEnrollment.is_enrolled(user, course_key):
redirect_url = "{url}?next={redirect}".format(
url=reverse(enroll_staff, args=[course_key.to_deprecated_string()]),
redirect=redirect_url
)
redirect_url = get_redirect_url_for_global_staff(course_key, usage_key)
except ItemNotFoundError:
raise Http404(u"No data at this location: {0}".format(usage_key))
except NoPathToItem:
......@@ -839,57 +836,58 @@ def get_cosmetic_display_price(course, registration_price):
return _('Free')
@require_global_staff
@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
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.
2. Course is valid course
2. Yes
3. Post request, enroll the user and redirect him to the requested view
:param request:
:param course_id:
:return:
class EnrollStaffView(View):
"""
user = request.user
course_key = CourseKey.from_string(course_id)
_next = urllib.quote_plus(request.GET.get('next', 'info'), safe='/:?=')
Determine If user is global staff, it will be redirected to page "enroll_satff.html"
that asks you if you want to register for the course.
This pages has the courseware link you were heading to as a ?next parameter
Click "enroll" and be redirected to the page you wanted to go to
Click "Don't enroll" and go back to the course about page
if request.method == 'GET':
with modulestore().bulk_operations(course_key):
course = get_course_with_access(user, 'load', course_key, depth=2)
Arguments:
- request : HTTP request
- course_id : course id
# Prompt for enrollment if Globalstaff is not enrolled in the course
if not registered_for_course(course, user):
return render_to_response('enroll_staff.html', {
'course': course,
'csrftoken': csrf(request)["csrf_token"]
})
Returns:
-RedirectResponse
"""
template_name = 'enroll_staff.html'
elif request.method == 'POST':
@method_decorator(require_global_staff)
@method_decorator(ensure_valid_course_key)
def get(self, request, course_id):
"""
Renders Enroll Staff View
"""
user = request.user
course_key = from_string_or_404(course_id)
with modulestore().bulk_operations(course_key):
course = get_course_with_access(user, 'load', course_key)
if not registered_for_course(course, user):
context = {'course': course,
'csrftoken': csrf(request)["csrf_token"]}
return render_to_response(self.template_name, context)
@method_decorator(require_global_staff)
@method_decorator(ensure_valid_course_key)
def post(self, request, course_id):
"""
Enroll and returns the response
"""
_next = urllib.quote_plus(request.GET.get('next', 'info'), safe='/:?=')
course_key = from_string_or_404(course_id)
if 'enroll' in request.POST:
enrollment = CourseEnrollment.get_or_create_enrollment(user, course_key)
enrollment.update_enrollment(is_active=True)
CourseEnrollment.enroll(request.user, course_key)
log.info(
u"User %s enrolled in %s via `enroll_staff` view",
user.username,
request.user.username,
course_id
)
return redirect(_next)
elif 'dont_enroll' in request.POST:
return redirect(reverse('about_course', args=[unicode(course_key)]))
else:
return redirect(reverse('about_course', args=[course_key.to_deprecated_string()]))
raise Http404
@ensure_csrf_cookie
......
<%page expression_filter="h" />
<%inherit file="main.html" />
<%namespace name='static' file='static_content.html'/>
<%!
......@@ -6,11 +7,11 @@
%>
<%block name="headextra">
<meta property="og:title" content="${course.display_name_with_default_escaped}"/>
<meta property="og:title" content="${course.display_name_with_default}"/>
<meta property="og:description" content="${get_course_about_section(request, course, 'short_description')}"/>
</%block>
<%block name="pagetitle">${course.display_name_with_default_escaped}</%block>
<%block name="pagetitle">${course.display_name_with_default}</%block>
<section class="course-info">
<header class="course-profile">
......@@ -22,15 +23,15 @@
</div>
<div class="heading-group">
<h1>
${course.display_name_with_default_escaped}
<a href="#">${course.display_org_with_default | h}</a>
${course.display_name_with_default}
<a href="#">${course.display_org_with_default}</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")}"/>
<input class="register" name="enroll" type="submit" value="${_('Enroll')}"/>
<input class="register" name="dont_enroll" type="submit" value="${_('Don\'t enroll')}"/>
</div>
</form>
</section>
......
......@@ -10,7 +10,7 @@ from django.conf.urls.static import static
from microsite_configuration import microsite
import auth_exchange.views
from courseware.views import EnrollStaffView
from config_models.views import ConfigurationModelCurrentAPIView
from courseware.views.index import CoursewareIndex
from openedx.core.djangoapps.programs.models import ProgramsApiConfig
......@@ -370,7 +370,7 @@ urlpatterns += (
r'^courses/{}/enroll_staff$'.format(
settings.COURSE_ID_PATTERN,
),
'courseware.views.enroll_staff',
EnrollStaffView.as_view(),
name='enroll_staff',
),
......
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