Commit 48e7fc81 by attiyaishaque

Bokchoy Test Deleted.

parent 275a31ec
...@@ -286,21 +286,3 @@ class CoursewareSequentialTabPage(CoursePage): ...@@ -286,21 +286,3 @@ class CoursewareSequentialTabPage(CoursePage):
return the body of the sequential currently selected return the body of the sequential currently selected
""" """
return self.q(css='#seq_content .xblock').text[0] return self.q(css='#seq_content .xblock').text[0]
class AboutPage(CoursePage):
"""
Course about page.
"""
url_path = "about/"
def is_browser_on_page(self):
return self.q(css='.intro').present
@property
def is_register_button_present(self):
"""
Returns True if the Enrollment button is visible on the about page.
"""
return self.q(css=".register").is_present()
...@@ -5,7 +5,6 @@ Studio Home page ...@@ -5,7 +5,6 @@ Studio Home page
from bok_choy.page_object import PageObject from bok_choy.page_object import PageObject
from . import BASE_URL from . import BASE_URL
from selenium.webdriver import ActionChains from selenium.webdriver import ActionChains
from ..common.utils import click_css
class DashboardPage(PageObject): class DashboardPage(PageObject):
...@@ -13,23 +12,11 @@ class DashboardPage(PageObject): ...@@ -13,23 +12,11 @@ class DashboardPage(PageObject):
Studio Home page Studio Home page
""" """
def __init__(self, browser):
"""
Initialize the page.
"""
super(DashboardPage, self).__init__(browser)
url = BASE_URL + "/course/" url = BASE_URL + "/course/"
def is_browser_on_page(self): def is_browser_on_page(self):
return self.q(css='.content-primary').visible return self.q(css='.content-primary').visible
def mouse_hover(self, element):
"""
Mouse over on given element.
"""
mouse_hover_action = ActionChains(self.browser).move_to_element(element)
mouse_hover_action.perform()
@property @property
def course_runs(self): def course_runs(self):
""" """
...@@ -61,15 +48,6 @@ class DashboardPage(PageObject): ...@@ -61,15 +48,6 @@ class DashboardPage(PageObject):
# Clicking on course with run will trigger an ajax event # Clicking on course with run will trigger an ajax event
self.wait_for_ajax() self.wait_for_ajax()
def view_live(self, element):
"""
Clicks the "View Live" link and switches to the new tab
"""
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)
def has_new_library_button(self): def has_new_library_button(self):
""" """
(bool) is the "New Library" button present? (bool) is the "New Library" button present?
......
""" """
Acceptance tests for Home Page (My Courses / My Libraries). Acceptance tests for Home Page (My Courses / My Libraries).
""" """
import os
import uuid
from bok_choy.web_app_test import WebAppTest from bok_choy.web_app_test import WebAppTest
from common.test.acceptance.pages.common.logout import LogoutPage
from common.test.acceptance.pages.lms.courseware import AboutPage, CoursewarePage
from flaky import flaky from flaky import flaky
from opaque_keys.edx.locator import LibraryLocator, CourseLocator from opaque_keys.edx.locator import LibraryLocator
from uuid import uuid4 from uuid import uuid4
from ...fixtures import PROGRAMS_STUB_URL from ...fixtures import PROGRAMS_STUB_URL
...@@ -178,78 +173,3 @@ class StudioLanguageTest(WebAppTest): ...@@ -178,78 +173,3 @@ class StudioLanguageTest(WebAppTest):
get_selected_option_text(language_selector), get_selected_option_text(language_selector),
u'Dummy Language (Esperanto)' u'Dummy Language (Esperanto)'
) )
class CourseNotEnrollTest(WebAppTest):
"""
Test that we can create a new content library on the studio home page.
"""
def setUp(self):
"""
Load the helper for the home page (dashboard page)
"""
super(CourseNotEnrollTest, self).setUp()
self.auth_page = AutoAuthPage(self.browser, staff=True)
self.dashboard_page = DashboardPage(self.browser)
self.course_name = "New Course Name"
self.course_org = "orgX"
self.course_number = str(uuid.uuid4().get_hex().upper()[0:6])
self.course_run = "2015_T2"
def course_id(self):
"""
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', 'split')
course_key = CourseLocator(
self.course_org,
self.course_number,
self.course_run,
deprecated=(default_store == 'split')
)
return unicode(course_key)
def test_unenroll_course(self):
"""
From the home page:
Click "New Course" ,Fill out the form
Submit the form
Return to the home page and logout
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 Don't Enroll button
-Second click the Enroll button and see the response.
"""
self.auth_page.visit()
self.dashboard_page.visit()
self.assertTrue(self.dashboard_page.new_course_button.present)
self.dashboard_page.click_new_course_button()
self.assertTrue(self.dashboard_page.is_new_course_form_visible())
self.dashboard_page.fill_new_course_form(
self.course_name, self.course_org, self.course_number, self.course_run
)
self.assertTrue(self.dashboard_page.is_new_course_form_valid())
self.dashboard_page.submit_new_course_form()
self.dashboard_page.visit()
LogoutPage(self.browser).visit()
AutoAuthPage(self.browser, course_id=None, staff=True).visit()
self.dashboard_page.visit()
self.dashboard_page.view_live('input[name= "dont_enroll"]')
about_page = AboutPage(self.browser, self.course_id)
about_page.wait_for_page()
self.assertTrue(about_page.is_browser_on_page())
self.assertTrue(about_page.is_register_button_present)
self.dashboard_page.visit()
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())
...@@ -39,7 +39,7 @@ from course_modes.tests.factories import CourseModeFactory ...@@ -39,7 +39,7 @@ from course_modes.tests.factories import CourseModeFactory
from courseware.model_data import set_score from courseware.model_data import set_score
from courseware.module_render import toc_for_course from courseware.module_render import toc_for_course
from courseware.testutils import RenderXBlockTestMixin from courseware.testutils import RenderXBlockTestMixin
from courseware.tests.factories import StudentModuleFactory from courseware.tests.factories import StudentModuleFactory, GlobalStaffFactory
from courseware.url_helpers import get_redirect_url from courseware.url_helpers import get_redirect_url
from courseware.user_state_client import DjangoXBlockUserStateClient from courseware.user_state_client import DjangoXBlockUserStateClient
from courseware.views.index import render_accordion, CoursewareIndex from courseware.views.index import render_accordion, CoursewareIndex
...@@ -196,7 +196,7 @@ class ViewsTestCase(ModuleStoreTestCase): ...@@ -196,7 +196,7 @@ class ViewsTestCase(ModuleStoreTestCase):
def setUp(self): def setUp(self):
super(ViewsTestCase, self).setUp() super(ViewsTestCase, self).setUp()
self.course = CourseFactory.create(display_name=u'teꜱᴛ course') self.course = CourseFactory.create(display_name=u'teꜱᴛ course', run="Testing_course")
self.chapter = ItemFactory.create( self.chapter = ItemFactory.create(
category='chapter', category='chapter',
parent_location=self.course.location, parent_location=self.course.location,
...@@ -323,63 +323,104 @@ class ViewsTestCase(ModuleStoreTestCase): ...@@ -323,63 +323,104 @@ 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 _create_url_for_enroll_staff(self): def _create_global_staff_user(self):
""" """
User will have satff access and creates the url for enroll_staff view Create global staff user and log them in
""" """
self.user.is_staff = True self.global_staff = GlobalStaffFactory.create() # pylint: disable=attribute-defined-outside-init
self.user.save() # pylint: disable=no-member self.client.login(username=self.global_staff.username, password='test')
self.client.login(username=self.user.username, password=self.password)
# create the course
course = CourseFactory.create()
def _create_url_for_enroll_staff(self):
"""
creates the courseware url and enroll staff url
"""
# create the _next parameter # create the _next parameter
courseware_url = reverse('courseware', kwargs={ courseware_url = reverse(
'course_id': unicode(course.id)}) + '?activate_block_id=test_block_id' 'courseware_section',
kwargs={
'course_id': unicode(self.course_key),
'chapter': unicode(self.chapter.location.name),
'section': unicode(self.section.location.name),
}
)
# create the url for enroll_staff view # create the url for enroll_staff view
enroll_staff_url = "{enroll_staff_url}?next={courseware_url}".format( enroll_url = "{enroll_url}?next={courseware_url}".format(
enroll_staff_url=reverse('enroll_staff', kwargs={'course_id': unicode(course.id)}), enroll_url=reverse('enroll_staff', kwargs={'course_id': unicode(self.course.id)}),
courseware_url=courseware_url courseware_url=courseware_url
) )
return enroll_staff_url, course.id return courseware_url, enroll_url
def test_redirection_unenrolled_staff(self): @ddt.data(
({'enroll': "Enroll"}, True),
({'dont_enroll': "Don't enroll"}, False))
@ddt.unpack
def test_enroll_staff_redirection(self, data, enrollment):
""" """
Test that staff is not redirected to the 'about' page when visiting an unregistered course Verify unenrolled staff is redirected to correct url.
""" """
enroll_staff_url, __ = self._create_url_for_enroll_staff() self._create_global_staff_user()
courseware_url, enroll_url = self._create_url_for_enroll_staff()
# Check the GET method response = self.client.post(enroll_url, data=data, follow=True)
response = self.client.get(enroll_staff_url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
response_content = response.content
self.assertIn('Enroll', response_content)
self.assertIn("dont_enroll", response_content)
@ddt.data( # we were redirected to our current location
({'enroll': "Enroll"}, 'courses/{}/courseware?activate_block_id=test_block_id'), self.assertIn(302, response.redirect_chain[0])
({'dont_enroll': "Don't enroll"}, '/courses/{}/about')) self.assertEqual(len(response.redirect_chain), 1)
@ddt.unpack if enrollment:
def test_enroll_staff_redirection(self, data, expected_url): self.assertRedirects(response, courseware_url)
else:
self.assertRedirects(response, '/courses/{}/about'.format(unicode(self.course_key)))
def test_enroll_staff_with_invalid_data(self):
""" """
Verify unenrolled staff is redirected to the page according to data passed. If we try to post with an invalid data pattern, then we'll redirected to
course about page.
""" """
enroll_staff_url, course_id = self._create_url_for_enroll_staff() self._create_global_staff_user()
response = self.client.post(enroll_staff_url, data=data) __, enroll_url = self._create_url_for_enroll_staff()
response = self.client.post(enroll_url, data={'test': "test"})
# Here we check the status code 302 because of the redirect
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertRedirects(response, expected_url.format(unicode(course_id))) self.assertRedirects(response, '/courses/{}/about'.format(unicode(self.course_key)))
def test_enroll_staff_redirection_invalid_data(self): def test_courseware_redirection(self):
""" """
Verify unenrolled staff is redirected to the page according to data passed. Tests that a global staff member is redirected to the staff enrollment page.
Un-enrolled Staff user should be redirected to the staff enrollment page accessing courseware,
user chooses to enroll in the course. User is enrolled and redirected to the requested url.
Scenario:
1. Un-enrolled staff tries to access any course vertical (courseware url).
2. User is redirected to the staff enrollment page.
3. User chooses to enroll in the course.
4. User is enrolled in the course and redirected to the requested courseware url.
""" """
enroll_staff_url, __ = self._create_url_for_enroll_staff() self._create_global_staff_user()
response = self.client.post(enroll_staff_url, data={'test': "test"}) courseware_url, enroll_url = self._create_url_for_enroll_staff()
self.assertEqual(response.status_code, 404)
# Accessing the courseware url in which not enrolled & redirected to staff enrollment page
response = self.client.get(courseware_url, follow=True)
self.assertEqual(response.status_code, 200)
self.assertIn(302, response.redirect_chain[0])
self.assertEqual(len(response.redirect_chain), 1)
self.assertRedirects(response, enroll_url)
# Accessing the enroll staff url and verify the correct url
response = self.client.get(enroll_url)
self.assertEqual(response.status_code, 200)
response_content = response.content
self.assertIn('Enroll', response_content)
self.assertIn("dont_enroll", response_content)
# Post the valid data to enroll the staff in the course
response = self.client.post(enroll_url, data={'enroll': "Enroll"}, follow=True)
self.assertEqual(response.status_code, 200)
self.assertIn(302, response.redirect_chain[0])
self.assertEqual(len(response.redirect_chain), 1)
self.assertRedirects(response, courseware_url)
# Verify staff has been enrolled to the given course
self.assertTrue(CourseEnrollment.is_enrolled(self.global_staff, self.course.id))
@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})
......
...@@ -42,27 +42,23 @@ def get_redirect_url(course_key, usage_key): ...@@ -42,27 +42,23 @@ def get_redirect_url(course_key, usage_key):
# Here we use the navigation_index from the position returned from # Here we use the navigation_index from the position returned from
# path_to_location - we can only navigate to the topmost vertical at the # path_to_location - we can only navigate to the topmost vertical at the
# moment # moment
redirect_url = reverse( redirect_url = reverse(
'courseware_position', 'courseware_position',
args=(unicode(course_key), chapter, section, navigation_index(position)) args=(unicode(course_key), chapter, section, navigation_index(position))
) )
redirect_url += "?{}".format(urlencode({'activate_block_id': unicode(final_target_id)})) redirect_url += "?{}".format(urlencode({'activate_block_id': unicode(final_target_id)}))
return redirect_url return redirect_url
def get_redirect_url_for_global_staff(course_key, location): def get_redirect_url_for_global_staff(course_key, _next):
""" """
Returns the redirect url Returns the redirect url for staff enrollment
Args: Args:
course_key(str): Course key string course_key(str): Course key string
location(str): The location id of course component _next(str): Redirect url of course component
""" """
redirect_url = ("{url}?next={redirect}".format(
_next = get_redirect_url(course_key, location)
redirect_url = "{url}?next={redirect}".format(
url=reverse('enroll_staff', args=[unicode(course_key)]), url=reverse('enroll_staff', args=[unicode(course_key)]),
redirect=_next) redirect=_next))
return redirect_url return redirect_url
...@@ -15,6 +15,8 @@ from django.views.decorators.cache import cache_control ...@@ -15,6 +15,8 @@ from django.views.decorators.cache import cache_control
from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic import View from django.views.generic import View
from django.shortcuts import redirect from django.shortcuts import redirect
from courseware.url_helpers import get_redirect_url_for_global_staff
from edxmako.shortcuts import render_to_response, render_to_string from edxmako.shortcuts import render_to_response, render_to_string
import logging import logging
import newrelic.agent import newrelic.agent
...@@ -26,7 +28,9 @@ from opaque_keys.edx.keys import CourseKey ...@@ -26,7 +28,9 @@ from opaque_keys.edx.keys import CourseKey
from openedx.core.lib.gating import api as gating_api from openedx.core.lib.gating import api as gating_api
from openedx.core.djangoapps.user_api.preferences.api import get_user_preference from openedx.core.djangoapps.user_api.preferences.api import get_user_preference
from shoppingcart.models import CourseRegistrationCode from shoppingcart.models import CourseRegistrationCode
from student.models import CourseEnrollment
from student.views import is_course_blocked from student.views import is_course_blocked
from student.roles import GlobalStaff
from util.views import ensure_valid_course_key from util.views import ensure_valid_course_key
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.x_module import STUDENT_VIEW from xmodule.x_module import STUDENT_VIEW
...@@ -89,6 +93,7 @@ class CoursewareIndex(View): ...@@ -89,6 +93,7 @@ class CoursewareIndex(View):
self.section_url_name = section self.section_url_name = section
self.position = position self.position = position
self.chapter, self.section = None, None self.chapter, self.section = None, None
self.url = request.path
try: try:
self._init_new_relic() self._init_new_relic()
...@@ -221,6 +226,11 @@ class CoursewareIndex(View): ...@@ -221,6 +226,11 @@ class CoursewareIndex(View):
self.effective_user, self.effective_user,
unicode(self.course.id) unicode(self.course.id)
) )
user_is_global_staff = GlobalStaff().has_user(self.effective_user)
user_is_enrolled = CourseEnrollment.is_enrolled(self.effective_user, self.course_key)
if user_is_global_staff and not user_is_enrolled:
redirect_url = get_redirect_url_for_global_staff(self.course_key, _next=self.url)
raise Redirect(redirect_url)
raise Redirect(reverse('about_course', args=[unicode(self.course.id)])) raise Redirect(reverse('about_course', args=[unicode(self.course.id)]))
def _redirect_if_needed_for_prereqs(self): def _redirect_if_needed_for_prereqs(self):
......
...@@ -12,30 +12,34 @@ ...@@ -12,30 +12,34 @@
</%block> </%block>
<%block name="pagetitle">${course.display_name_with_default}</%block> <%block name="pagetitle">${course.display_name_with_default}</%block>
<main id="main" aria-label="Content" tabindex="-1">
<section class="course-info"> <div class="course-info">
<header class="course-profile"> <header class="course-profile">
<div class="intro-inner-wrapper"> <div class="intro-inner-wrapper">
<div class="table"> <div class="table">
<section class="intro"> <div class="intro">
<div class="heading-group"> <div class="heading-group">
<h3> ${_("You should Register before trying to access the Unit")}</h3> <h3> ${_("You should Register before trying to access the Unit")}</h3>
</div>
<div class="heading-group">
<h1>
${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')}"/>
</div> </div>
</form> <div class="heading-group">
</section> <p>
${course.display_name_with_default}
</p>
</div>
<form role="form" id="enroll_staff_form" method="post" action="">
<input type="hidden" name="csrfmiddlewaretoken" value="${ csrftoken }"/>
<div class="main-cta">
<button class="register" name="enroll" type="submit"
value="${_('Enroll')}">${_('Enroll')}<span
class="sr">${course.display_name_with_default}</span></button>
<button class="register" name="dont_enroll" type="submit"
value="${_('Don\'t enroll')}">${_('Don\'t enroll')}<span
class="sr">${course.display_name_with_default}</span></button>
</div>
</form>
</div>
</div>
</div> </div>
</div> </header>
</header> </div>
</section> </main>
...@@ -10,7 +10,7 @@ from django.conf.urls.static import static ...@@ -10,7 +10,7 @@ from django.conf.urls.static import static
from microsite_configuration import microsite from microsite_configuration import microsite
import auth_exchange.views import auth_exchange.views
from courseware.views import EnrollStaffView from courseware.views.views import EnrollStaffView
from config_models.views import ConfigurationModelCurrentAPIView from config_models.views import ConfigurationModelCurrentAPIView
from courseware.views.index import CoursewareIndex from courseware.views.index import CoursewareIndex
from openedx.core.djangoapps.programs.models import ProgramsApiConfig from openedx.core.djangoapps.programs.models import ProgramsApiConfig
......
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