def offer_edit(request, idOffer): offer = Offer.pickById(idOffer) if request.method == 'POST': form = OfferForm(request.POST) form.updateForm() if form.is_valid(): idProfessor = form.cleaned_data['dropDownProfessor'] classNumber = form.cleaned_data['classNumber'] practical = form.cleaned_data['dropDownTeoricaPratica'] numberOfRegistrations = form.cleaned_data['numberOfRegistrations'] schedulesIds = form.cleaned_data['listSchedules'] schedules = [ Schedule.pickById(int(schedule)) for schedule in schedulesIds ] schedules_string_old = '[ ' schedules_string = '[ ' for schedule in offer.schedules: schedules_string_old += str(schedule).replace('ç', 'c') + " " for schedule in schedules: schedules_string += str(schedule).replace('ç', 'c') + " " schedules_string_old += ']' schedules_string += ']' user = request.user user_name = request.user.username time = get_time() action = u"Usuário " + user_name + u" editou o oferecimento id: " + str(offer.idOffer) + " {" \ + u" Código do Curso: " + str(offer.course.courseCode) \ + u"; Periodo: " + str(offer.timePeriod) \ + u"; Turma: T" + str(offer.classNumber) + " => T" + str(classNumber) \ + u"; Professor: " + offer.professor.name + " => " + Professor.pickById(idProfessor).name \ + u"; Horários: " + schedules_string_old + " => " + schedules_string + " }" offer_edit_log = Log(user=user, action=action, time=time) offer_edit_log.save() offer.setProfessor(Professor.pickById(idProfessor)) offer.classNumber = classNumber offer.practical = practical numberOfRegistrations = None if not numberOfRegistrations else numberOfRegistrations offer.setNumberOfRegistrations(numberOfRegistrations) offer.setSchedules(schedules) offer.store() return HttpResponseRedirect('/interface/offer/' + str(idOffer)) else: form = OfferForm( initial={ 'dropDownProfessor': offer.professor.idProfessor, 'classNumber': offer.classNumber, 'dropDownTeoricaPratica': offer.practical, 'numberOfRegistrations': offer.numberOfRegistrations }) form.updateForm() form.fields['listSchedules'].initial = [ schedule.idSchedule for schedule in offer.schedules ] rendered_page = render(request, 'offer_edit.html', { 'offer': offer, 'form': form }) return rendered_page
def create_professor_and_schedule(self): cursor = MySQLConnection() cursor.execute('INSERT INTO `minitableDayOfTheWeek` (dayOfTheWeek) VALUES ("Domingo"), ("Segunda"), ("Terça"), ("Quarta"), ("Quinta"), ("Sexta"), ("Sabado")') self.schedule = Schedule('Domingo', '14:00:00', 'weekly', '12:00:00') self.schedule.store() self.schedule = Schedule('Segunda', '19:00:00', 'weekly', '16:00:00') self.schedule.store() self.schedule = Schedule('Quarta', '16:00:00', 'weekly', '14:00:00') self.schedule.store() self.professor = Professor('Professor Teste') self.professor.store() self.second_professor = Professor('Professor Teste2') self.second_professor.store()
def checkprofessor(self, professorname): """Checks if the professor with the name passed as argument is already in the bank and, if it isn't, stores a new professor. After that, returns the Professor object. If the professor name is empty, there is a special entry in the bank for this case """ professor = Professor.find(name_equal=professorname) if not professor: if not professorname: professor = Professor.find(name_equal=NO_PROFESSOR_STRING)[0] else: professor = Professor(professorname) professor.store() else: professor = professor[0] return professor
def create_professor_and_schedule(self): cursor = MySQLConnection() cursor.execute( 'INSERT INTO `minitableDayOfTheWeek` (dayOfTheWeek) VALUES ("Domingo"), ("Segunda"), ("Terça"), ("Quarta"), ("Quinta"), ("Sexta"), ("Sabado")' ) self.schedule = Schedule('Domingo', '14:00:00', 'weekly', '12:00:00') self.schedule.store() self.schedule = Schedule('Segunda', '19:00:00', 'weekly', '16:00:00') self.schedule.store() self.schedule = Schedule('Quarta', '16:00:00', 'weekly', '14:00:00') self.schedule.store() self.professor = Professor('Professor Teste') self.professor.store() self.second_professor = Professor('Professor Teste2') self.second_professor.store()
def test_delete_professor(self): professor = Professor(self.name_professor) professor.store() open_page(self.browser, '/interface/professor', self.live_server_url) professor_name_link = self.browser.find_element_by_link_text(self.name_professor) professor_name_link.click() self.assertIn('Interface - Professor Detail', self.browser.title) button_delete = self.browser.find_element_by_name('deletar') button_delete.click() alert = self.browser.switch_to.alert alert.accept() self.assertIn('Interface - Professor', self.browser.title) professor_name_after_delete = self.browser.find_elements_by_tag_name('a') names = [link.text for link in professor_name_after_delete] self.assertNotIn(self.name_professor, names)
def offer_edit(request, idOffer): offer = Offer.pickById(idOffer) if request.method == 'POST': form = OfferForm(request.POST) form.updateForm() if form.is_valid(): idProfessor = form.cleaned_data['dropDownProfessor'] classNumber = form.cleaned_data['classNumber'] practical = form.cleaned_data['dropDownTeoricaPratica'] numberOfRegistrations = form.cleaned_data['numberOfRegistrations'] schedulesIds = form.cleaned_data['listSchedules'] schedules = [Schedule.pickById(int(schedule)) for schedule in schedulesIds] schedules_string_old = '[ ' schedules_string = '[ ' for schedule in offer.schedules: schedules_string_old += str(schedule).replace('ç','c') + " " for schedule in schedules: schedules_string += str(schedule).replace('ç','c') + " " schedules_string_old += ']' schedules_string += ']' user= request.user user_name = request.user.username time = get_time() action = u"Usuário " + user_name + u" editou o oferecimento id: " + str(offer.idOffer) + " {" \ + u" Código do Curso: " + str(offer.course.courseCode) \ + u"; Periodo: " + str(offer.timePeriod) \ + u"; Turma: T" + str(offer.classNumber) + " => T" + str(classNumber) \ + u"; Professor: " + offer.professor.name + " => " + Professor.pickById(idProfessor).name \ + u"; Horários: " + schedules_string_old + " => " + schedules_string + " }" offer_edit_log = Log(user=user, action=action, time=time) offer_edit_log.save() offer.setProfessor(Professor.pickById(idProfessor)) offer.classNumber = classNumber offer.practical = practical numberOfRegistrations = None if not numberOfRegistrations else numberOfRegistrations offer.setNumberOfRegistrations(numberOfRegistrations) offer.setSchedules(schedules) offer.store() return HttpResponseRedirect('/interface/offer/' + str(idOffer)) else: form = OfferForm(initial={'dropDownProfessor': offer.professor.idProfessor, 'classNumber': offer.classNumber, 'dropDownTeoricaPratica': offer.practical, 'numberOfRegistrations': offer.numberOfRegistrations}) form.updateForm() form.fields['listSchedules'].initial = [schedule.idSchedule for schedule in offer.schedules] rendered_page = render(request, 'offer_edit.html', {'offer': offer, 'form': form}) return rendered_page
def professor_edit(request, idProfessor): professor = Professor.pickById(idProfessor) if request.method == 'POST': form = ProfessorForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] memberId = form.cleaned_data['memberId'] office = form.cleaned_data['office'] email = form.cleaned_data['email'] phoneNumber = form.cleaned_data['phoneNumber'] cellphoneNumber = form.cleaned_data['cellphoneNumber'] idDepartment = form.cleaned_data['idDepartment'] professor_name_old = professor.name professor_memberId_old = professor.memberId professor_office_old = professor.office professor_email_old = professor.email professor_phoneNumber_old = professor.phoneNumber professor_cellphoneNumber_old = professor.cellphoneNumber professor_idDepartment_old = professor.idDepartment professor.name = name professor.memberId = memberId office = None if not office else office email = None if not email else email professor.office = office professor.email = email professor.phoneNumber = phoneNumber professor.cellphoneNumber = cellphoneNumber professor.idDepartment = idDepartment user = request.user user_name = request.user.username time = get_time() action = u"Usuário " + user_name + u" alterou as informações do professor " + professor_name_old \ + u" { name: " + professor_name_old + " => " + professor.name \ + u"; memberId: " + str(professor_memberId_old) + " => " + str(professor.memberId) \ + u"; office: " + str(professor_office_old) + " => " + str(professor.office) \ + u"; email: " + str(professor_email_old) + " => " + str(professor.email) \ + u"; phoneNumber: " + str(professor_phoneNumber_old) + " => " + str(professor.phoneNumber) \ + u"; cellphoneNumber: " + str(professor_cellphoneNumber_old) + " => " + str(professor.cellphoneNumber) \ + u"; idDepartment: " + str(professor_idDepartment_old) + " => " + str(professor.idDepartment) + " }" professor_edit_log = Log(user=user, action=action, time=time) professor_edit_log.save() professor.store() return HttpResponseRedirect('/interface/professor/' + str(idProfessor)) else: form = ProfessorForm( initial={ 'name': professor.name, 'idDepartment': professor.idDepartment, 'memberId': professor.memberId, 'office': professor.office, 'email': professor.email, 'phoneNumber': professor.phoneNumber, 'cellphoneNumber': professor.cellphoneNumber }) rendered_page = render(request, 'professor_edit.html', { 'professor': professor, 'form': form }) return rendered_page
def test_delete_professor(self): professor = Professor(self.name_professor) professor.store() open_page(self.browser, '/interface/professor', self.live_server_url) professor_name_link = self.browser.find_element_by_link_text( self.name_professor) professor_name_link.click() self.assertIn('Interface - Professor Detail', self.browser.title) button_delete = self.browser.find_element_by_name('deletar') button_delete.click() alert = self.browser.switch_to.alert alert.accept() self.assertIn('Interface - Professor', self.browser.title) professor_name_after_delete = self.browser.find_elements_by_tag_name( 'a') names = [link.text for link in professor_name_after_delete] self.assertNotIn(self.name_professor, names)
def tearDown(self): cursor = MySQLConnection() [offer.delete() for offer in Offer.find()] [schedule.delete() for schedule in Schedule.find()] cursor.execute('DELETE FROM minitableDayOfTheWeek') [timePeriod.delete() for timePeriod in TimePeriod.find()] [course.delete() for course in Course.find()] [professor.delete() for professor in Professor.find()] self.browser.quit()
def professor_delete(request, idProfessor): professor = Professor.pickById(idProfessor) user = request.user user_name = request.user.username time = get_time() action = u"Usuário " + user_name + u" deletou o professor " + professor.name professor_delete_log = Log(user=user, action=action, time=time) professor_delete_log.save() professor.delete() return HttpResponseRedirect('/interface/professor/')
def professor_delete(request, idProfessor): professor = Professor.pickById(idProfessor) user= request.user user_name = request.user.username time = get_time() action = u"Usuário " + user_name + u" deletou o professor " + professor.name professor_delete_log = Log(user=user, action=action, time=time) professor_delete_log.save() professor.delete() return HttpResponseRedirect('/interface/professor/')
def professor_edit(request, idProfessor): professor = Professor.pickById(idProfessor) if request.method == 'POST': form = ProfessorForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] memberId = form.cleaned_data['memberId'] office = form.cleaned_data['office'] email = form.cleaned_data['email'] phoneNumber = form.cleaned_data['phoneNumber'] cellphoneNumber = form.cleaned_data['cellphoneNumber'] idDepartment = form.cleaned_data['idDepartment'] professor_name_old = professor.name professor_memberId_old = professor.memberId professor_office_old = professor.office professor_email_old = professor.email professor_phoneNumber_old = professor.phoneNumber professor_cellphoneNumber_old = professor.cellphoneNumber professor_idDepartment_old = professor.idDepartment professor.name = name professor.memberId = memberId office = None if not office else office email = None if not email else email professor.office = office professor.email = email professor.phoneNumber = phoneNumber professor.cellphoneNumber = cellphoneNumber professor.idDepartment = idDepartment user= request.user user_name = request.user.username time = get_time() action = u"Usuário " + user_name + u" alterou as informações do professor " + professor_name_old \ + u" { name: " + professor_name_old + " => " + professor.name \ + u"; memberId: " + str(professor_memberId_old) + " => " + str(professor.memberId) \ + u"; office: " + str(professor_office_old) + " => " + str(professor.office) \ + u"; email: " + str(professor_email_old) + " => " + str(professor.email) \ + u"; phoneNumber: " + str(professor_phoneNumber_old) + " => " + str(professor.phoneNumber) \ + u"; cellphoneNumber: " + str(professor_cellphoneNumber_old) + " => " + str(professor.cellphoneNumber) \ + u"; idDepartment: " + str(professor_idDepartment_old) + " => " + str(professor.idDepartment) + " }" professor_edit_log = Log(user=user, action=action, time=time) professor_edit_log.save() professor.store() return HttpResponseRedirect('/interface/professor/' + str(idProfessor)) else: form = ProfessorForm(initial={'name': professor.name, 'idDepartment': professor.idDepartment, 'memberId': professor.memberId, 'office': professor.office, 'email': professor.email, 'phoneNumber': professor.phoneNumber, 'cellphoneNumber': professor.cellphoneNumber}) rendered_page = render(request, 'professor_edit.html', {'professor': professor, 'form': form}) return rendered_page
def test_edit_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_edit = self.browser.find_element_by_name('editar') button_edit.click() self.assertIn('Interface - Offer Edit', self.browser.title) dropdown_professor = self.browser.find_element_by_id( 'id_dropDownProfessor') select_professor = Select(dropdown_professor) select_professor.select_by_value(str( self.second_professor.idProfessor)) input_classNumber = self.browser.find_element_by_id('id_classNumber') input_classNumber.send_keys('1') dropdown_practical = self.browser.find_element_by_id( 'id_dropDownTeoricaPratica') select_practical = Select(dropdown_practical) select_practical.select_by_value('1') input_numberOfRegistrations = self.browser.find_element_by_id( 'id_numberOfRegistrations') input_numberOfRegistrations.send_keys('1') self.browser.find_element_by_id("id_listSchedules_1").click() self.browser.find_element_by_id("id_listSchedules_2").click() button_apply = self.browser.find_element_by_name('Aplicar') button_apply.click() self.assertIn('Interface - Offer Detail', self.browser.title) id_courseCode = self.browser.find_element_by_id('courseCode') self.assertEqual(id_courseCode.text, 'tst9999') id_name = self.browser.find_element_by_id('name') self.assertEqual(id_name.text, 'teste9999') id_professor_name = self.browser.find_element_by_id('professor_name') self.assertEqual(id_professor_name.text, 'Professor Teste2') id_timePeriod = self.browser.find_element_by_id('timePeriod') self.assertEqual(id_timePeriod.text, 'Primeiro semestre de 2014') id_classNumber = self.browser.find_element_by_id('classNumber') self.assertEqual(id_classNumber.text, 'T101') id_practical = self.browser.find_element_by_id('practical') self.assertEqual(id_practical.text, "PRATICA") id_numberOfRegistrations = self.browser.find_element_by_id( 'numberOfRegistrations') self.assertEqual(id_numberOfRegistrations.text, '101') id_schedules = self.browser.find_element_by_id('schedules') self.assertIn("Domingo 12:00 - 14:00", id_schedules.text) self.assertNotIn("Segunda 16:00 - 19:00", id_schedules.text) self.assertNotIn("Quarta 14:00 - 16:00", id_schedules.text)
def updateForm(self): professors = Professor.find() professorName = [professor.name for professor in professors] professorIds = [professor.idProfessor for professor in professors] professorInfo = zip(professorIds, professorName) professorInfo = sorted(professorInfo, key=getKey) schedules = Schedule.find() scheduleName = schedules scheduleIds = [schedule.idSchedule for schedule in schedules] scheduleInfo = zip(scheduleIds, scheduleName) self.fields['dropDownProfessor'] = forms.ChoiceField(widget=forms.Select, choices=professorInfo, label = "Professor") self.fields['listSchedules'] = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=scheduleInfo, label = 'Horários')
def test_edit_professor(self): professor = Professor(self.name_professor) professor.store() open_page(self.browser, '/interface/professor', self.live_server_url) professor_name_link = self.browser.find_element_by_link_text( self.name_professor) professor_name_link.click() self.assertIn('Interface - Professor Detail', self.browser.title) button_edit = self.browser.find_element_by_name('editar') button_edit.click() self.assertIn('Interface - Professor Edit', self.browser.title) form_name = self.browser.find_element_by_id('id_name') form_name.send_keys('Edit') form_memberId = self.browser.find_element_by_id('id_memberId') form_memberId.send_keys('') form_office = self.browser.find_element_by_id('id_office') form_office.send_keys('') form_email = self.browser.find_element_by_id('id_email') form_email.send_keys('') form_phoneNumber = self.browser.find_element_by_id('id_phoneNumber') form_phoneNumber.send_keys('0') form_cellphoneNumber = self.browser.find_element_by_id( 'id_cellphoneNumber') form_cellphoneNumber.send_keys('0') form_idDepartment = self.browser.find_element_by_id('id_idDepartment') form_idDepartment.send_keys('') button_apply = self.browser.find_element_by_name('Aplicar') button_apply.click() open_page(self.browser, '/interface/professor', self.live_server_url) professor_name_link_after_edit = self.browser.find_element_by_link_text( self.name_professor + 'Edit') professor_name_link_after_edit.click() list_professor_info = self.browser.find_elements_by_tag_name('p') self.assertEqual(list_professor_info[1].text, 'Member ID: 0') self.assertEqual(list_professor_info[2].text, 'Office: None') self.assertEqual(list_professor_info[3].text, 'Email: None') self.assertEqual(list_professor_info[4].text, 'Phone Number: 0') self.assertEqual(list_professor_info[5].text, 'CellPhone Number: 0') self.assertEqual(list_professor_info[6].text, 'Id Department: None')
def test_edit_professor(self): professor = Professor(self.name_professor) professor.store() open_page(self.browser, '/interface/professor', self.live_server_url) professor_name_link = self.browser.find_element_by_link_text(self.name_professor) professor_name_link.click() self.assertIn('Interface - Professor Detail', self.browser.title) button_edit = self.browser.find_element_by_name('editar') button_edit.click() self.assertIn('Interface - Professor Edit', self.browser.title) form_name = self.browser.find_element_by_id('id_name') form_name.send_keys('Edit') form_memberId = self.browser.find_element_by_id('id_memberId') form_memberId.send_keys('') form_office = self.browser.find_element_by_id('id_office') form_office.send_keys('') form_email = self.browser.find_element_by_id('id_email') form_email.send_keys('') form_phoneNumber = self.browser.find_element_by_id('id_phoneNumber') form_phoneNumber.send_keys('0') form_cellphoneNumber = self.browser.find_element_by_id('id_cellphoneNumber') form_cellphoneNumber.send_keys('0') form_idDepartment = self.browser.find_element_by_id('id_idDepartment') form_idDepartment.send_keys('') button_apply = self.browser.find_element_by_name('Aplicar') button_apply.click() open_page(self.browser, '/interface/professor', self.live_server_url) professor_name_link_after_edit = self.browser.find_element_by_link_text(self.name_professor + 'Edit') professor_name_link_after_edit.click() list_professor_info = self.browser.find_elements_by_tag_name('p') self.assertEqual(list_professor_info[1].text, 'Member ID: 0') self.assertEqual(list_professor_info[2].text, 'Office: None') self.assertEqual(list_professor_info[3].text, 'Email: None') self.assertEqual(list_professor_info[4].text, 'Phone Number: 0') self.assertEqual(list_professor_info[5].text, 'CellPhone Number: 0') self.assertEqual(list_professor_info[6].text, 'Id Department: None')
def offer_create(request, idTimePeriod, idCourse): timePeriod = TimePeriod.pickById(idTimePeriod) course = Course.pickById(idCourse) if request.method == 'POST': form = OfferForm(request.POST) form.updateForm() if form.is_valid(): idProfessor = form.cleaned_data['dropDownProfessor'] classNumber = form.cleaned_data['classNumber'] practical = form.cleaned_data['dropDownTeoricaPratica'] numberOfRegistrations = form.cleaned_data['numberOfRegistrations'] schedulesIds = form.cleaned_data['listSchedules'] schedules = [ Schedule.pickById(schedule) for schedule in schedulesIds ] professor = Professor.pickById(idProfessor) practical = (practical == 1) offer = Offer(timePeriod, course, classNumber, practical, professor) offer.setSchedules(schedules) offer.setNumberOfRegistrations(numberOfRegistrations) offer.store() user = request.user user_name = request.user.username time = get_time() schedules_string = '[ ' for schedule in schedules: schedules_string += str(schedule).replace('ç', 'c') + " " schedules_string += ']' action = u"Usuário " + user_name + u" criou o oferecimento id: " + str(offer.idOffer) + " {" \ + u" Código do Curso: " + str(course.courseCode) \ + u"; Turma: T" + str(classNumber) \ + u"; Professor: " + professor.name \ + u"; Periodo: " + str(timePeriod) \ + u"; Horários: " + schedules_string + " }" offer_create_log = Log(user=user, action=action, time=time) offer_create_log.save() return HttpResponseRedirect('/interface/offer/' + str(offer.idOffer)) else: form = OfferForm() form.updateForm() rendered_page = render(request, 'offer_create.html', { 'form': form, 'timePeriod': timePeriod, 'course': course }) return rendered_page
def test_edit_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_edit = self.browser.find_element_by_name('editar') button_edit.click() self.assertIn('Interface - Offer Edit', self.browser.title) dropdown_professor = self.browser.find_element_by_id('id_dropDownProfessor') select_professor = Select(dropdown_professor) select_professor.select_by_value(str(self.second_professor.idProfessor)) input_classNumber = self.browser.find_element_by_id('id_classNumber') input_classNumber.send_keys('1') dropdown_practical = self.browser.find_element_by_id('id_dropDownTeoricaPratica') select_practical = Select(dropdown_practical) select_practical.select_by_value('1') input_numberOfRegistrations = self.browser.find_element_by_id('id_numberOfRegistrations') input_numberOfRegistrations.send_keys('1') self.browser.find_element_by_id("id_listSchedules_1").click() self.browser.find_element_by_id("id_listSchedules_2").click() button_apply = self.browser.find_element_by_name('Aplicar') button_apply.click() self.assertIn('Interface - Offer Detail', self.browser.title) id_courseCode = self.browser.find_element_by_id('courseCode') self.assertEqual(id_courseCode.text, 'tst9999') id_name = self.browser.find_element_by_id('name') self.assertEqual(id_name.text, 'teste9999') id_professor_name = self.browser.find_element_by_id('professor_name') self.assertEqual(id_professor_name.text, 'Professor Teste2') id_timePeriod = self.browser.find_element_by_id('timePeriod') self.assertEqual(id_timePeriod.text, 'Primeiro semestre de 2014') id_classNumber = self.browser.find_element_by_id('classNumber') self.assertEqual(id_classNumber.text, 'T101') id_practical = self.browser.find_element_by_id('practical') self.assertEqual(id_practical.text, "PRATICA") id_numberOfRegistrations = self.browser.find_element_by_id('numberOfRegistrations') self.assertEqual(id_numberOfRegistrations.text, '101') id_schedules = self.browser.find_element_by_id('schedules') self.assertIn("Domingo 12:00 - 14:00", id_schedules.text) self.assertNotIn("Segunda 16:00 - 19:00", id_schedules.text) self.assertNotIn("Quarta 14:00 - 16:00", id_schedules.text)
def getOffers(courseCode, idTimePeriod): """ Returns the set of idOffers defined by this courseCode as is defined in expandCourse method. @param string courseCode : If it is a normal course this is not used, if this is a subgroup of a course, this courseCode is going to define the offers.Ex PTC3011(P)[ProfName] = only practical offers given by ProfName in course PTC3011. @param int idTimePeriod : The idTimePeriod of the wanted offer's timePeriod. @return : @author """ professor = None practical = None if courseCode.find('[') != -1: professorName = courseCode.rsplit('[')[1].rsplit(']')[0] professor = Professor.find(name_equal=professorName)[0] courseCode = courseCode.rsplit('[')[0] + courseCode.rsplit(']')[1] if courseCode.find('(') != -1: practical = courseCode.rsplit('(')[1].rsplit(')')[0] if practical == 'P': practical = True elif practical == 'T': practical = False else: raise ColumnsControllerError( "The parameter given between the '()' must be equal to 'P' or 'T'." ) courseCode = courseCode.rsplit('(')[0] + courseCode.rsplit(')')[1] course = Course.find(courseCode_equal=courseCode, endDate_equal='0000-00-00')[0] timePeriod = TimePeriod.pickById(idTimePeriod) if professor and practical != None: offers = Offer.find(course=course, practical=practical, professor=professor, timePeriod=timePeriod) elif professor: offers = Offer.find(course=course, professor=professor, timePeriod=timePeriod) elif practical != None: offers = Offer.find(course=course, practical=practical, timePeriod=timePeriod) else: offers = Offer.find(course=course, timePeriod=timePeriod) idOffers = [offer.idOffer for offer in offers] return idOffers
def test_delete_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_delete = self.browser.find_element_by_name('deletar') button_delete.click() alert = self.browser.switch_to.alert alert.accept() self.assertIn('Interface', self.browser.title) open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertNotIn('Interface - Offer Detail', self.browser.title)
def offer_create(request, idTimePeriod, idCourse): timePeriod = TimePeriod.pickById(idTimePeriod) course = Course.pickById(idCourse) if request.method == 'POST': form = OfferForm(request.POST) form.updateForm() if form.is_valid(): idProfessor = form.cleaned_data['dropDownProfessor'] classNumber = form.cleaned_data['classNumber'] practical = form.cleaned_data['dropDownTeoricaPratica'] numberOfRegistrations = form.cleaned_data['numberOfRegistrations'] schedulesIds = form.cleaned_data['listSchedules'] schedules = [Schedule.pickById(schedule) for schedule in schedulesIds] professor = Professor.pickById(idProfessor) practical = (practical == 1) offer = Offer(timePeriod, course, classNumber, practical, professor) offer.setSchedules(schedules) offer.setNumberOfRegistrations(numberOfRegistrations) offer.store() user= request.user user_name = request.user.username time = get_time() schedules_string = '[ ' for schedule in schedules: schedules_string += str(schedule).replace('ç','c') + " " schedules_string += ']' action = u"Usuário " + user_name + u" criou o oferecimento id: " + str(offer.idOffer) + " {" \ + u" Código do Curso: " + str(course.courseCode) \ + u"; Turma: T" + str(classNumber) \ + u"; Professor: " + professor.name \ + u"; Periodo: " + str(timePeriod) \ + u"; Horários: " + schedules_string + " }" offer_create_log = Log(user=user, action=action, time=time) offer_create_log.save() return HttpResponseRedirect('/interface/offer/' + str(offer.idOffer)) else: form = OfferForm() form.updateForm() rendered_page = render(request, 'offer_create.html', {'form': form, 'timePeriod': timePeriod, 'course': course}) return rendered_page
def getOffers(courseCode, idTimePeriod): """ Returns the set of idOffers defined by this courseCode as is defined in expandCourse method. @param string courseCode : If it is a normal course this is not used, if this is a subgroup of a course, this courseCode is going to define the offers.Ex PTC3011(P)[ProfName] = only practical offers given by ProfName in course PTC3011. @param int idTimePeriod : The idTimePeriod of the wanted offer's timePeriod. @return : @author """ professor = None practical = None if courseCode.find('[') != -1: professorName = courseCode.rsplit('[')[1].rsplit(']')[0] professor = Professor.find(name_equal = professorName)[0] courseCode = courseCode.rsplit('[')[0] + courseCode.rsplit(']')[1] if courseCode.find('(') != -1: practical = courseCode.rsplit('(')[1].rsplit(')')[0] if practical == 'P': practical = True elif practical == 'T': practical = False else: raise ColumnsControllerError("The parameter given between the '()' must be equal to 'P' or 'T'.") courseCode = courseCode.rsplit('(')[0] + courseCode.rsplit(')')[1] course = Course.find(courseCode_equal = courseCode, endDate_equal = '0000-00-00')[0] timePeriod = TimePeriod.pickById(idTimePeriod) if professor and practical != None: offers = Offer.find(course = course, practical = practical, professor = professor, timePeriod = timePeriod) elif professor: offers = Offer.find(course = course, professor = professor, timePeriod = timePeriod) elif practical != None: offers = Offer.find(course = course, practical = practical, timePeriod = timePeriod) else: offers = Offer.find(course = course, timePeriod = timePeriod) idOffers = [offer.idOffer for offer in offers] return idOffers
def professor_create(request): if request.method == 'POST': form = ProfessorForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] memberId = form.cleaned_data['memberId'] office = form.cleaned_data['office'] email = form.cleaned_data['email'] phoneNumber = form.cleaned_data['phoneNumber'] cellphoneNumber = form.cleaned_data['cellphoneNumber'] idDepartment = form.cleaned_data['idDepartment'] professor = Professor(name) professor.setMemberId(memberId) if office: professor.setOffice(office) if email: professor.setEmail(email) if phoneNumber: professor.setPhoneNumber(phoneNumber) if cellphoneNumber: professor.setCellphoneNumber(cellphoneNumber) if idDepartment: professor.setDepartment(Department.pickById(idDepartment)) user = request.user user_name = request.user.username time = get_time() action = u"Usuário " + user_name + u" criou o professor " + name professor_create_log = Log(user=user, action=action, time=time) professor_create_log.save() professor.store() return HttpResponseRedirect('/interface/professor/' + str(professor.idProfessor)) else: form = ProfessorForm() rendered_page = render(request, 'professor_create.html', {'form': form}) return rendered_page
class OfferTest(LiveServerTestCase): def setUp(self): self.name_professor = 'teste' self.create_timePeriod_and_course() self.create_professor_and_schedule() self.browser = WebDriver() create_user_and_login(self.browser, self.live_server_url, 'john', 'johnpassword', '*****@*****.**') self.browser.implicitly_wait(40) def tearDown(self): cursor = MySQLConnection() [offer.delete() for offer in Offer.find()] [schedule.delete() for schedule in Schedule.find()] cursor.execute('DELETE FROM minitableDayOfTheWeek') [timePeriod.delete() for timePeriod in TimePeriod.find()] [course.delete() for course in Course.find()] [professor.delete() for professor in Professor.find()] self.browser.quit() def create_timePeriod_and_course(self): cursor = MySQLConnection() length = cursor.execute( 'SELECT idLength FROM minitableLength where length="Semestral"') if not length: cursor.execute( 'INSERT INTO minitableLength (length) values ("Semestral")') self.course = Course('tst9999', 'teste9999', '0000-00-00') self.course.store() length = cursor.execute( 'SELECT idLength FROM minitableLength where length="Semestral"') self.timePeriod = TimePeriod(1, 2014, 1) self.timePeriod.store() def create_professor_and_schedule(self): cursor = MySQLConnection() cursor.execute( 'INSERT INTO `minitableDayOfTheWeek` (dayOfTheWeek) VALUES ("Domingo"), ("Segunda"), ("Terça"), ("Quarta"), ("Quinta"), ("Sexta"), ("Sabado")' ) self.schedule = Schedule('Domingo', '14:00:00', 'weekly', '12:00:00') self.schedule.store() self.schedule = Schedule('Segunda', '19:00:00', 'weekly', '16:00:00') self.schedule.store() self.schedule = Schedule('Quarta', '16:00:00', 'weekly', '14:00:00') self.schedule.store() self.professor = Professor('Professor Teste') self.professor.store() self.second_professor = Professor('Professor Teste2') self.second_professor.store() def login_to_offer_page(self): open_page(self.browser, '/interface/', self.live_server_url) dropdown_timePeriod = self.browser.find_element_by_id( 'id_dropDownTimePeriod') dropdown_course = self.browser.find_element_by_id('id_dropDownCourse') select_timePeriod = Select(dropdown_timePeriod) select_timePeriod.select_by_value(str(self.timePeriod.idTimePeriod)) select_course = Select(dropdown_course) select_course.select_by_value(str(self.course.idCourse)) professor_interface = self.browser.find_element_by_link_text('Offer') professor_interface.click() self.assertIn('Interface - Offer', self.browser.title) def test_create_offer(self): self.login_to_offer_page() button_create_offer = self.browser.find_element_by_name('criar') button_create_offer.click() self.assertIn('Interface - Offer Create', self.browser.title) dropdown_professor = self.browser.find_element_by_id( 'id_dropDownProfessor') select_professor = Select(dropdown_professor) select_professor.select_by_value(str(self.professor.idProfessor)) input_classNumber = self.browser.find_element_by_id('id_classNumber') input_classNumber.send_keys('1') dropdown_practical = self.browser.find_element_by_id( 'id_dropDownTeoricaPratica') select_practical = Select(dropdown_practical) select_practical.select_by_value('1') input_numberOfRegistrations = self.browser.find_element_by_id( 'id_numberOfRegistrations') input_numberOfRegistrations.send_keys('10') self.browser.find_element_by_id("id_listSchedules_0").click() self.browser.find_element_by_id("id_listSchedules_1").click() self.browser.find_element_by_id("id_listSchedules_2").click() button_store = self.browser.find_element_by_name('Cadastrar') button_store.click() self.assertIn('Interface - Offer Detail', self.browser.title) id_courseCode = self.browser.find_element_by_id('courseCode') self.assertEqual(id_courseCode.text, 'tst9999') id_name = self.browser.find_element_by_id('name') self.assertEqual(id_name.text, 'teste9999') id_professor_name = self.browser.find_element_by_id('professor_name') self.assertEqual(id_professor_name.text, 'Professor Teste') id_timePeriod = self.browser.find_element_by_id('timePeriod') self.assertEqual(id_timePeriod.text, 'Primeiro semestre de 2014') id_classNumber = self.browser.find_element_by_id('classNumber') self.assertEqual(id_classNumber.text, 'T01') id_practical = self.browser.find_element_by_id('practical') self.assertEqual(id_practical.text, "TEORICA") id_numberOfRegistrations = self.browser.find_element_by_id( 'numberOfRegistrations') self.assertEqual(id_numberOfRegistrations.text, '10') id_schedules = self.browser.find_element_by_id('schedules') self.assertIn("Domingo 12:00 - 14:00", id_schedules.text) self.assertIn("Segunda 16:00 - 19:00", id_schedules.text) self.assertIn("Quarta 14:00 - 16:00", id_schedules.text) def test_edit_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_edit = self.browser.find_element_by_name('editar') button_edit.click() self.assertIn('Interface - Offer Edit', self.browser.title) dropdown_professor = self.browser.find_element_by_id( 'id_dropDownProfessor') select_professor = Select(dropdown_professor) select_professor.select_by_value(str( self.second_professor.idProfessor)) input_classNumber = self.browser.find_element_by_id('id_classNumber') input_classNumber.send_keys('1') dropdown_practical = self.browser.find_element_by_id( 'id_dropDownTeoricaPratica') select_practical = Select(dropdown_practical) select_practical.select_by_value('1') input_numberOfRegistrations = self.browser.find_element_by_id( 'id_numberOfRegistrations') input_numberOfRegistrations.send_keys('1') self.browser.find_element_by_id("id_listSchedules_1").click() self.browser.find_element_by_id("id_listSchedules_2").click() button_apply = self.browser.find_element_by_name('Aplicar') button_apply.click() self.assertIn('Interface - Offer Detail', self.browser.title) id_courseCode = self.browser.find_element_by_id('courseCode') self.assertEqual(id_courseCode.text, 'tst9999') id_name = self.browser.find_element_by_id('name') self.assertEqual(id_name.text, 'teste9999') id_professor_name = self.browser.find_element_by_id('professor_name') self.assertEqual(id_professor_name.text, 'Professor Teste2') id_timePeriod = self.browser.find_element_by_id('timePeriod') self.assertEqual(id_timePeriod.text, 'Primeiro semestre de 2014') id_classNumber = self.browser.find_element_by_id('classNumber') self.assertEqual(id_classNumber.text, 'T101') id_practical = self.browser.find_element_by_id('practical') self.assertEqual(id_practical.text, "PRATICA") id_numberOfRegistrations = self.browser.find_element_by_id( 'numberOfRegistrations') self.assertEqual(id_numberOfRegistrations.text, '101') id_schedules = self.browser.find_element_by_id('schedules') self.assertIn("Domingo 12:00 - 14:00", id_schedules.text) self.assertNotIn("Segunda 16:00 - 19:00", id_schedules.text) self.assertNotIn("Quarta 14:00 - 16:00", id_schedules.text) def test_delete_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_delete = self.browser.find_element_by_name('deletar') button_delete.click() alert = self.browser.switch_to.alert alert.accept() self.assertIn('Interface', self.browser.title) open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertNotIn('Interface - Offer Detail', self.browser.title)
def tearDown(self): [professor.delete() for professor in Professor.find()] self.browser.quit()
def professor_detail(request, idProfessor): professor = Professor.pickById(idProfessor) rendered_page = render(request, 'professor_detail.html', {'professor': professor}) return rendered_page
class OfferTest (LiveServerTestCase): def setUp(self): self.name_professor = 'teste' self.create_timePeriod_and_course() self.create_professor_and_schedule() self.browser = WebDriver() create_user_and_login(self.browser, self.live_server_url,'john','johnpassword','*****@*****.**') self.browser.implicitly_wait(40) def tearDown(self): cursor = MySQLConnection() [offer.delete() for offer in Offer.find()] [schedule.delete() for schedule in Schedule.find()] cursor.execute('DELETE FROM minitableDayOfTheWeek') [timePeriod.delete() for timePeriod in TimePeriod.find()] [course.delete() for course in Course.find()] [professor.delete() for professor in Professor.find()] self.browser.quit() def create_timePeriod_and_course(self): cursor = MySQLConnection() length = cursor.execute('SELECT idLength FROM minitableLength where length="Semestral"') if not length: cursor.execute('INSERT INTO minitableLength (length) values ("Semestral")') self.course = Course('tst9999', 'teste9999', '0000-00-00') self.course.store() length = cursor.execute('SELECT idLength FROM minitableLength where length="Semestral"') self.timePeriod = TimePeriod(1, 2014, 1) self.timePeriod.store() def create_professor_and_schedule(self): cursor = MySQLConnection() cursor.execute('INSERT INTO `minitableDayOfTheWeek` (dayOfTheWeek) VALUES ("Domingo"), ("Segunda"), ("Terça"), ("Quarta"), ("Quinta"), ("Sexta"), ("Sabado")') self.schedule = Schedule('Domingo', '14:00:00', 'weekly', '12:00:00') self.schedule.store() self.schedule = Schedule('Segunda', '19:00:00', 'weekly', '16:00:00') self.schedule.store() self.schedule = Schedule('Quarta', '16:00:00', 'weekly', '14:00:00') self.schedule.store() self.professor = Professor('Professor Teste') self.professor.store() self.second_professor = Professor('Professor Teste2') self.second_professor.store() def login_to_offer_page(self): open_page(self.browser, '/interface/', self.live_server_url) dropdown_timePeriod = self.browser.find_element_by_id('id_dropDownTimePeriod') dropdown_course = self.browser.find_element_by_id('id_dropDownCourse') select_timePeriod = Select(dropdown_timePeriod) select_timePeriod.select_by_value(str(self.timePeriod.idTimePeriod)) select_course = Select(dropdown_course) select_course.select_by_value(str(self.course.idCourse)) professor_interface = self.browser.find_element_by_link_text('Offer') professor_interface.click() self.assertIn('Interface - Offer', self.browser.title) def test_create_offer(self): self.login_to_offer_page() button_create_offer = self.browser.find_element_by_name('criar') button_create_offer.click() self.assertIn('Interface - Offer Create', self.browser.title) dropdown_professor = self.browser.find_element_by_id('id_dropDownProfessor') select_professor = Select(dropdown_professor) select_professor.select_by_value(str(self.professor.idProfessor)) input_classNumber = self.browser.find_element_by_id('id_classNumber') input_classNumber.send_keys('1') dropdown_practical = self.browser.find_element_by_id('id_dropDownTeoricaPratica') select_practical = Select(dropdown_practical) select_practical.select_by_value('1') input_numberOfRegistrations = self.browser.find_element_by_id('id_numberOfRegistrations') input_numberOfRegistrations.send_keys('10') self.browser.find_element_by_id("id_listSchedules_0").click() self.browser.find_element_by_id("id_listSchedules_1").click() self.browser.find_element_by_id("id_listSchedules_2").click() button_store = self.browser.find_element_by_name('Cadastrar') button_store.click() self.assertIn('Interface - Offer Detail', self.browser.title) id_courseCode = self.browser.find_element_by_id('courseCode') self.assertEqual(id_courseCode.text, 'tst9999') id_name = self.browser.find_element_by_id('name') self.assertEqual(id_name.text, 'teste9999') id_professor_name = self.browser.find_element_by_id('professor_name') self.assertEqual(id_professor_name.text, 'Professor Teste') id_timePeriod = self.browser.find_element_by_id('timePeriod') self.assertEqual(id_timePeriod.text, 'Primeiro semestre de 2014') id_classNumber = self.browser.find_element_by_id('classNumber') self.assertEqual(id_classNumber.text, 'T01') id_practical = self.browser.find_element_by_id('practical') self.assertEqual(id_practical.text, "TEORICA") id_numberOfRegistrations = self.browser.find_element_by_id('numberOfRegistrations') self.assertEqual(id_numberOfRegistrations.text, '10') id_schedules = self.browser.find_element_by_id('schedules') self.assertIn("Domingo 12:00 - 14:00", id_schedules.text) self.assertIn("Segunda 16:00 - 19:00", id_schedules.text) self.assertIn("Quarta 14:00 - 16:00", id_schedules.text) def test_edit_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_edit = self.browser.find_element_by_name('editar') button_edit.click() self.assertIn('Interface - Offer Edit', self.browser.title) dropdown_professor = self.browser.find_element_by_id('id_dropDownProfessor') select_professor = Select(dropdown_professor) select_professor.select_by_value(str(self.second_professor.idProfessor)) input_classNumber = self.browser.find_element_by_id('id_classNumber') input_classNumber.send_keys('1') dropdown_practical = self.browser.find_element_by_id('id_dropDownTeoricaPratica') select_practical = Select(dropdown_practical) select_practical.select_by_value('1') input_numberOfRegistrations = self.browser.find_element_by_id('id_numberOfRegistrations') input_numberOfRegistrations.send_keys('1') self.browser.find_element_by_id("id_listSchedules_1").click() self.browser.find_element_by_id("id_listSchedules_2").click() button_apply = self.browser.find_element_by_name('Aplicar') button_apply.click() self.assertIn('Interface - Offer Detail', self.browser.title) id_courseCode = self.browser.find_element_by_id('courseCode') self.assertEqual(id_courseCode.text, 'tst9999') id_name = self.browser.find_element_by_id('name') self.assertEqual(id_name.text, 'teste9999') id_professor_name = self.browser.find_element_by_id('professor_name') self.assertEqual(id_professor_name.text, 'Professor Teste2') id_timePeriod = self.browser.find_element_by_id('timePeriod') self.assertEqual(id_timePeriod.text, 'Primeiro semestre de 2014') id_classNumber = self.browser.find_element_by_id('classNumber') self.assertEqual(id_classNumber.text, 'T101') id_practical = self.browser.find_element_by_id('practical') self.assertEqual(id_practical.text, "PRATICA") id_numberOfRegistrations = self.browser.find_element_by_id('numberOfRegistrations') self.assertEqual(id_numberOfRegistrations.text, '101') id_schedules = self.browser.find_element_by_id('schedules') self.assertIn("Domingo 12:00 - 14:00", id_schedules.text) self.assertNotIn("Segunda 16:00 - 19:00", id_schedules.text) self.assertNotIn("Quarta 14:00 - 16:00", id_schedules.text) def test_delete_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_delete = self.browser.find_element_by_name('deletar') button_delete.click() alert = self.browser.switch_to.alert alert.accept() self.assertIn('Interface', self.browser.title) open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertNotIn('Interface - Offer Detail', self.browser.title)
def professor(request): professors = Professor.find() rendered_page = render(request, 'professor.html', {'professors': professors}) return rendered_page
def professor_create(request): if request.method == 'POST': form = ProfessorForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] memberId = form.cleaned_data['memberId'] office = form.cleaned_data['office'] email = form.cleaned_data['email'] phoneNumber = form.cleaned_data['phoneNumber'] cellphoneNumber = form.cleaned_data['cellphoneNumber'] idDepartment = form.cleaned_data['idDepartment'] professor = Professor(name) professor.setMemberId(memberId) if office: professor.setOffice(office) if email: professor.setEmail(email) if phoneNumber: professor.setPhoneNumber(phoneNumber) if cellphoneNumber: professor.setCellphoneNumber(cellphoneNumber) if idDepartment: professor.setDepartment(Department.pickById(idDepartment)) user= request.user user_name = request.user.username time = get_time() action = u"Usuário " + user_name + u" criou o professor " + name professor_create_log = Log(user=user, action=action, time=time) professor_create_log.save() professor.store() return HttpResponseRedirect('/interface/professor/' + str(professor.idProfessor)) else: form = ProfessorForm() rendered_page = render(request, 'professor_create.html', {'form': form}) return rendered_page