def bookCar(self, id): if not self.__isUserLoggedIn(): return redirect(url_for('index')) form = BookingForm() if request.method == 'POST': userId = self.__getLoggedInUser().getId() carId = request.form['carId'] startMonth = request.form['startMonth'] startDay = request.form['startDay'] endMonth = request.form['endMonth'] endDay = request.form['endDay'] userDict = self.__apiController.requestGet( 'http://localhost:5000/css/api/v1.0/users/{}'.format(userId)) user = User(userDict['id'], userDict['username'], userDict['password'], userDict['firstName'], userDict['lastName'], userDict['email'], userDict['faceId']) carDict = self.__apiController.requestGet( 'http://localhost:5000/css/api/v1.0/cars/{}'.format(carId)) bookingController = BookingController(user) bookingController.book(carDict['make'], user, startMonth, startDay, endMonth, endDay) return redirect(url_for('index')) return render_template('carBooking.html', carId=id, userId=self.__getLoggedInUser().getId(), form=form)
def setUp(self): googleController.authenticateGoogleUser() googleController.fetchCalendar() uDict = self.__apiController.requestGet('http://localhost:5000/css/api/v1.0/users/1') self.__user = User(uDict['id'], uDict['username'], uDict['password'], uDict['firstName'], uDict['lastName'], uDict['email'], uDict['faceId']) self.__bookingController = BookingController(self.__user) return super().setUp()
class Interface: def mainMenu(self): showCarsController = ShowAllCarsController() book = bookingConsole(self.__bookingController, self.__user) menuController = MainMenuController() menuController.setUser(self.__user) menuController.setBookingConsole(book) menu = mainMenuConsole(menuController, showCarsController) return menu.printMenu() def userLogin(self): logController = LoginController() verController = VerificationController() encryptPassword = EncryptPassword() log = loginFromConsole(logController, verController, encryptPassword) return log.login() def userRegister(self): camController = CameraController(self.__camera, self.__recogniser) regController = RegistrationController() verController = VerificationController() encryptPassword = EncryptPassword() reg = registerFromConsole(verController, regController, encryptPassword, camController) reg.register() def showAllAvailableCars(self): showCarsController = ShowAllCarsController() showCars = showAllAvailableCarsConsole(showCarsController) showCars.showAllAvailableCars() def initialMenu(self): camController = CameraController(self.__camera, self.__recogniser) logController = LoginController() verController = VerificationController() regController = RegistrationController() encryptPassword = EncryptPassword() log = loginFromConsole(logController, verController, encryptPassword) reg = registerFromConsole(verController, regController, encryptPassword, camController) menuController = InitialMenuController(log, reg) menuConsole = initialMenuConsole(menuController) self.__user = menuConsole.printMenu() self.__bookingController = BookingController(self.__user) print('Please wait while your existing bookings are updated...') self.__bookingController.updateBookingsStatus() return self.__user def calendarSetup(self): googleController.authenticateGoogleUser() googleController.fetchCalendar() def setFaceClasses(self, camera, recogniser): self.__camera = camera self.__recogniser = recogniser
def login(self): form = LoginForm() if request.method == 'POST': email = request.form['email'] password = self.__encryptPassword.hash(request.form['password']) user = self.__loginController.login(email, password) if user: googleController.authenticateGoogleUser() googleController.fetchCalendar() bookingController = BookingController(user) bookingController.updateBookingsStatus() return redirect(url_for('index')) return redirect(url_for('login')) return render_template('login.html', form=form)
def initialMenu(self): camController = CameraController(self.__camera, self.__recogniser) logController = LoginController() verController = VerificationController() regController = RegistrationController() encryptPassword = EncryptPassword() log = loginFromConsole(logController, verController, encryptPassword) reg = registerFromConsole(verController, regController, encryptPassword, camController) menuController = InitialMenuController(log, reg) menuConsole = initialMenuConsole(menuController) self.__user = menuConsole.printMenu() self.__bookingController = BookingController(self.__user) print('Please wait while your existing bookings are updated...') self.__bookingController.updateBookingsStatus() return self.__user
class BookingControllerTest(unittest.TestCase): __bookingController = None __apiController = ApiController() def setUp(self): googleController.authenticateGoogleUser() googleController.fetchCalendar() uDict = self.__apiController.requestGet('http://localhost:5000/css/api/v1.0/users/1') self.__user = User(uDict['id'], uDict['username'], uDict['password'], uDict['firstName'], uDict['lastName'], uDict['email'], uDict['faceId']) self.__bookingController = BookingController(self.__user) return super().setUp() def testbook(self): self.assertTrue(self.__bookingController.book('Holden', self.__user, 12, 1, 12, 7)) def tearDown(self): bookingId = len(self.__apiController.requestGet('http://localhost:5000/css/api/v1.0/bookings')['bookings']) requests.delete('http://localhost:5000/css/api/v1.0/bookings/{}'.format(bookingId)) return super().tearDown()