Commit d114be73 by Awais Jibran

Merge pull request #11514 from attiyaIshaque/ai/tnl4067-auto-register-course

User automatically registered to course.
parents c88697ca b1751e70
...@@ -1795,6 +1795,7 @@ def create_account_with_params(request, params): ...@@ -1795,6 +1795,7 @@ def create_account_with_params(request, params):
log.error(u'Unable to send activation email to user from "%s"', from_address, exc_info=True) log.error(u'Unable to send activation email to user from "%s"', from_address, exc_info=True)
else: else:
registration.activate() registration.activate()
_enroll_user_in_pending_courses(user) # Enroll student in any pending courses
# Immediately after a user creates an account, we log them in. They are only # Immediately after a user creates an account, we log them in. They are only
# logged in until they close the browser. They can't log in again until they click # logged in until they close the browser. They can't log in again until they click
...@@ -1824,6 +1825,25 @@ def create_account_with_params(request, params): ...@@ -1824,6 +1825,25 @@ def create_account_with_params(request, params):
return new_user return new_user
def _enroll_user_in_pending_courses(student):
"""
Enroll student in any pending courses he/she may have.
"""
ceas = CourseEnrollmentAllowed.objects.filter(email=student.email)
for cea in ceas:
if cea.auto_enroll:
enrollment = CourseEnrollment.enroll(student, cea.course_id)
manual_enrollment_audit = ManualEnrollmentAudit.get_manual_enrollment_by_email(student.email)
if manual_enrollment_audit is not None:
# get the enrolled by user and reason from the ManualEnrollmentAudit table.
# then create a new ManualEnrollmentAudit table entry for the same email
# different transition state.
ManualEnrollmentAudit.create_manual_enrollment_audit(
manual_enrollment_audit.enrolled_by, student.email, ALLOWEDTOENROLL_TO_ENROLLED,
manual_enrollment_audit.reason, enrollment
)
@csrf_exempt @csrf_exempt
def create_account(request, post_override=None): def create_account(request, post_override=None):
""" """
...@@ -2020,21 +2040,7 @@ def activate_account(request, key): ...@@ -2020,21 +2040,7 @@ def activate_account(request, key):
already_active = False already_active = False
# Enroll student in any pending courses he/she may have if auto_enroll flag is set # Enroll student in any pending courses he/she may have if auto_enroll flag is set
student = User.objects.filter(id=regs[0].user_id) _enroll_user_in_pending_courses(regs[0].user)
if student:
ceas = CourseEnrollmentAllowed.objects.filter(email=student[0].email)
for cea in ceas:
if cea.auto_enroll:
enrollment = CourseEnrollment.enroll(student[0], cea.course_id)
manual_enrollment_audit = ManualEnrollmentAudit.get_manual_enrollment_by_email(student[0].email)
if manual_enrollment_audit is not None:
# get the enrolled by user and reason from the ManualEnrollmentAudit table.
# then create a new ManualEnrollmentAudit table entry for the same email
# different transition state.
ManualEnrollmentAudit.create_manual_enrollment_audit(
manual_enrollment_audit.enrolled_by, student[0].email, ALLOWEDTOENROLL_TO_ENROLLED,
manual_enrollment_audit.reason, enrollment
)
resp = render_to_response( resp = render_to_response(
"registration/activation_complete.html", "registration/activation_complete.html",
......
...@@ -678,6 +678,7 @@ class MembershipPageAutoEnrollSection(PageObject): ...@@ -678,6 +678,7 @@ class MembershipPageAutoEnrollSection(PageObject):
auto_enroll_browse_button_selector = '.auto_enroll_csv .file-browse input.file_field#browseBtn' auto_enroll_browse_button_selector = '.auto_enroll_csv .file-browse input.file_field#browseBtn'
auto_enroll_upload_button_selector = '.auto_enroll_csv button[name="enrollment_signup_button"]' auto_enroll_upload_button_selector = '.auto_enroll_csv button[name="enrollment_signup_button"]'
batch_enrollment_selector = '.batch-enrollment'
NOTIFICATION_ERROR = 'error' NOTIFICATION_ERROR = 'error'
NOTIFICATION_WARNING = 'warning' NOTIFICATION_WARNING = 'warning'
NOTIFICATION_SUCCESS = 'confirmation' NOTIFICATION_SUCCESS = 'confirmation'
...@@ -750,6 +751,31 @@ class MembershipPageAutoEnrollSection(PageObject): ...@@ -750,6 +751,31 @@ class MembershipPageAutoEnrollSection(PageObject):
self.q(css=self.auto_enroll_browse_button_selector).results[0].send_keys(file_path) self.q(css=self.auto_enroll_browse_button_selector).results[0].send_keys(file_path)
self.click_upload_file_button() self.click_upload_file_button()
def fill_enrollment_batch_text_box(self, email):
"""
Fill in the form with the provided email and submit it.
"""
email_selector = "{} >p>textarea".format(self.batch_enrollment_selector)
enrollment_button = "{} .enrollment-button[data-action='enroll']".format(self.batch_enrollment_selector)
# Fill the email addresses after the email selector is visible.
self.wait_for_element_visibility(email_selector, 'Email field is visible')
self.q(css=email_selector).fill(email)
# Verify enrollment button is present before clicking
EmptyPromise(
lambda: self.q(css=enrollment_button).present, "Enrollment button"
).fulfill()
self.q(css=enrollment_button).click()
def get_notification_text(self):
"""
Check notification div is visible and have message.
"""
notification_selector = '{} .request-response'.format(self.batch_enrollment_selector)
self.wait_for_element_visibility(notification_selector, 'Notification div is visible')
return self.q(css="{} h3".format(notification_selector)).text
class SpecialExamsPageAllowanceSection(PageObject): class SpecialExamsPageAllowanceSection(PageObject):
""" """
......
...@@ -21,6 +21,7 @@ from ...pages.lms.dashboard import DashboardPage ...@@ -21,6 +21,7 @@ from ...pages.lms.dashboard import DashboardPage
from ...pages.lms.problem import ProblemPage from ...pages.lms.problem import ProblemPage
from ...pages.lms.track_selection import TrackSelectionPage from ...pages.lms.track_selection import TrackSelectionPage
from ...pages.lms.pay_and_verify import PaymentAndVerificationFlow, FakePaymentPage from ...pages.lms.pay_and_verify import PaymentAndVerificationFlow, FakePaymentPage
from ...pages.lms.login_and_register import CombinedLoginAndRegisterPage
from common.test.acceptance.tests.helpers import disable_animations from common.test.acceptance.tests.helpers import disable_animations
from ...fixtures.certificates import CertificateConfigFixture from ...fixtures.certificates import CertificateConfigFixture
...@@ -58,6 +59,9 @@ class AutoEnrollmentWithCSVTest(BaseInstructorDashboardTest): ...@@ -58,6 +59,9 @@ class AutoEnrollmentWithCSVTest(BaseInstructorDashboardTest):
self.log_in_as_instructor() self.log_in_as_instructor()
instructor_dashboard_page = self.visit_instructor_dashboard() instructor_dashboard_page = self.visit_instructor_dashboard()
self.auto_enroll_section = instructor_dashboard_page.select_membership().select_auto_enroll_section() self.auto_enroll_section = instructor_dashboard_page.select_membership().select_auto_enroll_section()
# Initialize the page objects
self.register_page = CombinedLoginAndRegisterPage(self.browser, start_page="register")
self.dashboard_page = DashboardPage(self.browser)
def test_browse_and_upload_buttons_are_visible(self): def test_browse_and_upload_buttons_are_visible(self):
""" """
...@@ -68,6 +72,38 @@ class AutoEnrollmentWithCSVTest(BaseInstructorDashboardTest): ...@@ -68,6 +72,38 @@ class AutoEnrollmentWithCSVTest(BaseInstructorDashboardTest):
self.assertTrue(self.auto_enroll_section.is_file_attachment_browse_button_visible()) self.assertTrue(self.auto_enroll_section.is_file_attachment_browse_button_visible())
self.assertTrue(self.auto_enroll_section.is_upload_button_visible()) self.assertTrue(self.auto_enroll_section.is_upload_button_visible())
def test_enroll_unregister_student(self):
"""
Scenario: On the Membership tab of the Instructor Dashboard, Batch Enrollment div is visible.
Given that I am on the Membership tab on the Instructor Dashboard
Then I enter the email and enroll it.
Logout the current page.
And Navigate to the registration page and register the student.
Then I see the course which enrolled the student.
"""
username = "test_{uuid}".format(uuid=self.unique_id[0:6])
email = "{user}@example.com".format(user=username)
self.auto_enroll_section.fill_enrollment_batch_text_box(email)
self.assertIn(
'Successfully sent enrollment emails to the following users. '
'They will be enrolled once they register:',
self.auto_enroll_section.get_notification_text()
)
LogoutPage(self.browser).visit()
self.register_page.visit()
self.register_page.register(
email=email,
password="123456",
username=username,
full_name="Test User",
terms_of_service=True,
country="US",
favorite_movie="Harry Potter",
)
course_names = self.dashboard_page.wait_for_page().available_courses
self.assertEquals(len(course_names), 1)
self.assertIn(self.course_info["display_name"], course_names)
def test_clicking_file_upload_button_without_file_shows_error(self): def test_clicking_file_upload_button_without_file_shows_error(self):
""" """
Scenario: Clicking on the upload button without specifying a CSV file results in error. Scenario: Clicking on the upload button without specifying a CSV file results in error.
......
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