From b1751e70c3159bb66d78c88ac231bcd6d335c161 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 8 Feb 2016 10:25:55 +0000 Subject: [PATCH] User automatically registered to course. --- common/djangoapps/student/views.py | 36 +++++++++++-------- .../pages/lms/instructor_dashboard.py | 26 ++++++++++++++ .../lms/test_lms_instructor_dashboard.py | 36 +++++++++++++++++++ 3 files changed, 83 insertions(+), 15 deletions(-) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 89040c6dc6..6b74ecbce3 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -1775,6 +1775,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) else: 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 # logged in until they close the browser. They can't log in again until they click @@ -1804,6 +1805,25 @@ def create_account_with_params(request, params): 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 def create_account(request, post_override=None): """ @@ -2000,21 +2020,7 @@ def activate_account(request, key): already_active = False # 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) - 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 - ) + _enroll_user_in_pending_courses(regs[0].user) resp = render_to_response( "registration/activation_complete.html", diff --git a/common/test/acceptance/pages/lms/instructor_dashboard.py b/common/test/acceptance/pages/lms/instructor_dashboard.py index 9b462b4904..b94ab914a0 100644 --- a/common/test/acceptance/pages/lms/instructor_dashboard.py +++ b/common/test/acceptance/pages/lms/instructor_dashboard.py @@ -678,6 +678,7 @@ class MembershipPageAutoEnrollSection(PageObject): 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"]' + batch_enrollment_selector = '.batch-enrollment' NOTIFICATION_ERROR = 'error' NOTIFICATION_WARNING = 'warning' NOTIFICATION_SUCCESS = 'confirmation' @@ -750,6 +751,31 @@ class MembershipPageAutoEnrollSection(PageObject): self.q(css=self.auto_enroll_browse_button_selector).results[0].send_keys(file_path) 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): """ diff --git a/common/test/acceptance/tests/lms/test_lms_instructor_dashboard.py b/common/test/acceptance/tests/lms/test_lms_instructor_dashboard.py index 50c4faabd6..9205cdf700 100644 --- a/common/test/acceptance/tests/lms/test_lms_instructor_dashboard.py +++ b/common/test/acceptance/tests/lms/test_lms_instructor_dashboard.py @@ -21,6 +21,7 @@ from ...pages.lms.dashboard import DashboardPage from ...pages.lms.problem import ProblemPage from ...pages.lms.track_selection import TrackSelectionPage 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 ...fixtures.certificates import CertificateConfigFixture @@ -58,6 +59,9 @@ class AutoEnrollmentWithCSVTest(BaseInstructorDashboardTest): self.log_in_as_instructor() instructor_dashboard_page = self.visit_instructor_dashboard() 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): """ @@ -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_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): """ Scenario: Clicking on the upload button without specifying a CSV file results in error.