def test_inline_without_always_cohort_inline_discussion_flag(self): self.create_discussion("Chapter", "Discussion") set_course_cohort_settings(course_key=self.course.id, is_cohorted=True, always_cohort_inline_discussions=False) self.assert_category_map_equals( { "entries": {}, "subcategories": { "Chapter": { "entries": { "Discussion": { "id": "discussion1", "sort_key": None, "is_cohorted": False, } }, "subcategories": {}, "children": ["Discussion"] } }, "children": ["Chapter"] }, cohorted_if_in_list=True)
def setUp(self): super(UniversityIDViewStaffTestCase, self).setUp() set_course_cohort_settings(course_key=self.course.id, is_cohorted=True) self.student_form_url = reverse('edraak_university:id', args=[unicode(self.course.id)]) self.staff_list_url = reverse('edraak_university:id_staff', args=[unicode(self.course.id)])
def test_configured_topics(self): self.course.discussion_topics = { "Topic A": {"id": "Topic_A"}, "Topic B": {"id": "Topic_B"}, "Topic C": {"id": "Topic_C"} } def check_cohorted_topics(expected_ids): # pylint: disable=missing-docstring self.assert_category_map_equals( { "entries": { "Topic A": {"id": "Topic_A", "sort_key": "Topic A", "is_cohorted": "Topic_A" in expected_ids}, "Topic B": {"id": "Topic_B", "sort_key": "Topic B", "is_cohorted": "Topic_B" in expected_ids}, "Topic C": {"id": "Topic_C", "sort_key": "Topic C", "is_cohorted": "Topic_C" in expected_ids}, }, "subcategories": {}, "children": ["Topic A", "Topic B", "Topic C"] } ) check_cohorted_topics([]) # default (empty) cohort config set_course_cohort_settings(course_key=self.course.id, is_cohorted=False, cohorted_discussions=[]) check_cohorted_topics([]) set_course_cohort_settings(course_key=self.course.id, is_cohorted=True, cohorted_discussions=[]) check_cohorted_topics([]) set_course_cohort_settings( course_key=self.course.id, is_cohorted=True, cohorted_discussions=["Topic_B", "Topic_C"], always_cohort_inline_discussions=False, ) check_cohorted_topics(["Topic_B", "Topic_C"]) set_course_cohort_settings( course_key=self.course.id, is_cohorted=True, cohorted_discussions=["Topic_A", "Some_Other_Topic"], always_cohort_inline_discussions=False, ) check_cohorted_topics(["Topic_A"]) # unlikely case, but make sure it works. set_course_cohort_settings( course_key=self.course.id, is_cohorted=False, cohorted_discussions=["Topic_A"], always_cohort_inline_discussions=False, ) check_cohorted_topics([])
def test_configured_topics(self): self.course.discussion_topics = { "Topic A": {"id": "Topic_A"}, "Topic B": {"id": "Topic_B"}, "Topic C": {"id": "Topic_C"} } def check_cohorted_topics(expected_ids): # pylint: disable=missing-docstring self.assert_category_map_equals( { "entries": { "Topic A": {"id": "Topic_A", "sort_key": "Topic A", "is_cohorted": "Topic_A" in expected_ids}, "Topic B": {"id": "Topic_B", "sort_key": "Topic B", "is_cohorted": "Topic_B" in expected_ids}, "Topic C": {"id": "Topic_C", "sort_key": "Topic C", "is_cohorted": "Topic_C" in expected_ids}, }, "subcategories": {}, "children": ["Topic A", "Topic B", "Topic C"] } ) check_cohorted_topics([]) # default (empty) cohort config set_course_cohort_settings(course_key=self.course.id, is_cohorted=False, cohorted_discussions=[]) check_cohorted_topics([]) set_course_cohort_settings(course_key=self.course.id, is_cohorted=True, cohorted_discussions=[]) check_cohorted_topics([]) set_course_cohort_settings( course_key=self.course.id, is_cohorted=True, cohorted_discussions=["Topic_B", "Topic_C"], always_cohort_inline_discussions=False, ) check_cohorted_topics(["Topic_B", "Topic_C"]) set_course_cohort_settings( course_key=self.course.id, is_cohorted=True, cohorted_discussions=["Topic_A", "Some_Other_Topic"], always_cohort_inline_discussions=False, ) check_cohorted_topics(["Topic_A"]) # unlikely case, but make sure it works. set_course_cohort_settings( course_key=self.course.id, is_cohorted=False, cohorted_discussions=["Topic_A"], always_cohort_inline_discussions=False, ) check_cohorted_topics([])
def test_disabled_university_id_redirect(self): disabled_course = CourseFactory.create(enable_university_id=False) CourseEnrollment.get_or_create_enrollment(self.user, disabled_course.id) set_course_cohort_settings(disabled_course.id, is_cohorted=True) student_form_url = reverse('edraak_university:id', args=[unicode(disabled_course.id)]) course_root_url = reverse('course_root', args=[unicode(disabled_course.id)]) res = self.client.get(student_form_url) self.assertRedirects(res, course_root_url)
def setUp(self): super(UniversityIDFormTest, self).setUp() self.course = CourseFactory.create() set_course_cohort_settings(course_key=self.course.id, is_cohorted=True) # Initialize the default group! default_cohort = get_cohort(user=self.user, course_key=self.course.id) self.assertEquals(default_cohort.name, DEFAULT_COHORT_NAME) # Sanity-check self.cohort, _created = CourseUserGroup.create( name='Cohort_A', course_id=self.course.id, )
def test_inline_with_always_cohort_inline_discussion_flag(self): self.create_discussion("Chapter", "Discussion") set_course_cohort_settings(course_key=self.course.id, is_cohorted=True) self.assert_category_map_equals( { "entries": {}, "subcategories": { "Chapter": { "entries": {"Discussion": {"id": "discussion1", "sort_key": None, "is_cohorted": True}}, "subcategories": {}, "children": ["Discussion"], } }, "children": ["Chapter"], } )
def setUp(self): super(UniversityIDModelTest, self).setUp() self.course = CourseFactory.create( org='a', number='b', run='c', ) self.cohort = CohortFactory.create(course_id=self.course.id, ) set_course_cohort_settings(course_key=self.course.id, is_cohorted=True) self.model = UniversityIDFactory.create( user__username='******', user__email='*****@*****.**', user__profile__name='Mike Wazowski', course_key=self.course.id, university_id='201711201', ) self.profile = UserProfile.objects.get(user=self.model.user)
def test_tree(self): self.create_discussion("Chapter 1", "Discussion 1") self.create_discussion("Chapter 1", "Discussion 2") self.create_discussion("Chapter 2", "Discussion") self.create_discussion("Chapter 2 / Section 1 / Subsection 1", "Discussion") self.create_discussion("Chapter 2 / Section 1 / Subsection 2", "Discussion") self.create_discussion("Chapter 3 / Section 1", "Discussion") def check_cohorted(is_cohorted): self.assert_category_map_equals({ "entries": {}, "subcategories": { "Chapter 1": { "entries": { "Discussion 1": { "id": "discussion1", "sort_key": None, "is_cohorted": is_cohorted, }, "Discussion 2": { "id": "discussion2", "sort_key": None, "is_cohorted": is_cohorted, } }, "subcategories": {}, "children": ["Discussion 1", "Discussion 2"] }, "Chapter 2": { "entries": { "Discussion": { "id": "discussion3", "sort_key": None, "is_cohorted": is_cohorted, } }, "subcategories": { "Section 1": { "entries": {}, "subcategories": { "Subsection 1": { "entries": { "Discussion": { "id": "discussion4", "sort_key": None, "is_cohorted": is_cohorted, } }, "subcategories": {}, "children": ["Discussion"] }, "Subsection 2": { "entries": { "Discussion": { "id": "discussion5", "sort_key": None, "is_cohorted": is_cohorted, } }, "subcategories": {}, "children": ["Discussion"] } }, "children": ["Subsection 1", "Subsection 2"] } }, "children": ["Discussion", "Section 1"] }, "Chapter 3": { "entries": {}, "subcategories": { "Section 1": { "entries": { "Discussion": { "id": "discussion6", "sort_key": None, "is_cohorted": is_cohorted, } }, "subcategories": {}, "children": ["Discussion"] } }, "children": ["Section 1"] } }, "children": ["Chapter 1", "Chapter 2", "Chapter 3"] }) # empty / default config check_cohorted(False) # explicitly disabled cohorting set_course_cohort_settings(course_key=self.course.id, is_cohorted=False) check_cohorted(False) # explicitly enabled cohorting set_course_cohort_settings(course_key=self.course.id, is_cohorted=True) check_cohorted(True)
def test_tree(self): self.create_discussion("Chapter 1", "Discussion 1") self.create_discussion("Chapter 1", "Discussion 2") self.create_discussion("Chapter 2", "Discussion") self.create_discussion("Chapter 2 / Section 1 / Subsection 1", "Discussion") self.create_discussion("Chapter 2 / Section 1 / Subsection 2", "Discussion") self.create_discussion("Chapter 3 / Section 1", "Discussion") def check_cohorted(is_cohorted): self.assert_category_map_equals( { "entries": {}, "subcategories": { "Chapter 1": { "entries": { "Discussion 1": { "id": "discussion1", "sort_key": None, "is_cohorted": is_cohorted, }, "Discussion 2": { "id": "discussion2", "sort_key": None, "is_cohorted": is_cohorted, } }, "subcategories": {}, "children": ["Discussion 1", "Discussion 2"] }, "Chapter 2": { "entries": { "Discussion": { "id": "discussion3", "sort_key": None, "is_cohorted": is_cohorted, } }, "subcategories": { "Section 1": { "entries": {}, "subcategories": { "Subsection 1": { "entries": { "Discussion": { "id": "discussion4", "sort_key": None, "is_cohorted": is_cohorted, } }, "subcategories": {}, "children": ["Discussion"] }, "Subsection 2": { "entries": { "Discussion": { "id": "discussion5", "sort_key": None, "is_cohorted": is_cohorted, } }, "subcategories": {}, "children": ["Discussion"] } }, "children": ["Subsection 1", "Subsection 2"] } }, "children": ["Discussion", "Section 1"] }, "Chapter 3": { "entries": {}, "subcategories": { "Section 1": { "entries": { "Discussion": { "id": "discussion6", "sort_key": None, "is_cohorted": is_cohorted, } }, "subcategories": {}, "children": ["Discussion"] } }, "children": ["Section 1"] } }, "children": ["Chapter 1", "Chapter 2", "Chapter 3"] } ) # empty / default config check_cohorted(False) # explicitly disabled cohorting set_course_cohort_settings(course_key=self.course.id, is_cohorted=False) check_cohorted(False) # explicitly enabled cohorting set_course_cohort_settings(course_key=self.course.id, is_cohorted=True) check_cohorted(True)
def _enable_cohorting(self): set_course_cohort_settings(self.course.id, is_cohorted=True)
def _enable_cohorting(self): set_course_cohort_settings(self.course.id, is_cohorted=True)
def create_or_update_course(request): """ **Use Case** Create or edit course. **Example Requests** POST /api/extended/course/{ "org": "test_org", "number": "test_course_num", "display_name": "TEST COURSE NAME", "run": "test_course_run", "start_date": "2016-09-01", "enrollment_start": "2016-08-15", "intro_video": "jsUdxcBsym0?list=PLWdgcBEz6133fTE9ePks31tT1QBLNaxFe", "syllabus": "123", "short_description": "456", "overview": "789", "effort": "40", "language": "ru", "course_modes": [ { "mode": "honor", "title": "test" } ] } **Post Parameters** * org: Organization that owns course (slug) * number: Course slug * display_name: Course run display name for edX * run: Course run slug * start_date: Date when course starts * enrollment_start: Date when enrollment for course is opened * intro_video: Code of course introduction video on youtube (with player parameters) * syllabus: Course syllabus * short_description: Course short description * overview: Course overview * effort: Course effort (ni weeks) * language: Two-letter code of course language * course_modes: List of course modes. Course mode params: * mode: Mode type ("audit", "honor" or "verified") * price: Course mode price * currency: Currency of course mode price * title: Course mode title * description: Course mode description * upgrade_deadline: Last date when user can be enrolled/reenrolled to this mode **Response Values** * url: Course URL for CMS and LMS * course_key: The unique identifier for the course (full slug) """ global_stuff = User.objects.filter(is_staff=True).first() if global_stuff is not None: request.user = global_stuff else: raise PermissionDenied() course_key = modulestore().make_course_key(request.json["org"], request.json["number"], request.json["run"]) with modulestore().bulk_operations(course_key): course_key = modulestore().has_course(course_key) if course_key is None: response = _create_or_rerun_course(request) if response.status_code >= 400: return response course_key_string = json.loads(response.content).get("course_key") if course_key_string is not None: course_key = CourseKey.from_string(course_key_string) else: return response course_data = request.json.copy() if course_data["start_date"] is None: course_data["start_date"] = format(DEFAULT_START_DATE, "%Y-%m-%d") course_data["end_date"] = format(DEFAULT_START_DATE, "%Y-%m-%d") course_data["enrollment_end"] = format(DEFAULT_START_DATE, "%Y-%m-%d") CourseDetails.update_from_json(course_key, course_data, global_stuff) set_course_cohort_settings(course_key, is_cohorted=True) modes = request.json.get("course_modes", []) CourseMode.objects.filter(course_id=course_key).exclude( mode_slug__in=[mode["mode"] for mode in modes]).delete() for mode in modes: mode_params = {"course_id": course_key, "mode_slug": mode["mode"]} if "price" in mode: mode_params["min_price"] = mode["price"] if "currency" in mode: mode_params["currency"] = mode["currency"] if "title" in mode: mode_params["mode_display_name"] = mode["title"] if "description" in mode: mode_params["description"] = mode["description"] if "upgrade_deadline" in mode: mode_params["_expiration_datetime"] = mode["upgrade_deadline"] CourseMode.objects.update_or_create(course_id=course_key, mode_slug=mode["mode"], defaults=mode_params) return JsonResponse({ 'url': reverse_course_url('course_handler', course_key), 'course_key': unicode(course_key) })
def _enable_cohorting(self): """ Turn on cohorting in the course. """ set_course_cohort_settings(self.course.id, is_cohorted=True)
def setUp(self): super(UniversityIDViewStudentTestCase, self).setUp() set_course_cohort_settings(self.course.id, is_cohorted=True) self.cohort = CohortFactory.create(course_id=self.course.id) self.url = reverse('edraak_university:id', args=[unicode(self.course.id)])