def checkforschedule(day, start, end): """Returns a schedule object created after a bank query using the parameters or a new schedule, if a schedule is not found""" schedule = Schedule.find(dayOfTheWeek_equal=day, start_equal=start, end_equal=end) if schedule: schedule = schedule[0] else: schedule = Schedule(day, end, 'semanal', start) return schedule
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 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 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 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_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 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 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 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 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 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
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)
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)