Repository navigation
Staff and instructor users of the master course are added to CCX created via REST APIs #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| """ | ||
| test utils | ||
| """ | ||
| import uuid | ||
| from nose.plugins.attrib import attr | ||
|
|
||
| from ccx_keys.locator import CCXLocator | ||
|
|
@@ -21,10 +22,14 @@ | |
| from xmodule.modulestore.tests.factories import CourseFactory | ||
| from xmodule.modulestore.django import modulestore | ||
|
|
||
| from lms.djangoapps.instructor.access import list_with_level, allow_access | ||
|
|
||
| from lms.djangoapps.ccx.utils import add_master_course_staff_to_ccx | ||
| from lms.djangoapps.ccx.views import ccx_course | ||
| from lms.djangoapps.instructor.access import ( | ||
| allow_access, | ||
| list_with_level, | ||
| ) | ||
| from lms.djangoapps.ccx.utils import ( | ||
| add_master_course_staff_to_ccx, | ||
| ccx_course, | ||
| ) | ||
| from lms.djangoapps.ccx.tests.factories import CcxFactory | ||
| from lms.djangoapps.ccx.tests.utils import CcxTestCase | ||
|
|
||
|
|
@@ -62,7 +67,7 @@ def test_ccx_locator(self): | |
| self.assertEqual(result, ccx) | ||
|
|
||
|
|
||
| class TestStaffOnCCX(CcxTestCase, SharedModuleStoreTestCase): | ||
| class TestStaffOnCCX(CcxTestCase): | ||
| """ | ||
| Tests for staff on ccx courses. | ||
| """ | ||
|
|
@@ -87,24 +92,91 @@ def setUp(self): | |
| allow_access(self.course, instructor, 'instructor') | ||
| self.assertTrue(CourseInstructorRole(self.course.id).has_user(instructor)) | ||
|
|
||
| self.make_coach() | ||
| self.ccx = self.make_ccx() | ||
| self.ccx_locator = CCXLocator.from_course_locator(self.course.id, self.ccx.id) | ||
|
|
||
| def test_add_master_course_staff_to_ccx(self): | ||
| """ | ||
| Test add staff of master course to ccx course | ||
| """ | ||
| self.make_coach() | ||
| ccx = self.make_ccx() | ||
| ccx_locator = CCXLocator.from_course_locator(self.course.id, ccx.id) | ||
| add_master_course_staff_to_ccx(self.course, ccx_locator, ccx.display_name) | ||
| add_master_course_staff_to_ccx(self.course, self.ccx_locator, self.ccx.display_name) | ||
|
|
||
| # assert that staff and instructors of master course has staff and instructor roles on ccx | ||
| list_staff_master_course = list_with_level(self.course, 'staff') | ||
| list_instructor_master_course = list_with_level(self.course, 'instructor') | ||
|
|
||
| with ccx_course(ccx_locator) as course_ccx: | ||
| with ccx_course(self.ccx_locator) as course_ccx: | ||
| list_staff_ccx_course = list_with_level(course_ccx, 'staff') | ||
| self.assertEqual(len(list_staff_master_course), len(list_staff_ccx_course)) | ||
| self.assertEqual(list_staff_master_course[0].email, list_staff_ccx_course[0].email) | ||
|
|
||
| list_instructor_ccx_course = list_with_level(course_ccx, 'instructor') | ||
| self.assertEqual(len(list_instructor_ccx_course), len(list_instructor_master_course)) | ||
| self.assertEqual(list_instructor_ccx_course[0].email, list_instructor_master_course[0].email) | ||
|
|
||
| def test_add_master_course_staff_to_ccx_display_name(self): | ||
| """ | ||
| Test add staff of master course to ccx course. | ||
| Specific test to check that a passed display name is in the | ||
| subject of the email sent to the enrolled users. | ||
| """ | ||
| outbox = self.get_outbox() | ||
| # create a unique display name | ||
| display_name = 'custom_display_{}'.format(uuid.uuid4()) | ||
| list_staff_master_course = list_with_level(self.course, 'staff') | ||
| list_instructor_master_course = list_with_level(self.course, 'instructor') | ||
| self.assertEqual(len(outbox), 0) | ||
| # give access to the course staff/instructor | ||
| add_master_course_staff_to_ccx(self.course, self.ccx_locator, display_name) | ||
| self.assertEqual(len(outbox), len(list_staff_master_course) + len(list_instructor_master_course)) | ||
| for email in outbox: | ||
| self.assertIn(display_name, email.subject) | ||
|
|
||
| def test_add_master_course_staff_to_ccx_idempotent(self): | ||
| """ | ||
| Test add staff of master course to ccx course multiple time will | ||
| not result in multiple enrollments. | ||
| """ | ||
| outbox = self.get_outbox() | ||
| list_staff_master_course = list_with_level(self.course, 'staff') | ||
| list_instructor_master_course = list_with_level(self.course, 'instructor') | ||
| self.assertEqual(len(outbox), 0) | ||
|
|
||
| # run the assignment the first time | ||
| add_master_course_staff_to_ccx(self.course, self.ccx_locator, self.ccx.display_name) | ||
| self.assertEqual(len(outbox), len(list_staff_master_course) + len(list_instructor_master_course)) | ||
| with ccx_course(self.ccx_locator) as course_ccx: | ||
| list_staff_ccx_course = list_with_level(course_ccx, 'staff') | ||
| list_instructor_ccx_course = list_with_level(course_ccx, 'instructor') | ||
| self.assertEqual(len(list_staff_master_course), len(list_staff_ccx_course)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to compare the lists directly instead of the count, or is that cumbersome? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually it looks like you could just say And you could remove the next couple lines as well
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually tried and for some reason it was failing |
||
| for user in list_staff_master_course: | ||
| self.assertIn(user, list_staff_ccx_course) | ||
| self.assertEqual(len(list_instructor_master_course), len(list_instructor_ccx_course)) | ||
| for user in list_instructor_master_course: | ||
| self.assertIn(user, list_instructor_ccx_course) | ||
|
|
||
| # run the assignment again | ||
| add_master_course_staff_to_ccx(self.course, self.ccx_locator, self.ccx.display_name) | ||
| # there are no new duplicated email | ||
| self.assertEqual(len(outbox), len(list_staff_master_course) + len(list_instructor_master_course)) | ||
| # there are no duplicated staffs | ||
| with ccx_course(self.ccx_locator) as course_ccx: | ||
| list_staff_ccx_course = list_with_level(course_ccx, 'staff') | ||
| list_instructor_ccx_course = list_with_level(course_ccx, 'instructor') | ||
| self.assertEqual(len(list_staff_master_course), len(list_staff_ccx_course)) | ||
| for user in list_staff_master_course: | ||
| self.assertIn(user, list_staff_ccx_course) | ||
| self.assertEqual(len(list_instructor_master_course), len(list_instructor_ccx_course)) | ||
| for user in list_instructor_master_course: | ||
| self.assertIn(user, list_instructor_ccx_course) | ||
|
|
||
| def test_add_master_course_staff_to_ccx_no_email(self): | ||
| """ | ||
| Test add staff of master course to ccx course without | ||
| sending enrollment email. | ||
| """ | ||
| outbox = self.get_outbox() | ||
| self.assertEqual(len(outbox), 0) | ||
| add_master_course_staff_to_ccx(self.course, self.ccx_locator, self.ccx.display_name, send_email=False) | ||
| self.assertEqual(len(outbox), 0) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you already did this comparison in the previous for loop