def test_notifications_handler_dismiss(self): state = CourseRerunUIStateManager.State.FAILED should_display = True rerun_course_key = CourseLocator(org='testx', course='test_course', run='test_run') # add an instructor to this course user2 = UserFactory() add_instructor(rerun_course_key, self.user, user2) # create a test notification rerun_state = CourseRerunState.objects.update_state( course_key=rerun_course_key, new_state=state, allow_not_found=True) CourseRerunState.objects.update_should_display( entry_id=rerun_state.id, user=user2, should_display=should_display) # try to get information on this notification notification_dismiss_url = reverse_course_url( 'course_notifications_handler', self.course.id, kwargs={ 'action_state_id': rerun_state.id, }) resp = self.client.delete(notification_dismiss_url) self.assertEqual(resp.status_code, 200) with self.assertRaises(CourseRerunState.DoesNotExist): # delete nofications that are dismissed CourseRerunState.objects.get(id=rerun_state.id) self.assertFalse(has_course_author_access(user2, rerun_course_key))
def _get_or_create_library(org, number, display_name, user): """ Create or retrieve given library and return its course-like key """ try: # Create library if it does not exist store = modulestore() with store.default_store(ModuleStoreEnum.Type.split): library = store.create_library( org=org, library=number, user_id=user.id, fields={"display_name": display_name}, ) add_instructor(library.location.library_key, user, user) return library.location.library_key, True except DuplicateCourseError: # Course exists, return its key return LibraryLocator(org=org, library=number), False
def _get_or_create_library(org, number, display_name, user): """ Create or retrieve given library and return its course-like key """ try: # Create library if it does not exist store = modulestore() with store.default_store(ModuleStoreEnum.Type.split): library = store.create_library( org=org, library=number, user_id=user.id, fields={ "display_name": display_name }, ) add_instructor(library.location.library_key, user, user) return library.location.library_key, True except DuplicateCourseError: # Course exists, return its key return LibraryLocator(org=org, library=number), False