def create_grad_templ(): templates = [ { "unit": Unit.objects.get(slug='cmpt'), "label": "offer", "content": "Congratulations, {{first_name}}, we would like to offer you admission to the {{program}} program in Computing Science at SFU.\r\n\r\nThis is good news. Really." }, { "unit": Unit.objects.get(slug='cmpt'), "label": "visa", "content": "This is to confirm that {{title}} {{first_name}} {{last_name}} is currently enrolled as a full time student in the {{program}} in the School of Computing Science at SFU." }, { "unit": Unit.objects.get(slug='cmpt'), "label": "Funding", "content": "This is to confirm that {{title}} {{first_name}} {{last_name}} is a student in the School of Computing Science's {{program}} program. {{He_She}} has been employed as follows:\r\n\r\n{% if tafunding %}Teaching assistant responsibilities include providing tutorials, office hours and marking assignments. {{title}} {{last_name}}'s assignments have been:\r\n\r\n{{ tafunding }}{% endif %}\r\n{% if rafunding %}Research assistants assist/provide research services to faculty. {{title}} {{last_name}}'s assignments have been:\r\n\r\n{{ rafunding }}{% endif %}\r\n{% if scholarships %}{{title}} {{last_name}} has received the following scholarships:\r\n\r\n{{ scholarships }}{% endif %}\r\n\r\n{{title}} {{last_name}} is making satisfactory progress." }, ] for data in templates: t = LetterTemplate(**data) t.save()
def test_grad_pages(self): """ Check overall pages for the grad module and make sure they all load """ client = Client() client.login_user('dzhao') gs = self.__make_test_grad() prog = gs.program GradRequirement(program=prog, description="Some New Requirement").save() Supervisor(student=GradStudent.objects.all()[0], supervisor=Person.objects.get(userid='ggbaker'), supervisor_type='SEN').save() lt = LetterTemplate( unit=gs.program.unit, label='Template', content="This is the\n\nletter for {{first_name}}.") lt.save() test_views(self, client, 'grad.views.', [ 'programs', 'new_program', 'requirements', 'new_requirement', 'letter_templates', 'new_letter_template', 'manage_scholarshipType', 'search', 'funding_report', 'all_promises' ], {}) test_views(self, client, 'grad.views.', ['manage_letter_template'], {'letter_template_slug': lt.slug}) test_views(self, client, 'grad.views.', ['not_found'], {}, qs='search=grad')
def create_grad_templ(): templates = [ {"unit": Unit.objects.get(slug='cmpt'), "label": "offer", "content": "Congratulations, {{first_name}}, we would like to offer you admission to the {{program}} program in Computing Science at SFU.\r\n\r\nThis is good news. Really." }, {"unit": Unit.objects.get(slug='cmpt'), "label": "visa", "content": "This is to confirm that {{title}} {{first_name}} {{last_name}} is currently enrolled as a full time student in the {{program}} in the School of Computing Science at SFU." }, {"unit": Unit.objects.get(slug='cmpt'), "label": "Funding", "content": "This is to confirm that {{title}} {{first_name}} {{last_name}} is a student in the School of Computing Science's {{program}} program. {{He_She}} has been employed as follows:\r\n\r\n{% if tafunding %}Teaching assistant responsibilities include providing tutorials, office hours and marking assignments. {{title}} {{last_name}}'s assignments have been:\r\n\r\n{{ tafunding }}{% endif %}\r\n{% if rafunding %}Research assistants assist/provide research services to faculty. {{title}} {{last_name}}'s assignments have been:\r\n\r\n{{ rafunding }}{% endif %}\r\n{% if scholarships %}{{title}} {{last_name}} has received the following scholarships:\r\n\r\n{{ scholarships }}{% endif %}\r\n\r\n{{title}} {{last_name}} is making satisfactory progress." }, ] for data in templates: t = LetterTemplate(**data) t.save()
def test_grad_pages(self): """ Check overall pages for the grad module and make sure they all load """ client = Client() test_auth(client, 'ggbaker') gs = self.__make_test_grad() prog = gs.program GradRequirement(program=prog, description="Some New Requirement").save() Supervisor(student=GradStudent.objects.all()[0], supervisor=Person.objects.get(userid='ggbaker'), supervisor_type='SEN').save() lt = LetterTemplate(unit=gs.program.unit, label='Template', content="This is the\n\nletter for {{first_name}}.") lt.save() test_views(self, client, 'grad.views.', ['programs', 'new_program', 'requirements', 'new_requirement', 'letter_templates', 'new_letter_template', 'manage_scholarshipType', 'search', 'funding_report', 'all_promises'], {}) test_views(self, client, 'grad.views.', ['manage_letter_template'], {'letter_template_slug': lt.slug}) test_views(self, client, 'grad.views.', ['not_found'], {}, qs='search=grad')
def test_grad_student_pages(self): """ Check the pages for a grad student and make sure they all load """ client = Client() client.login_user('dzhao') gs = self.__make_test_grad() lt = LetterTemplate( unit=gs.program.unit, label='Template', content="This is the\n\nletter for {{first_name}}.") lt.save() url = reverse('grad.views.get_letter_text', kwargs={ 'grad_slug': gs.slug, 'letter_template_id': lt.id }) content = client.get(url).content Letter(student=gs, template=lt, date=datetime.date.today(), content=content).save() url = reverse('grad.views.view', kwargs={'grad_slug': gs.slug}) response = basic_page_tests(self, client, url) self.assertEqual(response.status_code, 200) # sections of the main gradstudent view that can be loaded for section in all_sections: url = reverse('grad.views.view', kwargs={'grad_slug': gs.slug}) # check fragment fetch for AJAX try: response = client.get(url, {'section': section}) self.assertEqual(response.status_code, 200) except: print "with section==" + repr(section) raise # check section in page try: response = basic_page_tests( self, client, url + '?_escaped_fragment_=' + section) self.assertEqual(response.status_code, 200) except: print "with section==" + repr(section) raise # check all sections together url = url + '?_escaped_fragment_=' + ','.join(all_sections) response = basic_page_tests(self, client, url) self.assertEqual(response.status_code, 200) # check management pages for view in [ 'financials', 'manage_general', 'manage_requirements', 'manage_scholarships', 'manage_otherfunding', 'manage_promises', 'manage_letters', 'manage_status', 'manage_supervisors', 'manage_program', 'manage_start_end_semesters', 'manage_financialcomments', 'manage_defence', 'manage_progress', 'manage_documents' ]: try: url = reverse('grad.views.' + view, kwargs={'grad_slug': gs.slug}) response = basic_page_tests(self, client, url) self.assertEqual(response.status_code, 200) except: print "with view==" + repr(view) raise for style in STYLES: url = reverse('grad.views.financials', kwargs={ 'grad_slug': gs.slug, 'style': style }) response = basic_page_tests(self, client, url) self.assertEqual(response.status_code, 200) url = reverse('grad.views.new_letter', kwargs={ 'grad_slug': gs.slug, 'letter_template_slug': lt.slug }) response = basic_page_tests(self, client, url) self.assertEqual(response.status_code, 200)
def create_grad(): """ Test data for grad, ta, ra """ from grad.models import GradProgram, GradStudent, GradProgramHistory, GradStatus, ScholarshipType, Scholarship, \ OtherFunding, Promise, GradRequirement, CompletedRequirement, LetterTemplate, GradFlag, GradFlagValue, Supervisor cmpt = Unit.objects.get(slug='cmpt') ensc = Unit.objects.get(slug='ensc') mse = Unit.objects.get(slug='mse') # some admin roles d = Person.objects.get(userid='dzhao') r1 = Role(person=d, role='GRAD', unit=cmpt, expiry=role_expiry) r1.save() r2 = Role(person=Person.objects.get(userid='popowich'), role="GRPD", unit=cmpt, expiry=role_expiry) r2.save() roles = [r1, r2] # departmental data st1 = ScholarshipType(unit=cmpt, name='Scholarship-o-rama', eligible=False) st1.save() st2 = ScholarshipType(unit=cmpt, name='Generic Scholarship #8', eligible=True) st2.save() scholarship_types = [st1, st2] templates = [ { "unit": cmpt, "label": "offer", "content": u"Congratulations, {{first_name}}, we would like to offer you admission to the {{program}} program in Computing Science at SFU.\r\n\r\nThis is gööd news. Really." }, { "unit": cmpt, "label": "visa", "content": "This is to confirm that {{title}} {{first_name}} {{last_name}} is currently enrolled as a full time student in the {{program}} in the School of Computing Science at SFU." }, { "unit": cmpt, "label": "Funding", "content": "This is to confirm that {{title}} {{first_name}} {{last_name}} is a student in the School of Computing Science's {{program}} program. {{He_She}} has been employed as follows:\r\n\r\n{% if tafunding %}Teaching assistant responsibilities include providing tutorials, office hours and marking assignments. {{title}} {{last_name}}'s assignments have been:\r\n\r\n{{ tafunding }}{% endif %}\r\n{% if rafunding %}Research assistants assist/provide research services to faculty. {{title}} {{last_name}}'s assignments have been:\r\n\r\n{{ rafunding }}{% endif %}\r\n{% if scholarships %}{{title}} {{last_name}} has received the following scholarships:\r\n\r\n{{ scholarships }}{% endif %}\r\n\r\n{{title}} {{last_name}} is making satisfactory progress." }, ] for data in templates: t = LetterTemplate(**data) t.save() p = GradProgram(unit=cmpt, label='MSc Course', description='MSc Course option') p.save() p = GradProgram(unit=cmpt, label='MSc Proj', description='MSc Project option') p.save() p = GradProgram(unit=cmpt, label='MSc Thesis', description='MSc Thesis option') p.save() p = GradProgram(unit=cmpt, label='PhD', description='Doctor of Philosophy') p.save() p = GradProgram(unit=cmpt, label='Qualifying', description='Qualifying student') p.save() p = GradProgram(unit=cmpt, label='Special', description='Special Arrangements') p.save() gr = GradRequirement(program=p, description='Achieved Speciality') gr.save() for p in GradProgram.objects.filter(unit=cmpt): gr = GradRequirement(program=p, description='Found campus') gr.save() gf = GradFlag(unit=cmpt, label='Dual Degree Program') gf.save() gf = GradFlag(unit=cmpt, label='Co-op') gf.save() grads = list(Person.objects.filter(last_name='Grad')) programs = list(GradProgram.objects.all()) today = datetime.date.today() starts = Semester.objects.filter(start__gt=today - datetime.timedelta(1000), start__lt=today) supervisors = list( set([ m.person for m in Member.objects.filter( role='INST').select_related('person') ])) # create GradStudents (and associated data) in a vaguely realistic way for g in grads + random.sample(grads, 5): # put a few in two programs p = random.choice(programs) start = random.choice(starts) sstart = start.start if random.randint(1, 2) == 1: end = start.offset(random.randint(3, 9)) else: end = None gs = GradStudent(person=g, program=p, research_area=randname(8) + 'ology', campus=random.choice([x for x, _ in CAMPUS_CHOICES]), is_canadian=randnullbool()) gs.save() gph = GradProgramHistory(student=gs, program=p, start_semester=start) gph.save() if random.randint(1, 3) == 1: p2 = random.choice( [p2 for p2 in programs if p != p2 and p.unit == p2.unit]) gph = GradProgramHistory(student=gs, program=p2, start_semester=start.offset( random.randint(1, 4))) gph.save() s = GradStatus(student=gs, status='COMP', start=start, start_date=sstart - datetime.timedelta(days=100)) s.save() if random.randint(1, 4) == 1: s = GradStatus(student=gs, status='REJE', start=start, start_date=sstart - datetime.timedelta(days=80)) s.save() else: s = GradStatus(student=gs, status='OFFO', start=start, start_date=sstart - datetime.timedelta(days=80)) s.save() s = GradStatus(student=gs, status='ACTI', start=start, start_date=sstart) s.save() if end: if random.randint(1, 3): s = GradStatus(student=gs, status='WIDR', start=end, start_date=end.start) s.save() else: s = GradStatus(student=gs, status='GRAD', start=end, start_date=end.start) s.save() gs.update_status_fields() # give some money sch = Scholarship(student=gs, scholarship_type=random.choice(scholarship_types)) sch.amount = 2000 sch.start_semester = start sch.end_semester = start.offset(2) sch.save() of = OtherFunding(student=gs, semester=start.offset(3)) of.amount = 1300 of.description = "Money fell from the sky" of.save() # promise p = Promise(student=gs, start_semester=start, end_semester=start.offset(2), amount=10000) p.save() p = Promise(student=gs, start_semester=start.offset(3), end_semester=start.offset(5), amount=10000) p.save() # flags if random.randint(1, 3) == 1: cr = CompletedRequirement(requirement=gr, student=gs, semester=start.offset(1)) cr.save() if random.randint(1, 4) == 1: gfv = GradFlagValue(flag=gf, student=gs, value=True) gfv.save() # supervisors if random.randint(1, 3) != 1: p = random.choice(supervisors) s = Supervisor(student=gs, supervisor=p, supervisor_type='POT') s.save() if random.randint(1, 2) == 1: s = Supervisor(student=gs, supervisor=p, supervisor_type='SEN') s.save() s = Supervisor(student=gs, supervisor=random.choice(supervisors), supervisor_type='COM') s.save() return itertools.chain( roles, programs, scholarship_types, GradRequirement.objects.all(), LetterTemplate.objects.all(), GradFlag.objects.all(), GradStudent.objects.all(), GradProgramHistory.objects.all(), GradStatus.objects.all(), Scholarship.objects.all(), OtherFunding.objects.all(), Promise.objects.all(), CompletedRequirement.objects.all(), GradFlagValue.objects.all(), Supervisor.objects.all(), )
def test_grad_student_pages(self): """ Check the pages for a grad student and make sure they all load """ client = Client() test_auth(client, 'ggbaker') gs = self.__make_test_grad() lt = LetterTemplate(unit=gs.program.unit, label='Template', content="This is the\n\nletter for {{first_name}}.") lt.save() url = reverse('grad.views.get_letter_text', kwargs={'grad_slug': gs.slug, 'letter_template_id': lt.id}) content = client.get(url).content Letter(student=gs, template=lt, date=datetime.date.today(), content=content).save() url = reverse('grad.views.view', kwargs={'grad_slug': gs.slug}) response = basic_page_tests(self, client, url) self.assertEqual(response.status_code, 200) # sections of the main gradstudent view that can be loaded for section in all_sections: url = reverse('grad.views.view', kwargs={'grad_slug': gs.slug}) # check fragment fetch for AJAX try: response = client.get(url, {'section': section}) self.assertEqual(response.status_code, 200) except: print "with section==" + repr(section) raise # check section in page try: response = basic_page_tests(self, client, url + '?_escaped_fragment_=' + section) self.assertEqual(response.status_code, 200) except: print "with section==" + repr(section) raise # check all sections together url = url + '?_escaped_fragment_=' + ','.join(all_sections) response = basic_page_tests(self, client, url) self.assertEqual(response.status_code, 200) # check management pages for view in ['financials', 'manage_general', 'manage_requirements', 'manage_scholarships', 'manage_otherfunding', 'manage_promises', 'manage_letters', 'manage_status', 'manage_supervisors', 'manage_program', 'manage_start_end_semesters', 'manage_financialcomments', 'manage_defence', 'manage_progress', 'manage_documents']: try: url = reverse('grad.views.'+view, kwargs={'grad_slug': gs.slug}) response = basic_page_tests(self, client, url) self.assertEqual(response.status_code, 200) except: print "with view==" + repr(view) raise for style in STYLES: url = reverse('grad.views.financials', kwargs={'grad_slug': gs.slug, 'style': style}) response = basic_page_tests(self, client, url) self.assertEqual(response.status_code, 200) url = reverse('grad.views.new_letter', kwargs={'grad_slug': gs.slug, 'letter_template_slug': lt.slug}) response = basic_page_tests(self, client, url) self.assertEqual(response.status_code, 200)
def create_grad(): """ Test data for grad, ta, ra """ from grad.models import GradProgram, GradStudent, GradProgramHistory, GradStatus, ScholarshipType, Scholarship, \ OtherFunding, Promise, GradRequirement, CompletedRequirement, LetterTemplate, GradFlag, GradFlagValue, Supervisor cmpt = Unit.objects.get(slug='cmpt') ensc = Unit.objects.get(slug='ensc') mse = Unit.objects.get(slug='mse') # some admin roles d = Person.objects.get(userid='dzhao') r1 = Role(person=d, role='GRAD', unit=cmpt) r1.save() r2 = Role(person=Person.objects.get(userid='popowich'), role="GRPD", unit=cmpt) r2.save() roles = [r1, r2] # departmental data st1 = ScholarshipType(unit=cmpt, name='Scholarship-o-rama', eligible=False) st1.save() st2 = ScholarshipType(unit=cmpt, name='Generic Scholarship #8', eligible=True) st2.save() scholarship_types = [st1, st2] templates = [ {"unit": cmpt, "label": "offer", "content": "Congratulations, {{first_name}}, we would like to offer you admission to the {{program}} program in Computing Science at SFU.\r\n\r\nThis is good news. Really." }, {"unit": cmpt, "label": "visa", "content": "This is to confirm that {{title}} {{first_name}} {{last_name}} is currently enrolled as a full time student in the {{program}} in the School of Computing Science at SFU." }, {"unit": cmpt, "label": "Funding", "content": "This is to confirm that {{title}} {{first_name}} {{last_name}} is a student in the School of Computing Science's {{program}} program. {{He_She}} has been employed as follows:\r\n\r\n{% if tafunding %}Teaching assistant responsibilities include providing tutorials, office hours and marking assignments. {{title}} {{last_name}}'s assignments have been:\r\n\r\n{{ tafunding }}{% endif %}\r\n{% if rafunding %}Research assistants assist/provide research services to faculty. {{title}} {{last_name}}'s assignments have been:\r\n\r\n{{ rafunding }}{% endif %}\r\n{% if scholarships %}{{title}} {{last_name}} has received the following scholarships:\r\n\r\n{{ scholarships }}{% endif %}\r\n\r\n{{title}} {{last_name}} is making satisfactory progress." }, ] for data in templates: t = LetterTemplate(**data) t.save() p = GradProgram(unit=cmpt, label='MSc Course', description='MSc Course option') p.save() p = GradProgram(unit=cmpt, label='MSc Proj', description='MSc Project option') p.save() p = GradProgram(unit=cmpt, label='MSc Thesis', description='MSc Thesis option') p.save() p = GradProgram(unit=cmpt, label='PhD', description='Doctor of Philosophy') p.save() p = GradProgram(unit=cmpt, label='Qualifying', description='Qualifying student') p.save() p = GradProgram(unit=cmpt, label='Special', description='Special Arrangements') p.save() gr = GradRequirement(program=p, description='Achieved Speciality') gr.save() for p in GradProgram.objects.filter(unit=cmpt): gr = GradRequirement(program=p, description='Found campus') gr.save() gf = GradFlag(unit=cmpt, label='Dual Degree Program') gf.save() gf = GradFlag(unit=cmpt, label='Co-op') gf.save() grads = list(Person.objects.filter(last_name='Grad')) programs = list(GradProgram.objects.all()) today = datetime.date.today() starts = Semester.objects.filter(start__gt=today-datetime.timedelta(1000), start__lt=today) supervisors = list(set([m.person for m in Member.objects.filter(role='INST').select_related('person')])) # create GradStudents (and associated data) in a vaguely realistic way for g in grads + random.sample(grads, 5): # put a few in two programs p = random.choice(programs) start = random.choice(starts) sstart = start.start if random.randint(1,2) == 1: end = start.offset(random.randint(3,9)) else: end = None gs = GradStudent(person=g, program=p, research_area=randname(8)+'ology', campus=random.choice([x for x,_ in CAMPUS_CHOICES]), is_canadian=randnullbool()) gs.save() gph = GradProgramHistory(student=gs, program=p, start_semester=start) gph.save() if random.randint(1,3) == 1: p2 = random.choice([p2 for p2 in programs if p != p2 and p.unit == p2.unit]) gph = GradProgramHistory(student=gs, program=p2, start_semester=start.offset(random.randint(1,4))) gph.save() s = GradStatus(student=gs, status='COMP', start=start, start_date=sstart-datetime.timedelta(days=100)) s.save() if random.randint(1,4) == 1: s = GradStatus(student=gs, status='REJE', start=start, start_date=sstart-datetime.timedelta(days=80)) s.save() else: s = GradStatus(student=gs, status='OFFO', start=start, start_date=sstart-datetime.timedelta(days=80)) s.save() s = GradStatus(student=gs, status='ACTI', start=start, start_date=sstart) s.save() if end: if random.randint(1,3): s = GradStatus(student=gs, status='WIDR', start=end, start_date=end.start) s.save() else: s = GradStatus(student=gs, status='GRAD', start=end, start_date=end.start) s.save() gs.update_status_fields() # give some money sch = Scholarship(student=gs, scholarship_type=random.choice(scholarship_types)) sch.amount = 2000 sch.start_semester = start sch.end_semester = start.offset(2) sch.save() of = OtherFunding(student=gs, semester=start.offset(3)) of.amount = 1300 of.description = "Money fell from the sky" of.save() # promise p = Promise(student=gs, start_semester=start, end_semester=start.offset(2), amount=10000) p.save() p = Promise(student=gs, start_semester=start.offset(3), end_semester=start.offset(5), amount=10000) p.save() # flags if random.randint(1,3) == 1: cr = CompletedRequirement(requirement=gr, student=gs, semester=start.offset(1)) cr.save() if random.randint(1,4) == 1: gfv = GradFlagValue(flag=gf, student=gs, value=True) gfv.save() # supervisors if random.randint(1,3) != 1: p = random.choice(supervisors) s = Supervisor(student=gs, supervisor=p, supervisor_type='POT') s.save() if random.randint(1,2) == 1: s = Supervisor(student=gs, supervisor=p, supervisor_type='SEN') s.save() s = Supervisor(student=gs, supervisor=random.choice(supervisors), supervisor_type='COM') s.save() return itertools.chain( roles, programs, scholarship_types, GradRequirement.objects.all(), LetterTemplate.objects.all(), GradFlag.objects.all(), GradStudent.objects.all(), GradProgramHistory.objects.all(), GradStatus.objects.all(), Scholarship.objects.all(), OtherFunding.objects.all(), Promise.objects.all(), CompletedRequirement.objects.all(), GradFlagValue.objects.all(), Supervisor.objects.all(), )