def create_booking_information(testingBookingId, testingCarId, testingUsername, testingBookStatus, testingStartTime, testingEndTime): defineNull = None response = API.test_client().post( '/bookings', data=json.dumps({ "bookingId": testingBookingId, "carId": testingCarId, "userId": testingUsername, "bookStatus": testingBookStatus, "startTime": testingStartTime, "endTime": testingEndTime, "returnTime": defineNull, "bookingFee": defineNull, "customerNotes": defineNull, "adminNotes": defineNull, "mechanicalIssue": defineNull, "ticketStatus": defineNull, "locationName": defineNull }), content_type='application/json', ) response = API.test_client().get( '/bookings/' + testingBookingId, content_type='application/json', ) data2 = json.loads(response.get_data(as_text=True)) returnBookStatus = data2["bookingDetails"]["bookStatus"] return returnBookStatus
def signup(): username = request.form['username'] password = request.form['password'] firstname = request.form['firstname'] lastname = request.form['lastname'] email = request.form['email'] usertype = request.form['usertype'] userstatus = 'active' hashedPassword = sha256_crypt.using(rounds = 3000).hash(password) data1=json.dumps({"userId": username, "firstName": firstname, "lastName": lastname, "emailId": email, "accountType": usertype, "accountStatus": userstatus}) data=json.dumps({"passHash": hashedPassword, "userId": username}) response = API.test_client().post( '/logins', data = data, content_type='application/json', ) response = API.test_client().post( '/users', data = data1, content_type='application/json', ) return redirect(url_for('index'))
def create_user_information(username, testingFirstName, testingLastName, testingEmailID, testingAccountType, testingAccountStatus): response = API.test_client().post( '/users', data=json.dumps({ "userId": username, "firstName": testingFirstName, "lastName": testingLastName, "emailId": testingEmailID, "accountType": testingAccountType, "accountStatus": testingAccountStatus }), content_type='application/json', ) response = API.test_client().get( '/users/' + username, content_type='application/json', ) data2 = json.loads(response.get_data(as_text=True)) returnEmailID = data2["userDetails"]["emailId"] return returnEmailID
def delete_car_information(carnumber): response = API.test_client().delete( '/cars/' + carnumber, content_type='application/json', ) response = API.test_client().get( '/bookings/' + carnumber, content_type='application/json', ) data2 = json.loads(response.get_data(as_text=True)) returnUser = data2["carDetails"]["carId"] return returnUser
def delete_login_information(username): response = API.test_client().delete( '/logins/' + username, content_type='application/json', ) response = API.test_client().get( '/logins/' + username, content_type='application/json', ) data2 = json.loads(response.get_data(as_text=True)) returnUser = data2["loginDetails"]["userId"] return returnUser
def getBooikings(): """ query the database for all bookings """ response = a.test_client().get('/bookings', content_type='application/json',) data2 = json.loads(response.get_data(as_text=True)) return data2
def getUserName(var): """ query the database for all cars of a cetrain body type """ response = a.test_client().get('/usersbyfirstname/' + var, content_type='application/json',) data2 = json.loads(response.get_data(as_text=True)) return data2
def update_user_information(username, newaccountstatus): response = API.test_client().put( '/users/' + username, data=json.dumps({"accountStatus": newaccountstatus}), content_type='application/json', ) response = API.test_client().get( '/users/' + username, content_type='application/json', ) data2 = json.loads(response.get_data(as_text=True)) returnAccountStatus = data2["userDetails"]["accountStatus"] return returnAccountStatus
def update_booking_information(testingBookingId, testingAdminNote): response = API.test_client().put( '/bookings/' + testingBookingId, data=json.dumps({"adminNotes": testingAdminNote}), content_type='application/json', ) response = API.test_client().get( '/bookings/' + testingBookingId, content_type='application/json', ) data2 = json.loads(response.get_data(as_text=True)) returnAdminNote = data2["bookingDetails"]["adminNotes"] return returnAdminNote
def update_car_information(testingCarId, testingNewLockStatus): response = API.test_client().put( '/cars/' + testingCarId, data=json.dumps({"colorType": testingNewLockStatus}), content_type='application/json', ) response = API.test_client().get( '/cars/' + testingCarId, content_type='application/json', ) data2 = json.loads(response.get_data(as_text=True)) returnCarId = data2["carDetails"]["makeBrand"] returnLockStatus = data2["carDetails"]["colorType"] return returnLockStatus
def update_login_information(username, newpassword): response = API.test_client().put( '/logins/' + username, data=json.dumps({"passHash": newpassword}), content_type='application/json', ) response = API.test_client().get( '/logins/' + username, content_type='application/json', ) data2 = json.loads(response.get_data(as_text=True)) returnUser = data2["loginDetails"]["userId"] returnPass = data2["loginDetails"]["passHash"] return returnUser return returnPass
def getCars(): """ query the database for all available cars """ response = a.test_client().get('/availablecars', content_type='application/json',) data2 = json.loads(response.get_data(as_text=True)) return data2
def availablecars(): response = API.test_client().get( '/availablecars', content_type = 'application/json', ) data = json.loads(response.get_data(as_text = True)) return render_template('availableCars.html', value = str(data))
def adminbookinghistory(): response = API.test_client().get( '/bookings', content_type = 'application/json', ) data = json.loads(response.get_data(as_text = True)) return render_template('bookingHistoryResults.html', value = str(data))
def searchbycarid(): search = request.form['searchcriteria'] response = API.test_client().get( '/cars/' + search, content_type = 'application/json', ) data2 = json.loads(response.get_data(as_text=True)) return render_template('results.html', value = str(data2))
def setUp(self): ''' this method sets up the client and the test data we'll be using in the tests ''' app.config.from_object(app_config['testing']) self.client = app.test_client() with self.client as client: ''' create all tables before first request ''' dbHandle = DbHandler() dbHandle.drop_all_tables() dbHandle.create_tables() dbHandle.close_conn() add_test_user(client)
def searchbyaccountstatus(): search = request.form['searchuser'] response = API.test_client().get( '/usersbyaccountstatus/' + search, content_type = 'application/json', ) data2 = json.loads(response.get_data(as_text=True)) return render_template('results.html', value = data2)
def get_new_carid(): response = API.test_client().get( '/makenewcarid', content_type='application/json', ) data = json.loads(response.get_data(as_text=True)) returncarid = data["makenewcarid"][0]["MAX(carId)"] returncarid += 1 return returncarid
def cancelbooking(): test= returnUsername() response = API.test_client().get( '/bookingsbyusers/' + test, content_type = 'application/json', ) data2 = json.loads(response.get_data(as_text=True)) return render_template('cancelBookingResults.html', value = data2)
def get_new_bookingid(): response = API.test_client().get( '/makenewbookingid', content_type='application/json', ) data7 = json.loads(response.get_data(as_text=True)) returnBookingId = data7["makenewbookingid"][0]["MAX(bookingId)"] returnBookingId += 1 return returnBookingId
def bookinghistory(): userid = returnUsername() # userid = userId response = API.test_client().get( '/bookingsbyusers/' + userid, content_type = 'application/json', ) data = json.loads(response.get_data(as_text = True)) return render_template('bookingHistoryResults.html', value = str(data))
def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] hashedPassword = sha256_crypt.using(rounds = 3000).hash(password) response = API.test_client().get( '/logins/' + username, content_type='application/json', ) response1 = API.test_client().get( 'users/' + username, content_type='application/json', ) data2 = json.loads(response.get_data(as_text=True)) data3 = json.loads(response1.get_data(as_text=True)) userId = data2["loginDetails"]["userId"] passHash = data2["loginDetails"]["passHash"] userType = data3["userDetails"]["accountType"] try: if str(userType) == 'admin': if str(userId) == username or str(hashedPassword) == passHash: if(sha256_crypt.verify(password, passHash)): return render_template('adminView.html', value = username) flash('Invalid Login Credentials!') elif str(userType) != 'admin': if str(userId) == username or str(hashedPassword) == passHash: if(sha256_crypt.verify(password, passHash)): return render_template('view.html', value = username) flash('Invalid Login Credentials!') except: flash('Invalid Login Credentials!') return redirect(url_for('index'))
def createbooking(): defineNull = None userId = returnUsername() startdate = request.form['starttime'] enddate = request.form['endtime'] carid = request.form['carid'] bookstatus = 'booked' bookingId = get_new_bookingid() data=json.dumps({"userId": userId, "bookingId": bookingId, "carId": carid, "bookStatus": bookstatus, "startTime": startdate, "endTime": enddate, "returnTime": defineNull, "bookingFee": defineNull, "customerNotes": defineNull, "adminNotes": defineNull, "locationName": defineNull}) response = API.test_client().get( '/cars/' + carid, content_type = 'application/json', ) data2 = json.loads(response.get_data(as_text=True)) try: carID = data2["carDetails"]["carId"] brand = data2["carDetails"]["makeBrand"] bodyType = data2["carDetails"]["bodyType"] color = data2["carDetails"]["colorType"] numSeats = data2["carDetails"]["numSeats"] hrCost = data2["carDetails"]["hourlyCost"] if str(carID) == carid: response1 = API.test_client().post( '/bookings', data = data, content_type = 'application/json', ) #Creates new calendar event cal = calendar.GoogleCalendar() cal.creatEvent(defineNull, "location", carID, brand, bodyType, color, numSeats, hrCost, startdate, enddate) return render_template('view.html') except: flash('Invalid CarID') return render_template('view.html')
def cancelbookingfinal(): bookingID = request.form['bookingid'] newBookStatus = 'Cancelled' response = API.test_client().put( '/bookings/' + bookingID, data=json.dumps({"bookStatus": newBookStatus}), content_type='application/json', ) flash('Booking has been cancelled') return redirect(url_for('view'))
def update_booking_for_tech(newBookingId, newBookStatus, newMechanicalIssue, newTicketStatus): response = API.test_client().put( '/bookings/' + newBookingId, data=json.dumps({"bookStatus": newBookStatus}), content_type='application/json', ) #data2 = json.loads(response.get_data(as_text=True)) response = API.test_client().put( '/bookings/' + newBookingId, data=json.dumps({"mechanicalIssue": newMechanicalIssue}), content_type='application/json', ) #data2 = json.loads(response.get_data(as_text=True)) response = API.test_client().put( '/bookings/' + newBookingId, data=json.dumps({"ticketStatus": newTicketStatus}), content_type='application/json', )
def returnUsername(): # returnuser = request.form['username'] returnuser = '******' response = API.test_client().get( '/logins/' + returnuser, content_type='application/json', ) data2 = json.loads(response.get_data(as_text=True)) userId = data2["loginDetails"]["userId"] if str(userId) == returnuser: return returnuser
def create_car_information(testingCarId, testingMakeBrand, testingBodyType, testingRego, testingColorType, testingNumSeats, testingHourlyCost, testingLockStatus): response = API.test_client().post( '/cars', data=json.dumps({ "carId": testingCarId, "makeBrand": testingMakeBrand, "bodyType": testingBodyType, "rego": testingRego, "colorType": testingColorType, "numSeats": testingNumSeats, "hourlyCost": testingHourlyCost, "lockStatus": testingLockStatus }), content_type='application/json', ) response = API.test_client().get( '/cars/' + testingCarId, content_type='application/json', ) data2 = json.loads(response.get_data(as_text=True)) returnCarId = data2["carDetails"]["carId"] returnMakeBrand = data2["carDetails"]["makeBrand"] returnBodyType = data2["carDetails"]["bodyType"] returnRego = data2["carDetails"]["rego"] returnColorType = data2["carDetails"]["colorType"] returnNumSeats = data2["carDetails"]["numSeats"] returnHourlyCost = data2["carDetails"]["hourlyCost"] returnLockStatus = data2["carDetails"]["lockStatus"] return returnBodyType return returnMakeBrand
def addcar(): rego = request.form['rego'] makebrand = request.form['makebrand'] bodytype = request.form['bodytype'] colourtype = request.form['colourtype'] numseats = request.form['numseats'] lockstatus = 'false' carId = get_new_carid() hourlycost = request.form['hourlycost'] data = json.dumps({'rego':rego, 'makeBrand':makebrand, 'bodyType':bodytype, 'colorType':colourtype, 'numSeats':numseats, 'lockStatus':lockstatus, 'carId':carId, 'hourlyCost':hourlycost}) response = API.test_client().post( '/cars', data = data, content_type = 'application/json', ) return render_template('adminView.html')
def login(self): response = API.test_client().get( '/logins/' + self.systemUserId, content_type='application/json', ) data2 = json.loads(response.get_data(as_text=True)) userId = data2["loginDetails"]["userId"] passHash = data2["loginDetails"]["passHash"] if userId == self.systemUserId: if(sha256_crypt.verify(self.systemPassword, passHash)): self.idPassed = True return redirect(url_for('view')) else: self.idPassed = False return redirect(url_for('index'))
def setUp(self): self.tester = app.test_client() app.doTesting = True self.tester.testing = True