def test_safe_key(self): def transform_function(pii_str): return 'tr(%s)' % pii_str key_name = oeditor.EditorPrefsDao.create_key_name( 321, self.location, self.key) dto = oeditor.EditorPrefsDto(key_name, {}) oeditor.EditorPrefsDao.save(dto) entity = oeditor.EditorPrefsEntity.get_by_key_name(key_name) safe_key = oeditor.EditorPrefsEntity.safe_key(entity.key(), transform_function) self.assertEqual( 'tr(321):/%s/rest/course/lesson:%s' % (self.COURSE_NAME, self.lesson.lesson_id), safe_key.name())
def test_records_indexed_by_user_id_removed(self): """Test a sampling of types whose index is or contains the user ID.""" user_id = None user = actions.login(self.STUDENT_EMAIL) actions.register(self, self.STUDENT_EMAIL, course=self.COURSE) # Get IDs of those students; make an event for each. with common_utils.Namespace(self.NAMESPACE): student = models.Student.get_by_user(user) user_id = student.user_id # Indexed by user ID suffixed with a string. p = models.StudentPropertyEntity.create(student, 'foo') p.value = 'foo' p.put() invitation.InvitationStudentProperty.load_or_default(student).put() questionnaire.StudentFormEntity.load_or_default( student, 'a_form').put() # User ID plus skill name. cm = competency.BaseCompetencyMeasure.load(user_id, 1) cm.save() # models.student_work.KeyProperty - a foreign key to Student. reviewee_key = db.Key.from_path(models.Student.kind(), user_id) reviewer_key = db.Key.from_path(models.Student.kind(), 'xyzzy') student_work.Review(contents='abcdef', reviewee_key=reviewee_key, reviewer_key=reviewer_key, unit_id='7').put() submission_key = student_work.Submission( unit_id='7', reviewee_key=reviewee_key).put() peer.ReviewSummary(submission_key=submission_key, reviewee_key=reviewee_key, unit_id='7').put() peer.ReviewStep( submission_key=submission_key, reviewee_key=reviewee_key, reviewer_key=reviewer_key, unit_id='7', state=domain.REVIEW_STATE_ASSIGNED, assigner_kind=domain.ASSIGNER_KIND_AUTO).put() key_name = oeditor.EditorPrefsDao.create_key_name( user_id, 'dasboard?action=foo', 'frammis') editor_prefs = oeditor.EditorPrefsDto(key_name, {'this': 'that'}) oeditor.EditorPrefsDao.save(editor_prefs) # Assure ourselves that we have all of the items we just added. with common_utils.Namespace(self.NAMESPACE): l = list(models.StudentPropertyEntity.all().run()) self.assertEquals(2, len(l)) # 'foo', 'linear-course-completion' l = list(invitation.InvitationStudentProperty.all().run()) self.assertEquals(1, len(l)) l = list(questionnaire.StudentFormEntity.all().run()) self.assertEquals(1, len(l)) l = list(competency.CompetencyMeasureEntity.all().run()) self.assertEquals(1, len(l)) l = list(student_work.Review.all().run()) self.assertEquals(1, len(l)) l = list(student_work.Submission.all().run()) self.assertEquals(1, len(l)) l = list(peer.ReviewSummary.all().run()) self.assertEquals(1, len(l)) l = list(peer.ReviewStep.all().run()) self.assertEquals(1, len(l)) l = list(oeditor.EditorPrefsEntity.all().run()) self.assertEquals(1, len(l)) self._unregister_and_request_data_removal(self.COURSE) self._complete_removal() # Assure ourselves that all added items are now gone. with common_utils.Namespace(self.NAMESPACE): l = list(models.StudentPropertyEntity.all().run()) self.assertEquals(0, len(l)) l = list(invitation.InvitationStudentProperty.all().run()) self.assertEquals(0, len(l)) l = list(questionnaire.StudentFormEntity.all().run()) self.assertEquals(0, len(l)) l = list(competency.CompetencyMeasureEntity.all().run()) self.assertEquals(0, len(l)) l = list(student_work.Review.all().run()) self.assertEquals(0, len(l)) l = list(student_work.Submission.all().run()) self.assertEquals(0, len(l)) l = list(peer.ReviewSummary.all().run()) self.assertEquals(0, len(l)) l = list(peer.ReviewStep.all().run()) self.assertEquals(0, len(l)) l = list(oeditor.EditorPrefsEntity.all().run()) self.assertEquals(0, len(l))