def test_programme_directors_see_all_modules_in_subject_areas(self): subject_area1 = SubjectArea.objects.create(name="Cartoon Studies") subject_area2 = SubjectArea.objects.create(name="Evil Plotting") module1 = create_module() module1.subject_areas.add(subject_area1) module2 = Module.objects.create( title="Portable Hole Techniques", code="pht23", year=1900 ) module2.subject_areas.add(subject_area1) module3 = Module.objects.create( title="Roadrunner Catching", code="rc23", year=1900 ) module3.subject_areas.add(subject_area2) self.user.staff.modules.add(module1) self.user.staff.programme_director = True self.user.staff.subject_areas.add(subject_area1) self.user.staff.save() request = self.factory.get('/') request.user = self.user response = home(request) soup = BeautifulSoup(response.content) modules = str(soup.select('#menu-module-list')) self.assertTrue(module1.get_absolute_url() in modules) self.assertTrue(module2.get_absolute_url() in modules) self.assertFalse(module3.get_absolute_url() in modules)
def test_main_admin_sees_all_modules(self): subject_area1 = SubjectArea.objects.create(name="Cartoon Studies") subject_area2 = SubjectArea.objects.create(name="Evil Plotting") module1 = create_module() module1.subject_areas.add(subject_area1) module2 = Module.objects.create( title="Portable Hole Techniques", code="pht23", year=1900 ) module2.subject_areas.add(subject_area1) module3 = Module.objects.create( title="Roadrunner Catching", code="rc23", year=1900 ) module3.subject_areas.add(subject_area2) self.user.staff.main_admin = True self.user.staff.subject_areas.add(subject_area1) self.user.staff.save() request = self.factory.get('/') request.user = self.user response = home(request) soup = BeautifulSoup(response.content) modules = str(soup.select('#menu-module-list')) self.assertTrue(module1.get_absolute_url() in modules) self.assertTrue(module2.get_absolute_url() in modules) self.assertTrue(module3.get_absolute_url() in modules)
def delete_record(request, cliente_id=None, detail_type=None, impianto_id=None, sub_impianto_id=None): data = '' d = '' data_list = '' try: if request.method == 'POST': if not users.has_deletePermission(request): return show_record(request, cliente_id=cliente_id, detail_type=detail_type, impianto_id=impianto_id, sub_impianto_id=sub_impianto_id, message_hdr=ERROR_PERM_HDR, message=ERROR_PERM_DELETE, message_type=data_render.MSG_ERROR) if detail_type is None: cli = models.Cliente.objects.get(pk=cliente_id) nome = cli.nome cognome = cli.cognome cli.delete() s = "Cliente: %s %s Rimosso correttamente." % (nome, cognome) d = { 'message_hdr': OK_DB_DELETE , 'message': s, 'message_type':data_render.MSG_OK, } return views.home(request, d) else: if detail_type == 'impianto': imp = models.Impianto.objects.get(pk=impianto_id) s = "%s" % imp imp.delete() s = "Impianto: %s rimosso correttamente." % s return show_record(request, cliente_id=cliente_id, message_hdr=OK_DB_DELETE, message=s, message_type=data_render.MSG_OK) if detail_type == 'verifica': ver = models.Verifica.objects.get(pk=sub_impianto_id) s = "%s" % ver ver.delete() s = "Verifica e Manutezione: %s rimosso correttamente." % s return show_record(request, cliente_id=cliente_id, impianto_id=impianto_id, message_hdr=OK_DB_DELETE, message=s, message_type=data_render.MSG_OK) if detail_type == 'intervento': interv = models.Intervento.objects.get(pk=sub_impianto_id) s = "%s" % interv interv.delete() s = "Verifica e Manutezione: %s rimosso correttamente." % s return show_record(request, cliente_id=cliente_id, impianto_id=impianto_id, message_hdr=OK_DB_DELETE, message=s, message_type=data_render.MSG_OK) except ObjectDoesNotExist, m: return show_record(request, cliente_id=cliente_id, detail_type=detail_type, impianto_id=impianto_id, sub_impianto_id=sub_impianto_id, message_hdr=ERROR_DB_HDR, message=ERROR_DB_DELETE, message_type=data_render.MSG_ERROR)
def test_teachers_see_only_their_own_modules(self): module1 = create_module() module2 = Module.objects.create( title="Portable Hole Techniques", code="pht23", year=1900 ) self.user.staff.modules.add(module1) request = self.factory.get('/') request.user = self.user response = home(request) soup = BeautifulSoup(response.content) modules = str(soup.select('#menu-module-list')) self.assertTrue(module1.get_absolute_url() in modules) self.assertFalse(module2.get_absolute_url() in modules)
def test_main_admin_sees_all_student_categories(self): stuff = set_up_stuff() subject_area = create_subject_area() course = Course.objects.create(title="BA in Cartoon Studies") course.subject_areas.add(subject_area) self.user.staff.subject_areas.add(subject_area) self.user.staff.main_admin = True self.user.staff.save() student1 = stuff[1] student1.course = course student1.year = 1 student1.save() student2 = stuff[2] student2.course = course student2.year = 2 student2.save() student3 = stuff[3] student3.course = course student3.year = 7 student3.save() student4 = stuff[4] student4.course = course student4.year = 9 student4.save() student5 = stuff[5] student5.year = 1 student5.active = False student5.save() request = self.factory.get('/') request.user = self.user response = home(request) soup = BeautifulSoup(response.content) student_categories = str(soup.select('#menu-student-list')) self.assertTrue('Year 1' in student_categories) self.assertTrue('<a href="/students/1/">' in student_categories) self.assertTrue('Year 2' in student_categories) self.assertTrue('<a href="/students/2/">' in student_categories) self.assertFalse('Year 3' in student_categories) self.assertFalse('<a href="/students/3/">' in student_categories) self.assertTrue('Masters' in student_categories) self.assertTrue('<a href="/students/7/">' in student_categories) self.assertTrue('Alumni' in student_categories) self.assertTrue('<a href="/students/9/">' in student_categories) self.assertTrue('Inactive Students' in student_categories) self.assertTrue('<a href="/students/inactive/">' in student_categories)
def test_my_view(self): from main.views import home request = testing.DummyRequest() data = home(request) self.assertEqual(data['project'], 'service')
def test_index_html_displays_article(self): request = HttpRequest() response = home(request) self.assertTrue(response.content.startswith(b'<!doctype html>\n<html>\n<head>')) self.assertIn(self.test_body,response.content.decode())
def test_root_loads_index_html(self): request = HttpRequest() response = home(request) self.assertTrue(response.content.startswith(b'<!doctype html>\n<html>\n<head>')) self.assertIn("Hello World",response.content.decode())