def _do_test_beta_period(self): """Actually test beta periods, relying on settings to be right.""" # trust, but verify :) self.assertFalse(settings.MITX_FEATURES['DISABLE_START_DATES']) # Make courses start in the future tomorrow = time.time() + 24 * 3600 # nextday = tomorrow + 24 * 3600 # yesterday = time.time() - 24 * 3600 # toy course's hasn't started self.toy.lms.start = time.gmtime(tomorrow) self.assertFalse(self.toy.has_started()) # but should be accessible for beta testers self.toy.lms.days_early_for_beta = 2 # student user shouldn't see it student_user = get_user(self.student) self.assertFalse(has_access(student_user, self.toy, 'load')) # now add the student to the beta test group group_name = course_beta_test_group_name(self.toy.location) group = Group.objects.create(name=group_name) group.user_set.add(student_user) # now the student should see it self.assertTrue(has_access(student_user, self.toy, 'load'))
def test_beta_period(self): """ Check that beta-test access works. """ student_email, student_password = self.ACCOUNT_INFO[0] instructor_email, instructor_password = self.ACCOUNT_INFO[1] # Make courses start in the future now = datetime.datetime.now(pytz.UTC) tomorrow = now + datetime.timedelta(days=1) course_data = {'start': tomorrow} # self.course's hasn't started self.course = self.update_course(self.course, course_data) self.assertFalse(self.course.has_started()) # but should be accessible for beta testers self.course.lms.days_early_for_beta = 2 # student user shouldn't see it student_user = User.objects.get(email=student_email) self.assertFalse(has_access(student_user, self.course, 'load')) # now add the student to the beta test group group_name = course_beta_test_group_name(self.course.location) group = Group.objects.create(name=group_name) group.user_set.add(student_user) # now the student should see it self.assertTrue(has_access(student_user, self.course, 'load'))
def _do_test_beta_period(self): """Actually test beta periods, relying on settings to be right.""" # trust, but verify :) self.assertFalse(settings.MITX_FEATURES['DISABLE_START_DATES']) # Make courses start in the future tomorrow = datetime.datetime.now(UTC()) + datetime.timedelta(days=1) # toy course's hasn't started self.toy.lms.start = tomorrow self.assertFalse(self.toy.has_started()) # but should be accessible for beta testers self.toy.lms.days_early_for_beta = 2 # student user shouldn't see it student_user = get_user(self.student) self.assertFalse(has_access(student_user, self.toy, 'load')) # now add the student to the beta test group group_name = course_beta_test_group_name(self.toy.location) group = Group.objects.create(name=group_name) group.user_set.add(student_user) # now the student should see it self.assertTrue(has_access(student_user, self.toy, 'load'))
def list_with_level(course, level): """ List users who have 'level' access. `level` is in ['instructor', 'staff', 'beta'] for standard courses. There could be other levels specific to the course. If there is no Group for that course-level, returns an empty list """ if level == 'beta': grpname = course_beta_test_group_name(course.location) else: grpname = get_access_group_name(course, level) try: return Group.objects.get(name=grpname).user_set.all() except Group.DoesNotExist: log.info("list_with_level called with non-existant group named {}".format(grpname)) return []
def list_with_level(course, level): """ List users who have 'level' access. `level` is in ['instructor', 'staff', 'beta'] for standard courses. There could be other levels specific to the course. If there is no Group for that course-level, returns an empty list """ if level == 'beta': grpname = course_beta_test_group_name(course.location) else: grpname = get_access_group_name(course, level) try: return Group.objects.get(name=grpname).user_set.all() except Group.DoesNotExist: log.info( "list_with_level called with non-existant group named {}".format( grpname)) return []
def _change_access(course, user, level, action): """ Change access of user. `level` is one of ['instructor', 'staff', 'beta'] action is one of ['allow', 'revoke'] NOTE: will create a group if it does not yet exist. """ if level == 'beta': grpname = course_beta_test_group_name(course.location) elif level in ['instructor', 'staff']: grpname = get_access_group_name(course, level) else: raise ValueError("unrecognized level '{}'".format(level)) group, _ = Group.objects.get_or_create(name=grpname) if action == 'allow': user.groups.add(group) elif action == 'revoke': user.groups.remove(group) else: raise ValueError("unrecognized action '{}'".format(action))