def __init__(self, data): """Initializes the dashboard. Args: data: The RequestData object """ survey_key = db.Key.from_path(ProjectSurvey.kind(), "%s/%s" % (data.program.key().name(), "midterm")) subpages = [ { "name": "edit_student_evaluation", "description": ugettext("Create or edit midterm evaluation for " "students in active program"), "title": "Create or Edit Midterm Evaluation", "link": links.SOC_LINKER.survey(survey_key, "gsoc_edit_student_evaluation"), }, { "name": "preview_student_evaluation", "description": ugettext("Preview midterm evaluation to be " "administered to the students."), "title": "Preview Midterm Evaluation", "link": links.SOC_LINKER.survey(survey_key, "gsoc_preview_student_evaluation"), }, { "name": "view_student_evaluation", "description": ugettext("View midterm evaluation for students"), "title": "View Midterm Evaluation Records", "link": links.SOC_LINKER.survey(survey_key, "gsoc_list_student_eval_records"), }, ] survey_key = db.Key.from_path(ProjectSurvey.kind(), "%s/%s" % (data.program.key().name(), "final")) subpages += [ { "name": "edit_student_evaluation", "description": ugettext("Create or edit final evaluation for " "students in active program"), "title": "Create or Edit Final Evaluation", "link": links.SOC_LINKER.survey(survey_key, "gsoc_edit_student_evaluation"), }, { "name": "preview_student_evaluation", "description": ugettext("Preview final evaluation to be " "administered to the students."), "title": "Preview Final Evaluation", "link": links.SOC_LINKER.survey(survey_key, "gsoc_preview_student_evaluation"), }, { "name": "view_student_evaluation", "description": ugettext("View final evaluation for students"), "title": "View Final Evaluation Records", "link": links.SOC_LINKER.survey(survey_key, "gsoc_list_student_eval_records"), }, ] super(StudentEvaluationsDashboard, self).__init__(data, subpages)
def testCreateEvaluationForHost(self): host = self.data.createHost() link_id = LinkIDProvider(ProjectSurvey).getValue() suffix = "%s/%s" % (self.gsoc.key().name(), link_id) # test student evaluation create/edit GET url = '/gsoc/eval/student/edit/' + suffix response = self.get(url) self.assertEvaluationCreateTemplateUsed(response) self.assertContains( response, 'Create new student evaluation') self.assertContains( response, '<input name="schema" type="hidden" id="schema" value="" />') self.assertEqual(response.context['page_name'], 'Create new student evaluation') self.assertEqual(response.context['post_url'], url) form = response.context['forms'][0] expected_fields = ['author', 'title', 'short_name', 'content', 'survey_start', 'survey_end', 'schema'].sort() actual_fields = form.fields.keys().sort() self.assertEqual(expected_fields, actual_fields) # TODO(Madhu): Get rid of scope and author fields once the data # conversion is done. override = { 'survey_content': None, 'author': host.key(), 'created_by': host.key(), 'program': self.gsoc.key(), 'modified_by': host.key(), 'schema': self.evaluation.evalSchemaString(), } response, _ = self.modelPost(url, ProjectSurvey, override) self.assertResponseRedirect(response, url+'?validated') eval = ProjectSurvey.all().get() response = self.get(url) self.assertEvaluationCreateTemplateUsed(response) self.assertContains( response, 'Edit - %s' % (eval.title,)) self.assertContains( response, '<input name="schema" type="hidden" id="schema" value=%s />' % (json.dumps(escape(eval.schema)),)) self.assertEqual(response.context['page_name'], 'Edit - %s' % (eval.title,)) self.assertEqual(response.context['post_url'], url) form = response.context['forms'][0] expected_fields = ['author', 'title', 'short_name', 'content', 'survey_start', 'survey_end', 'schema'].sort() actual_fields = form.fields.keys().sort() self.assertEqual(expected_fields, actual_fields)
def createSurveys(self): """Creates the surveys and records required for the tests. """ survey_values = { 'author': self.founder, 'title': 'Title', 'modified_by': self.founder, 'link_id': 'link_id', 'scope': self.gsoc, 'scope_path': self.gsoc.key().id_or_name()} self.project_survey = ProjectSurvey(key_name='key_name', **survey_values) self.project_survey.put() self.grading_survey = GradingProjectSurvey(key_name='key_name', **survey_values) self.grading_survey.put() record_values = { 'user': self.student.user, 'org': self.org, 'project': self.project, 'survey': self.project_survey} self.project_survey_record = GSoCProjectSurveyRecord(**record_values) self.project_survey_record.put() self.grading_survey = GradingProjectSurvey(**survey_values) self.grading_survey.put() record_values = { 'user': self.student.user, 'org': self.org, 'project': self.project, 'survey': self.grading_survey, 'grade': True} self.grading_survey_record = GSoCGradingProjectSurveyRecord( **record_values) self.grading_survey_record.put() group_values = { 'name': 'Survey Group Name', 'grading_survey': self.grading_survey, 'student_survey': self.project_survey, 'program': self.gsoc} self.survey_group = GSoCGradingSurveyGroup(**group_values) self.survey_group.put() record_values = { 'grading_survey_group': self.survey_group, 'mentor_record': self.grading_survey_record, 'student_record': self.project_survey_record, 'grade_decision': 'pass'} self.grading_record = GSoCGradingRecord(parent=self.project, **record_values) self.grading_record.put()
def createSurveys(self): """Creates the surveys and records required for the tests in the old format. """ survey_values = { 'author': self.founder, 'title': 'Title', 'modified_by': self.founder, 'link_id': 'link_id', 'scope': self.gsoc, 'scope_path': self.gsoc.key().id_or_name() } self.project_survey = ProjectSurvey(key_name='key_name', **survey_values) self.project_survey.put() self.grading_survey = GradingProjectSurvey(key_name='key_name', **survey_values) self.grading_survey.put()
def createSurveys(self): """Creates the surveys and records required for the tests in the old format. """ user = profile_utils.seedNDBUser() survey_values = { 'author': user.key.to_old_key(), 'title': 'Title', 'modified_by': user.key.to_old_key(), 'link_id': 'link_id', 'scope': self.program, 'survey_start': timeline_utils.past(), 'survey_end': timeline_utils.past(), } self.project_survey = ProjectSurvey( key_name='key_name', **survey_values) self.project_survey.put() self.grading_survey = GradingProjectSurvey( key_name='key_name', **survey_values) self.grading_survey.put()
def post(self, data, check, mutator): evaluation = self.evaluationFromForm(data) if evaluation: # TODO(nathaniel): Redirection to self? survey_key = db.Key.from_path( ProjectSurvey.kind(), '%s/%s' % ( data.program.key().name(), data.kwargs['survey'])) url = links.SOC_LINKER.survey(survey_key, 'gsoc_edit_student_evaluation') # TODO(daniel): append 'validated=True' to the URL in a more elegant way. return http.HttpResponseRedirect(url + '?validated') else: # TODO(nathaniel): problematic self-use. return self.get(data, check, mutator)
def context(self, data, check, mutator): q = GradingProjectSurvey.all() q.filter("scope", data.program) mentor_surveys = q.fetch(1000) q = ProjectSurvey.all() q.filter("scope", data.program) student_surveys = q.fetch(1000) return { "page_name": "Sending Evaluation Reminders", "mentor_surveys": mentor_surveys, "student_surveys": student_surveys, "msg": data.request.GET.get("msg", ""), }
def context(self, data, check, mutator): q = GradingProjectSurvey.all() q.filter('scope', data.program) mentor_surveys = q.fetch(1000) q = ProjectSurvey.all() q.filter('scope', data.program) student_surveys = q.fetch(1000) return { 'page_name': 'Sending Evaluation Reminders', 'mentor_surveys': mentor_surveys, 'student_surveys': student_surveys, 'msg': data.request.GET.get('msg', '') }
def context(self): q = GradingProjectSurvey.all() q.filter('scope', self.data.program) mentor_surveys = q.fetch(1000) q = ProjectSurvey.all() q.filter('scope', self.data.program) student_surveys = q.fetch(1000) return { 'page_name': 'Sending Evaluation Reminders', 'mentor_surveys': mentor_surveys, 'student_surveys': student_surveys, 'msg': self.request.GET.get('msg', '') }
def studentEvaluationFromKwargs(self, raise_not_found=True): """Sets the student evaluation in RequestData object. Args: raise_not_found: iff False do not send 404 response. """ # kwargs which defines a survey fields = ['sponsor', 'program', 'survey'] key_name = '/'.join(['gsoc_program'] + [self.data.kwargs[field] for field in fields]) self.data.student_evaluation = ProjectSurvey.get_by_key_name(key_name) if raise_not_found and not self.data.student_evaluation: raise NotFound(DEF_NO_STUDENT_EVALUATION % key_name)
def studentEvaluationFromKwargs(self, raise_not_found=True): """Sets the student evaluation in RequestData object. Args: raise_not_found: iff False do not send 404 response. """ # kwargs which defines a survey fields = ['sponsor', 'program', 'survey'] key_name = '/'.join(['gsoc_program'] + [self.data.kwargs[field] for field in fields]) self.data.student_evaluation = ProjectSurvey.get_by_key_name(key_name) if raise_not_found and not self.data.student_evaluation: raise exception.NotFound(message=DEF_NO_STUDENT_EVALUATION % key_name)
def createSurveys(self): """Creates the surveys and records required for the tests in the old format. """ survey_values = { 'author': self.founder, 'title': 'Title', 'modified_by': self.founder, 'link_id': 'link_id', 'scope': self.gsoc, 'scope_path': self.gsoc.key().id_or_name()} self.project_survey = ProjectSurvey(key_name='key_name', **survey_values) self.project_survey.put() self.grading_survey = GradingProjectSurvey(key_name='key_name', **survey_values) self.grading_survey.put()
def context(self, data, check, mutator): if data.student_evaluation: form = GSoCStudentEvaluationEditForm( data=data.POST or None, instance=data.student_evaluation) else: form = GSoCStudentEvaluationEditForm(data=data.POST or None) page_name = ugettext('Edit - %s' % (data.student_evaluation.title)) \ if data.student_evaluation else 'Create new student evaluation' survey_key = db.Key.from_path( ProjectSurvey.kind(), '%s/%s' % ( data.program.key().name(), data.kwargs['survey'])) context = { 'page_name': page_name, 'post_url': links.SOC_LINKER.survey( survey_key, 'gsoc_edit_student_evaluation'), 'forms': [form], 'error': bool(form.errors), } return context
class GradingSurveyGroupTest(MailTestCase, GSoCDjangoTestCase, TaskQueueTestCase): """Tests for accept_proposals task. """ UPDATE_RECORDS_URL = '/tasks/gsoc/grading_record/update_records' UPDATE_PROJECTS_URL = '/tasks/gsoc/grading_record/update_projects' SEND_URL = '/tasks/gsoc/grading_record/mail_result' def setUp(self): super(GradingSurveyGroupTest, self).setUp() self.init() self.createMentor() self.createStudent() self.createSurveys() def createMentor(self): """Creates a new mentor. """ profile_helper = GSoCProfileHelper(self.gsoc, self.dev_test) profile_helper.createOtherUser('*****@*****.**') self.mentor = profile_helper.createMentor(self.org) def createStudent(self): """Creates a Student with a project. """ profile_helper = GSoCProfileHelper(self.gsoc, self.dev_test) profile_helper.createOtherUser('*****@*****.**') self.student = profile_helper.createStudentWithProject( self.org, self.mentor) self.project = GSoCProject.all().ancestor(self.student).get() def createSurveys(self): """Creates the surveys and records required for the tests. """ survey_values = { 'author': self.founder, 'title': 'Title', 'modified_by': self.founder, 'link_id': 'link_id', 'scope': self.gsoc, 'scope_path': self.gsoc.key().id_or_name() } self.project_survey = ProjectSurvey(key_name='key_name', **survey_values) self.project_survey.put() self.grading_survey = GradingProjectSurvey(key_name='key_name', **survey_values) self.grading_survey.put() record_values = { 'user': self.student.user, 'org': self.org, 'project': self.project, 'survey': self.project_survey } self.project_survey_record = GSoCProjectSurveyRecord(**record_values) self.project_survey_record.put() self.grading_survey = GradingProjectSurvey(**survey_values) self.grading_survey.put() record_values = { 'user': self.student.user, 'org': self.org, 'project': self.project, 'survey': self.grading_survey, 'grade': True } self.grading_survey_record = GSoCGradingProjectSurveyRecord( **record_values) self.grading_survey_record.put() group_values = { 'name': 'Survey Group Name', 'grading_survey': self.grading_survey, 'student_survey': self.project_survey, 'program': self.gsoc } self.survey_group = GSoCGradingSurveyGroup(**group_values) self.survey_group.put() record_values = { 'grading_survey_group': self.survey_group, 'mentor_record': self.grading_survey_record, 'student_record': self.project_survey_record, 'grade_decision': 'pass' } self.grading_record = GSoCGradingRecord(parent=self.project, **record_values) self.grading_record.put() def testCreateGradingRecord(self): """Test creating a GradingRecord. """ self.grading_record.delete() post_data = {'group_key': self.survey_group.key().id_or_name()} response = self.post(self.UPDATE_RECORDS_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=1, url=self.UPDATE_RECORDS_URL) record = GSoCGradingRecord.all().get() self.assertFalse(record is None) self.assertEqual(record.grade_decision, 'pass') def testUpdateGradingRecord(self): """Test updating a GradingRecord. """ self.grading_record.grade_decision = 'undecided' self.grading_record.put() post_data = {'group_key': self.survey_group.key().id_or_name()} response = self.post(self.UPDATE_RECORDS_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=1, url=self.UPDATE_RECORDS_URL) record = GSoCGradingRecord.all().get() self.assertFalse(record is None) self.assertEqual(record.grade_decision, 'pass') def testUpdateProject(self): """Test updating a Project with a GradingRecord's result. """ post_data = { 'group_key': self.survey_group.key().id_or_name(), } response = self.post(self.UPDATE_PROJECTS_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=1, url=self.UPDATE_PROJECTS_URL) project = GSoCProject.all().get() self.assertFalse(project is None) self.assertEqual(project.passed_evaluations, [self.grading_record.key()]) self.assertEqual(1, project.parent().student_info.passed_evaluations) def testUpdateProjectWithSendMail(self): """Test updating a Project with a GradingRecord's result and sending mail. """ post_data = { 'group_key': self.survey_group.key().id_or_name(), 'send_mail': True, } response = self.post(self.UPDATE_PROJECTS_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=1, url=self.UPDATE_PROJECTS_URL) self.assertTasksInQueue(n=1, url=self.SEND_URL) project = GSoCProject.all().get() self.assertFalse(project is None) self.assertEqual(project.passed_evaluations, [self.grading_record.key()]) self.assertEqual(1, project.parent().student_info.passed_evaluations) def testSendMail(self): """Test sending mail about a GradingRecord's result. """ post_data = {'record_key': str(self.grading_record.key())} response = self.post(self.SEND_URL, post_data) self.assertEqual(response.status_code, httplib.OK) # URL explicitly added since the email task is in there self.assertTasksInQueue(n=0, url=self.SEND_URL) self.assertEmailSent(to=self.student.email)
class SurveyRemindersTest(MailTestCase, GSoCDjangoTestCase, TaskQueueTestCase): """Tests for accept_proposals task. """ SPAWN_URL = '/tasks/gsoc/surveys/send_reminder/spawn' SEND_URL = '/tasks/gsoc/surveys/send_reminder/send' def setUp(self): super(SurveyRemindersTest, self).setUp() self.init() self.createMentor() self.createStudent() self.createSurveys() def createMentor(self): """Creates a new mentor. """ profile_helper = GSoCProfileHelper(self.gsoc, self.dev_test) profile_helper.createOtherUser('*****@*****.**') self.mentor = profile_helper.createMentor(self.org) def createStudent(self): """Creates a Student with a project. """ profile_helper = GSoCProfileHelper(self.gsoc, self.dev_test) profile_helper.createOtherUser('*****@*****.**') self.student = profile_helper.createStudentWithProject( self.org, self.mentor) self.project = GSoCProject.all().ancestor(self.student).get() def createSurveys(self): """Creates the surveys and records required for the tests in the old format. """ survey_values = { 'author': self.founder, 'title': 'Title', 'modified_by': self.founder, 'link_id': 'link_id', 'scope': self.gsoc, 'scope_path': self.gsoc.key().id_or_name() } self.project_survey = ProjectSurvey(key_name='key_name', **survey_values) self.project_survey.put() self.grading_survey = GradingProjectSurvey(key_name='key_name', **survey_values) self.grading_survey.put() def testSpawnSurveyRemindersForProjectSurvey(self): """Test spawning reminder tasks for a ProjectSurvey. """ post_data = { 'program_key': self.gsoc.key().id_or_name(), 'survey_key': self.project_survey.key().id_or_name(), 'survey_type': 'project' } response = self.post(self.SPAWN_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=2) self.assertTasksInQueue(n=1, url=self.SPAWN_URL) self.assertTasksInQueue(n=1, url=self.SEND_URL) def testSpawnSurveyRemindersForGradingSurvey(self): """Test spawning reminder tasks for a GradingProjectSurvey. """ post_data = { 'program_key': self.gsoc.key().id_or_name(), 'survey_key': self.grading_survey.key().id_or_name(), 'survey_type': 'grading' } response = self.post(self.SPAWN_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=2) self.assertTasksInQueue(n=1, url=self.SPAWN_URL) self.assertTasksInQueue(n=1, url=self.SEND_URL) def testSendSurveyReminderForProjectSurvey(self): """Test sending out a reminder for a ProjectSurvey. """ post_data = { 'survey_key': self.project_survey.key().id_or_name(), 'survey_type': 'project', 'project_key': str(self.project.key()) } response = self.post(self.SEND_URL, post_data) self.assertEqual(response.status_code, httplib.OK) # URL explicitly added since the email task is in there self.assertTasksInQueue(n=0, url=self.SEND_URL) self.assertEmailSent(to=self.student.email) self.assertEmailNotSent(to=self.mentor.email) def testSendSurveyReminderForGradingSurvey(self): """Test sending out a reminder for a GradingProjectSurvey. """ post_data = { 'survey_key': self.grading_survey.key().id_or_name(), 'survey_type': 'grading', 'project_key': str(self.project.key()) } response = self.post(self.SEND_URL, post_data) self.assertEqual(response.status_code, httplib.OK) # URL explicitly added since the email task is in there self.assertTasksInQueue(n=0, url=self.SEND_URL) self.assertEmailSent(to=self.mentor.email) self.assertEmailNotSent(to=self.student.email)
def __init__(self, data): """Initializes the dashboard. Args: data: The RequestData object """ survey_key = db.Key.from_path( ProjectSurvey.kind(), '%s/%s' % (data.program.key().name(), 'midterm')) subpages = [ { 'name': 'edit_student_evaluation', 'description': ugettext('Create or edit midterm evaluation for ' 'students in active program'), 'title': 'Create or Edit Midterm Evaluation', 'link': links.SOC_LINKER.survey( survey_key, 'gsoc_edit_student_evaluation') }, { 'name': 'preview_student_evaluation', 'description': ugettext('Preview midterm evaluation to be ' 'administered to the students.'), 'title': 'Preview Midterm Evaluation', 'link': links.SOC_LINKER.survey( survey_key, 'gsoc_preview_student_evaluation') }, { 'name': 'view_student_evaluation', 'description': ugettext('View midterm evaluation for students'), 'title': 'View Midterm Evaluation Records', 'link': links.SOC_LINKER.survey( survey_key, 'gsoc_list_student_eval_records') }, ] survey_key = db.Key.from_path( ProjectSurvey.kind(), '%s/%s' % (data.program.key().name(), 'final')) subpages += [ { 'name': 'edit_student_evaluation', 'description': ugettext('Create or edit final evaluation for ' 'students in active program'), 'title': 'Create or Edit Final Evaluation', 'link': links.SOC_LINKER.survey( survey_key, 'gsoc_edit_student_evaluation') }, { 'name': 'preview_student_evaluation', 'description': ugettext('Preview final evaluation to be ' 'administered to the students.'), 'title': 'Preview Final Evaluation', 'link': links.SOC_LINKER.survey( survey_key, 'gsoc_preview_student_evaluation') }, { 'name': 'view_student_evaluation', 'description': ugettext('View final evaluation for students'), 'title': 'View Final Evaluation Records', 'link': links.SOC_LINKER.survey( survey_key, 'gsoc_list_student_eval_records') }, ] super(StudentEvaluationsDashboard, self).__init__(data, subpages)
def __init__(self, data): """Initializes the dashboard. Args: data: The RequestData object """ survey_key = db.Key.from_path( ProjectSurvey.kind(), '%s/%s' % (data.program.key().name(), 'midterm')) subpages = [ { 'name': 'edit_student_evaluation', 'description': ugettext('Create or edit midterm evaluation for ' 'students in active program'), 'title': 'Create or Edit Midterm Evaluation', 'link': links.SOC_LINKER.survey(survey_key, 'gsoc_edit_student_evaluation') }, { 'name': 'preview_student_evaluation', 'description': ugettext('Preview midterm evaluation to be ' 'administered to the students.'), 'title': 'Preview Midterm Evaluation', 'link': links.SOC_LINKER.survey(survey_key, 'gsoc_preview_student_evaluation') }, { 'name': 'view_student_evaluation', 'description': ugettext('View midterm evaluation for students'), 'title': 'View Midterm Evaluation Records', 'link': links.SOC_LINKER.survey(survey_key, 'gsoc_list_student_eval_records') }, ] survey_key = db.Key.from_path( ProjectSurvey.kind(), '%s/%s' % (data.program.key().name(), 'final')) subpages += [ { 'name': 'edit_student_evaluation', 'description': ugettext('Create or edit final evaluation for ' 'students in active program'), 'title': 'Create or Edit Final Evaluation', 'link': links.SOC_LINKER.survey(survey_key, 'gsoc_edit_student_evaluation') }, { 'name': 'preview_student_evaluation', 'description': ugettext('Preview final evaluation to be ' 'administered to the students.'), 'title': 'Preview Final Evaluation', 'link': links.SOC_LINKER.survey(survey_key, 'gsoc_preview_student_evaluation') }, { 'name': 'view_student_evaluation', 'description': ugettext('View final evaluation for students'), 'title': 'View Final Evaluation Records', 'link': links.SOC_LINKER.survey(survey_key, 'gsoc_list_student_eval_records') }, ] super(StudentEvaluationsDashboard, self).__init__(data, subpages)
class SurveyRemindersTest( test_utils.GSoCDjangoTestCase, test_utils.TaskQueueTestCase): """Tests for accept_proposals task. """ SPAWN_URL = '/tasks/gsoc/surveys/send_reminder/spawn' SEND_URL = '/tasks/gsoc/surveys/send_reminder/send' def setUp(self): super(SurveyRemindersTest, self).setUp() self.init() self.mentor = profile_utils.seedNDBProfile( self.program.key(), mentor_for=[self.org.key]) self.student = profile_utils.seedNDBStudent(self.program) self.project = project_utils.seedProject( self.student, self.program.key(), org_key=self.org.key, mentor_key=self.mentor.key) self.createSurveys() def createSurveys(self): """Creates the surveys and records required for the tests in the old format. """ user = profile_utils.seedNDBUser() survey_values = { 'author': user.key.to_old_key(), 'title': 'Title', 'modified_by': user.key.to_old_key(), 'link_id': 'link_id', 'scope': self.program, 'survey_start': timeline_utils.past(), 'survey_end': timeline_utils.past(), } self.project_survey = ProjectSurvey( key_name='key_name', **survey_values) self.project_survey.put() self.grading_survey = GradingProjectSurvey( key_name='key_name', **survey_values) self.grading_survey.put() def testSpawnSurveyRemindersForProjectSurvey(self): """Test spawning reminder tasks for a ProjectSurvey.""" post_data = { 'program_key': self.program.key().id_or_name(), 'survey_key': self.project_survey.key().id_or_name(), 'survey_type': 'project' } response = self.post(self.SPAWN_URL, post_data) self.assertResponseOK(response) self.assertTasksInQueue(n=2) self.assertTasksInQueue(n=1, url=self.SPAWN_URL) self.assertTasksInQueue(n=1, url=self.SEND_URL) def testSpawnSurveyRemindersForGradingSurvey(self): """Test spawning reminder tasks for a GradingProjectSurvey.""" post_data = { 'program_key': self.program.key().id_or_name(), 'survey_key': self.grading_survey.key().id_or_name(), 'survey_type': 'grading' } response = self.post(self.SPAWN_URL, post_data) self.assertResponseOK(response) self.assertTasksInQueue(n=2) self.assertTasksInQueue(n=1, url=self.SPAWN_URL) self.assertTasksInQueue(n=1, url=self.SEND_URL) def testSendSurveyReminderForProjectSurvey(self): """Test sending out a reminder for a ProjectSurvey.""" post_data = { 'survey_key': self.project_survey.key().id_or_name(), 'survey_type': 'project', 'project_key': str(self.project.key()) } response = self.post(self.SEND_URL, post_data) self.assertResponseOK(response) # URL explicitly added since the email task is in there self.assertTasksInQueue(n=0, url=self.SEND_URL) self.assertEmailSent(to=self.student.contact.email) # TODO(daniel): add assertEmailNotSent to DjangoTestCase #self.assertEmailNotSent(to=self.mentor.email) def testSendSurveyReminderForGradingSurvey(self): """Test sending out a reminder for a GradingProjectSurvey.""" post_data = { 'survey_key': self.grading_survey.key().id_or_name(), 'survey_type': 'grading', 'project_key': str(self.project.key()) } response = self.post(self.SEND_URL, post_data) self.assertResponseOK(response) # URL explicitly added since the email task is in there self.assertTasksInQueue(n=0, url=self.SEND_URL) self.assertEmailSent(to=self.mentor.contact.email) # TODO(daniel): add assertEmailNotSent to DjangoTestCase #self.assertEmailNotSent(to=self.student.email) def testDoesNotSpawnProjectSurveyReminderForWithdrawnProject(self): """Test withdrawn projects don't spawn reminder tasks for student evaluation. This covers all the evaluations created (midterm and final). """ # seed a withdrawn project student = profile_utils.seedNDBStudent(self.program) project_utils.seedProject( student, self.program.key(), org_key=self.org.key, status='withdrawn') post_data = { 'program_key': self.gsoc.key().id_or_name(), 'survey_key': self.project_survey.key().id_or_name(), 'survey_type': 'project' } response = self.post(self.SPAWN_URL, post_data) self.assertResponseOK(response) self.assertTasksInQueue(n=2) self.assertTasksInQueue(n=1, url=self.SPAWN_URL) # We have two projects in datastore and one is withdrawn, so we expect # to spawn the task for only one project. self.assertTasksInQueue(n=1, url=self.SEND_URL) def testDoesNotGradingProjectSurveyReminderForWithdrawnProject(self): """Test withdrawn projects don't spawn reminder tasks for mentor evaluation. This covers all the evaluations created (midterm and final). """ student = profile_utils.seedNDBStudent(self.program) project_utils.seedProject( student, self.program.key(), org_key=self.org.key, status='withdrawn') self.project.put() post_data = { 'program_key': self.gsoc.key().id_or_name(), 'survey_key': self.grading_survey.key().id_or_name(), 'survey_type': 'grading' } response = self.post(self.SPAWN_URL, post_data) self.assertResponseOK(response) self.assertTasksInQueue(n=2) self.assertTasksInQueue(n=1, url=self.SPAWN_URL) # We have two projects in datastore and one is withdrawn, so we expect # to spawn the task for only one project. self.assertTasksInQueue(n=1, url=self.SEND_URL)
def createSurveys(self): """Creates the surveys and records required for the tests. """ survey_values = { 'author': self.founder, 'title': 'Title', 'modified_by': self.founder, 'link_id': 'link_id', 'scope': self.gsoc, 'scope_path': self.gsoc.key().id_or_name() } self.project_survey = ProjectSurvey(key_name='key_name', **survey_values) self.project_survey.put() self.grading_survey = GradingProjectSurvey(key_name='key_name', **survey_values) self.grading_survey.put() record_values = { 'user': self.student.user, 'org': self.org, 'project': self.project, 'survey': self.project_survey } self.project_survey_record = GSoCProjectSurveyRecord(**record_values) self.project_survey_record.put() self.grading_survey = GradingProjectSurvey(**survey_values) self.grading_survey.put() record_values = { 'user': self.student.user, 'org': self.org, 'project': self.project, 'survey': self.grading_survey, 'grade': True } self.grading_survey_record = GSoCGradingProjectSurveyRecord( **record_values) self.grading_survey_record.put() group_values = { 'name': 'Survey Group Name', 'grading_survey': self.grading_survey, 'student_survey': self.project_survey, 'program': self.gsoc } self.survey_group = GSoCGradingSurveyGroup(**group_values) self.survey_group.put() record_values = { 'grading_survey_group': self.survey_group, 'mentor_record': self.grading_survey_record, 'student_record': self.project_survey_record, 'grade_decision': 'pass' } self.grading_record = GSoCGradingRecord(parent=self.project, **record_values) self.grading_record.put()
class SurveyRemindersTest(MailTestCase, GSoCDjangoTestCase, TaskQueueTestCase): """Tests for accept_proposals task. """ SPAWN_URL = '/tasks/gsoc/surveys/send_reminder/spawn' SEND_URL = '/tasks/gsoc/surveys/send_reminder/send' def setUp(self): super(SurveyRemindersTest, self).setUp() self.init() self.createMentor() self.createStudent() self.createSurveys() def createMentor(self): """Creates a new mentor. """ profile_helper = GSoCProfileHelper(self.gsoc, self.dev_test) profile_helper.createOtherUser('*****@*****.**') self.mentor = profile_helper.createMentor(self.org) def createStudent(self): """Creates a Student with a project. """ profile_helper = GSoCProfileHelper(self.gsoc, self.dev_test) profile_helper.createOtherUser('*****@*****.**') self.student = profile_helper.createStudentWithProject(self.org, self.mentor) self.project = GSoCProject.all().ancestor(self.student).get() def createSurveys(self): """Creates the surveys and records required for the tests in the old format. """ survey_values = { 'author': self.founder, 'title': 'Title', 'modified_by': self.founder, 'link_id': 'link_id', 'scope': self.gsoc, 'scope_path': self.gsoc.key().id_or_name()} self.project_survey = ProjectSurvey(key_name='key_name', **survey_values) self.project_survey.put() self.grading_survey = GradingProjectSurvey(key_name='key_name', **survey_values) self.grading_survey.put() def testSpawnSurveyRemindersForProjectSurvey(self): """Test spawning reminder tasks for a ProjectSurvey. """ post_data = { 'program_key': self.gsoc.key().id_or_name(), 'survey_key': self.project_survey.key().id_or_name(), 'survey_type': 'project'} response = self.post(self.SPAWN_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=2) self.assertTasksInQueue(n=1, url=self.SPAWN_URL) self.assertTasksInQueue(n=1, url=self.SEND_URL) def testSpawnSurveyRemindersForGradingSurvey(self): """Test spawning reminder tasks for a GradingProjectSurvey. """ post_data = { 'program_key': self.gsoc.key().id_or_name(), 'survey_key': self.grading_survey.key().id_or_name(), 'survey_type': 'grading'} response = self.post(self.SPAWN_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=2) self.assertTasksInQueue(n=1, url=self.SPAWN_URL) self.assertTasksInQueue(n=1, url=self.SEND_URL) def testSendSurveyReminderForProjectSurvey(self): """Test sending out a reminder for a ProjectSurvey. """ post_data = { 'survey_key': self.project_survey.key().id_or_name(), 'survey_type': 'project', 'project_key': str(self.project.key())} response = self.post(self.SEND_URL, post_data) self.assertEqual(response.status_code, httplib.OK) # URL explicitly added since the email task is in there self.assertTasksInQueue(n=0, url=self.SEND_URL) self.assertEmailSent(to=self.student.email) self.assertEmailNotSent(to=self.mentor.email) def testSendSurveyReminderForGradingSurvey(self): """Test sending out a reminder for a GradingProjectSurvey. """ post_data = { 'survey_key': self.grading_survey.key().id_or_name(), 'survey_type': 'grading', 'project_key': str(self.project.key())} response = self.post(self.SEND_URL, post_data) self.assertEqual(response.status_code, httplib.OK) # URL explicitly added since the email task is in there self.assertTasksInQueue(n=0, url=self.SEND_URL) self.assertEmailSent(to=self.mentor.email) self.assertEmailNotSent(to=self.student.email)
class GradingSurveyGroupTest(MailTestCase, GSoCDjangoTestCase, TaskQueueTestCase): """Tests for accept_proposals task. """ UPDATE_RECORDS_URL = '/tasks/gsoc/grading_record/update_records' UPDATE_PROJECTS_URL = '/tasks/gsoc/grading_record/update_projects' SEND_URL = '/tasks/gsoc/grading_record/mail_result' def setUp(self): super(GradingSurveyGroupTest, self).setUp() self.init() self.createMentor() self.createStudent() self.createSurveys() def createMentor(self): """Creates a new mentor. """ profile_helper = GSoCProfileHelper(self.gsoc, self.dev_test) profile_helper.createOtherUser('*****@*****.**') self.mentor = profile_helper.createMentor(self.org) def createStudent(self): """Creates a Student with a project. """ profile_helper = GSoCProfileHelper(self.gsoc, self.dev_test) profile_helper.createOtherUser('*****@*****.**') self.student = profile_helper.createStudentWithProject(self.org, self.mentor) self.project = GSoCProject.all().ancestor(self.student).get() def createSurveys(self): """Creates the surveys and records required for the tests. """ survey_values = { 'author': self.founder, 'title': 'Title', 'modified_by': self.founder, 'link_id': 'link_id', 'scope': self.gsoc, 'scope_path': self.gsoc.key().id_or_name()} self.project_survey = ProjectSurvey(key_name='key_name', **survey_values) self.project_survey.put() self.grading_survey = GradingProjectSurvey(key_name='key_name', **survey_values) self.grading_survey.put() record_values = { 'user': self.student.user, 'org': self.org, 'project': self.project, 'survey': self.project_survey} self.project_survey_record = GSoCProjectSurveyRecord(**record_values) self.project_survey_record.put() self.grading_survey = GradingProjectSurvey(**survey_values) self.grading_survey.put() record_values = { 'user': self.student.user, 'org': self.org, 'project': self.project, 'survey': self.grading_survey, 'grade': True} self.grading_survey_record = GSoCGradingProjectSurveyRecord( **record_values) self.grading_survey_record.put() group_values = { 'name': 'Survey Group Name', 'grading_survey': self.grading_survey, 'student_survey': self.project_survey, 'program': self.gsoc} self.survey_group = GSoCGradingSurveyGroup(**group_values) self.survey_group.put() record_values = { 'grading_survey_group': self.survey_group, 'mentor_record': self.grading_survey_record, 'student_record': self.project_survey_record, 'grade_decision': 'pass'} self.grading_record = GSoCGradingRecord(parent=self.project, **record_values) self.grading_record.put() def testCreateGradingRecord(self): """Test creating a GradingRecord. """ self.grading_record.delete() post_data = { 'group_key': self.survey_group.key().id_or_name() } response = self.post(self.UPDATE_RECORDS_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=1, url=self.UPDATE_RECORDS_URL) record = GSoCGradingRecord.all().get() self.assertFalse(record is None) self.assertEqual(record.grade_decision, 'pass') def testUpdateGradingRecord(self): """Test updating a GradingRecord. """ self.grading_record.grade_decision = 'undecided' self.grading_record.put() post_data = { 'group_key': self.survey_group.key().id_or_name() } response = self.post(self.UPDATE_RECORDS_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=1, url=self.UPDATE_RECORDS_URL) record = GSoCGradingRecord.all().get() self.assertFalse(record is None) self.assertEqual(record.grade_decision, 'pass') def testUpdateProject(self): """Test updating a Project with a GradingRecord's result. """ post_data = { 'group_key': self.survey_group.key().id_or_name(), } response = self.post(self.UPDATE_PROJECTS_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=1, url=self.UPDATE_PROJECTS_URL) project = GSoCProject.all().get() self.assertFalse(project is None) self.assertEqual(project.passed_evaluations, [self.grading_record.key()]) self.assertEqual(1, project.parent().student_info.passed_evaluations) def testUpdateProjectWithSendMail(self): """Test updating a Project with a GradingRecord's result and sending mail. """ post_data = { 'group_key': self.survey_group.key().id_or_name(), 'send_mail': True, } response = self.post(self.UPDATE_PROJECTS_URL, post_data) self.assertEqual(response.status_code, httplib.OK) self.assertTasksInQueue(n=1, url=self.UPDATE_PROJECTS_URL) self.assertTasksInQueue(n=1, url=self.SEND_URL) project = GSoCProject.all().get() self.assertFalse(project is None) self.assertEqual(project.passed_evaluations, [self.grading_record.key()]) self.assertEqual(1, project.parent().student_info.passed_evaluations) def testSendMail(self): """Test sending mail about a GradingRecord's result. """ post_data = { 'record_key': str(self.grading_record.key()) } response = self.post(self.SEND_URL, post_data) self.assertEqual(response.status_code, httplib.OK) # URL explicitly added since the email task is in there self.assertTasksInQueue(n=0, url=self.SEND_URL) self.assertEmailSent(to=self.student.email)