def _install_masquerade(self, user, role='student'): """ Installs a masquerade for the specified user. """ user.masquerade_settings = { self.course_key: CourseMasquerade(self.course_key, role=role) }
def test_unpickling_sets_all_attributes(self): """ Make sure that old CourseMasquerade objects receive missing attributes when unpickled from the session. """ cmasq = CourseMasquerade(7) del cmasq.user_name pickled_cmasq = pickle.dumps(cmasq) unpickled_cmasq = pickle.loads(pickled_cmasq) self.assertEqual(unpickled_cmasq.user_name, None)
def test_setup_masquerade(self): masquerade_settings = { self.course.id: CourseMasquerade(course_key=self.course.id, role='student', user_name=self.student.username) } self.request.session[MASQUERADE_SETTINGS_KEY] = masquerade_settings course_masquerade, masquerade_user = setup_masquerade( self.request, self.course.id, staff_access=True) # Warning: the SafeSessions middleware relies on the `real_user` attribute to see if a # user is masquerading as another user. If the name of this attribute is changing, please update # the check in SafeSessionMiddleware._verify_user_unchanged as well. assert masquerade_user.real_user == self.staff assert masquerade_user == self.student assert self.request.user.masquerade_settings == masquerade_settings assert course_masquerade == masquerade_settings[self.course.id]