Commit 2ddc90cb by Ben Patterson

Merge pull request #6886 from edx/benp/change-enrollment-event-tests

An upgrade to verified should emit a mode_changed event.
parents 0f92b092 630801c7
......@@ -234,6 +234,24 @@ def element_has_text(page, css_selector, text):
return text_present
def assert_event_emitted_num_times(event_collection, event_name, event_time, event_user_id, num_times_emitted):
"""
Tests the number of times a particular event was emitted.
:param event_collection: MongoClient instance to query.
:param event_name: Expected event name (e.g., "edx.course.enrollment.activated")
:param event_time: Latest expected time, after which the event would fire (e.g., the beginning of the test case)
"""
assert(
event_collection.find(
{
"name": event_name,
"time": {"$gt": event_time},
"event.user_id": int(event_user_id),
}
).count() == num_times_emitted
)
class UniqueCourseTest(WebAppTest):
"""
Test that provides a unique course ID.
......
......@@ -3,9 +3,11 @@
End-to-end tests for the LMS.
"""
from datetime import datetime
from textwrap import dedent
from unittest import skip
from nose.plugins.attrib import attr
from pymongo import MongoClient
from bok_choy.promise import EmptyPromise
from bok_choy.web_app_test import WebAppTest
......@@ -14,7 +16,8 @@ from ..helpers import (
load_data_str,
generate_course_key,
select_option_by_value,
element_has_text
element_has_text,
assert_event_emitted_num_times
)
from ...pages.lms.auto_auth import AutoAuthPage
from ...pages.lms.create_mode import ModeCreationPage
......@@ -214,6 +217,8 @@ class PayAndVerifyTest(UniqueCourseTest):
self.upgrade_page = PaymentAndVerificationFlow(self.browser, self.course_id, entry_point='upgrade')
self.fake_payment_page = FakePaymentPage(self.browser, self.course_id)
self.dashboard_page = DashboardPage(self.browser)
self.event_collection = MongoClient()["test"]["events"]
self.start_time = datetime.now()
# Create a course
CourseFixture(
......@@ -232,7 +237,7 @@ class PayAndVerifyTest(UniqueCourseTest):
@skip("Flaky 02/02/2015")
def test_immediate_verification_enrollment(self):
# Create a user and log them in
AutoAuthPage(self.browser).visit()
student_id = AutoAuthPage(self.browser).visit().get_user_id()
# Navigate to the track selection page
self.track_selection_page.visit()
......@@ -246,6 +251,24 @@ class PayAndVerifyTest(UniqueCourseTest):
# Submit payment
self.fake_payment_page.submit_payment()
# Expect enrollment activated event
assert_event_emitted_num_times(
self.event_collection,
"edx.course.enrollment.activated",
self.start_time,
student_id,
1
)
# Expect that one mode_changed enrollment event fired as part of the upgrade
assert_event_emitted_num_times(
self.event_collection,
"edx.course.enrollment.mode_changed",
self.start_time,
student_id,
1
)
# Proceed to verification
self.payment_and_verification_flow.immediate_verification()
......@@ -269,7 +292,7 @@ class PayAndVerifyTest(UniqueCourseTest):
def test_deferred_verification_enrollment(self):
# Create a user and log them in
AutoAuthPage(self.browser).visit()
student_id = AutoAuthPage(self.browser).visit().get_user_id()
# Navigate to the track selection page
self.track_selection_page.visit()
......@@ -283,6 +306,15 @@ class PayAndVerifyTest(UniqueCourseTest):
# Submit payment
self.fake_payment_page.submit_payment()
# Expect enrollment activated event
assert_event_emitted_num_times(
self.event_collection,
"edx.course.enrollment.activated",
self.start_time,
student_id,
1
)
# Navigate to the dashboard
self.dashboard_page.visit()
......@@ -292,7 +324,7 @@ class PayAndVerifyTest(UniqueCourseTest):
def test_enrollment_upgrade(self):
# Create a user, log them in, and enroll them in the honor mode
AutoAuthPage(self.browser, course_id=self.course_id).visit()
student_id = AutoAuthPage(self.browser, course_id=self.course_id).visit().get_user_id()
# Navigate to the dashboard
self.dashboard_page.visit()
......@@ -313,6 +345,24 @@ class PayAndVerifyTest(UniqueCourseTest):
# Submit payment
self.fake_payment_page.submit_payment()
# Expect that one mode_changed enrollment event fired as part of the upgrade
assert_event_emitted_num_times(
self.event_collection,
"edx.course.enrollment.mode_changed",
self.start_time,
student_id,
1
)
# Expect no enrollment activated event
assert_event_emitted_num_times(
self.event_collection,
"edx.course.enrollment.activated",
self.start_time,
student_id,
0
)
# Navigate to the dashboard
self.dashboard_page.visit()
......
Feature: Change Enrollment Events
As a registered user
I want to change my enrollment mode
Scenario: I can change my enrollment
Given The course "6.002x" exists
And the course "6.002x" has all enrollment modes
And I am logged in
And I visit the courses page
When I register to audit the course
And a "edx.course.enrollment.activated" server event is emitted
# Skipping the rest in master. The testcase has not been run and no longer works.
#And a "edx.course.enrollment.mode_changed" server events is emitted
#
#And I visit the dashboard
#And I click on Challenge Yourself
#And I choose an honor code upgrade
#Then I should be on the dashboard page
#Then 2 "edx.course.enrollment.mode_changed" server event is emitted
#
## don't emit another mode_changed event upon unenrollment
#When I unenroll from the course numbered "6.002x"
#Then 2 "edx.course.enrollment.mode_changed" server events is emitted
""" Provides lettuce acceptance methods for course enrollment changes """
from __future__ import absolute_import
from lettuce import world, step
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from logging import getLogger
logger = getLogger(__name__)
import time
@step(u'the course "([^"]*)" has all enrollment modes$')
def add_enrollment_modes_to_course(_step, course):
""" Add honor, audit, and verified modes to the sample course """
world.CourseModeFactory.create(
course_id=SlashSeparatedCourseKey("edx", course, 'Test_Course'),
mode_slug="verified",
mode_display_name="Verified Course",
min_price=3
)
world.CourseModeFactory.create(
course_id=SlashSeparatedCourseKey("edx", course, 'Test_Course'),
mode_slug="honor",
mode_display_name="Honor Course",
)
world.CourseModeFactory.create(
course_id=SlashSeparatedCourseKey("edx", course, 'Test_Course'),
mode_slug="audit",
mode_display_name="Audit Course",
)
@step(u'I click on Challenge Yourself$')
def challenge_yourself(_step):
""" Simulates clicking 'Challenge Yourself' button on course """
challenge_button = world.browser.find_by_css('.wrapper-tip')
challenge_button.click()
verified_button = world.browser.find_by_css('#upgrade-to-verified')
verified_button.click()
@step(u'I choose an honor code upgrade$')
def honor_code_upgrade(_step):
""" Simulates choosing the honor code mode on the upgrade page """
honor_code_link = world.browser.find_by_css('.title-expand')
honor_code_link.click()
time.sleep(1)
honor_code_checkbox = world.browser.find_by_css('#honor-code')
honor_code_checkbox.click()
upgrade_button = world.browser.find_by_name("certificate_mode")
upgrade_button.click()
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