def newtrip(request): '''TIENE ALGUN VIAJE ACTIVO EL USER''' myActiveTrips = Trip.objects.filter( Q(driver=request.user.id) | Q(passengers__id=request.user.id)) myActiveTrips = myActiveTrips.filter( Q(status=1) | Q(status=2) | Q(status=3)) if (myActiveTrips.count() > 0): return HttpResponseRedirect("/ViajeroFrecuente/currenttrip") # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = NewTripForm(request.POST) # check whether it's valid: if form.is_valid(): authUser = User.objects.filter(username=request.user.username) user_id = authUser.first().id vehicle = Vehicle.objects.filter(drivers__id=user_id) vehicle_id = vehicle.first().id trip = Trip() trip.fromPlace = form.cleaned_data['fromPlace'] trip.toPlace = form.cleaned_data['toPlace'] trip.amount = form.cleaned_data['amount'] trip.passengerqty = form.cleaned_data['passengerqty'] trip.vehicle = Vehicle.objects.get(id=vehicle_id) trip.driver = User.objects.get(id=user_id) trip.status = TripStatus.objects.get(id=1) trip.Save() # process the data in form.cleaned_data as required # ... # redirect to a new URL: return HttpResponseRedirect('main') # if a GET (or any other method) we'll create a blank form else: form = NewTripForm() return render(request, 'newtrip.html', {'form': form})
def test_qualification_is_given_by_same_user(self): usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = Utils.encrypt(self, 'pwd1') usr.credits = 400 usr.Save() savedUsr = ServiceUser().RetrieveAll().first() usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() + timedelta(days=1) settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.tripstatus_description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.trip_date = date_with_timezone trip.trip_amount = 200 trip.trip_driver = savedUsr trip.trip_from = 'ORIGEN' trip.trip_to = 'DESTINO' trip.trip_passengerqty = 5 trip.trip_vehicle = vehicle trip.trip_tripstatus = tripStatus savedTrip = trip.Save() usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = Utils.encrypt(self, 'pwd1') usr.credits = 400 psngr = usr.Save() savedTrip = savedTrip.AddPassengerToTrip(psngr) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) qual = Qualification() qual.setQualificationDate(date_with_timezone) qual.setQualificationTrip(savedTrip) qual.setQualificationUser(savedUsr) qual.setQualificationGivenBy(savedUsr) qual.setQualificationValue(5) with self.assertRaises(Exception) as context: qual.Save() self.assertEqual('User giving and receiving feedback is the same', context.exception.args[0])
def test_was_created_successfully(self): usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr.Save() savedUsr = ServiceUser().RetrieveAll().first() usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.tripstatus_description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.trip_date = date_with_timezone trip.trip_amount = 200 trip.trip_driver = savedUsr trip.trip_from = 'ORIGEN' trip.trip_to = 'DESTINO' trip.trip_passengerqty = 5 trip.trip_vehicle = vehicle trip.trip_tripstatus = tripStatus savedTrip = trip.Save() usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = Utils.encrypt(self, 'pwd1') usr.credits = 400 psngr = usr.Save() savedTrip = savedTrip.AddPassengerToTrip(psngr) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) qual = Qualification() qual.setQualificationDate(date_with_timezone) qual.setQualificationTrip(savedTrip) qual.setQualificationUser(savedUsr) qual.setQualificationGivenBy(psngr) qual.setQualificationValue(5) savedQual = qual.Save() self.assertIsNotNone(savedQual)
def test_trip_vehicle_has_another_active_trip(self): '''USUARIO 1''' usr1 = AppUser() usr1.fullname = 'TEST NOMBRE COMPLETO' usr1.username = '******' usr1.password = '******' usr1.credits = 400 usr1 = usr1.Save() '''USUARIO 2''' usr2 = AppUser() usr2.fullname = 'TEST NOMBRE COMPLETO' usr2.username = '******' usr2.password = '******' usr2.credits = 400 usr2.Save() '''CREATE 1 VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set([usr1]) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.tripstatus_description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP 1''' trip1 = Trip() trip1.trip_date = date_with_timezone trip1.trip_amount = 1000 trip1.trip_driver = usr1 trip1.trip_from = 'ORIGEN' trip1.trip_to = 'DESTINO' trip1.trip_passengerqty = 5 trip1.trip_vehicle = vehicle trip1.trip_tripstatus = tripStatus trip1 = trip1.Save() '''CREATE TRIP 2''' trip2 = Trip() trip2.trip_date = date_with_timezone trip2.trip_amount = 1000 trip2.trip_driver = usr2 trip2.trip_from = 'ORIGEN' trip2.trip_to = 'DESTINO' trip2.trip_passengerqty = 5 trip2.trip_vehicle = vehicle trip2.trip_tripstatus = tripStatus with self.assertRaises(Exception) as context: trip2 = trip2.Save() self.assertEqual('Vehicle is assigned to another trip', context.exception.args[0])
def test_trip_driver_has_another_active_trip(self): usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr.Save() savedUsr = ServiceUser().RetrieveAll().first() usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle2 = Vehicle() vehicle2.model = 'FORD FOCUS' vehicle2.licenseplate = 'ABC124' vehicle2.passengerqty = 5 vehicle2 = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.tripstatus_description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.trip_date = date_with_timezone trip.trip_amount = 1000 trip.trip_driver = savedUsr trip.trip_from = 'ORIGEN' trip.trip_to = 'DESTINO' trip.trip_passengerqty = 5 trip.trip_vehicle = vehicle trip.trip_tripstatus = tripStatus trip.Save() '''CREATE TRIP''' trip2 = Trip() trip2.trip_date = date_with_timezone trip2.trip_amount = 1000 trip2.trip_driver = savedUsr trip2.trip_from = 'ORIGEN' trip2.trip_to = 'DESTINO' trip2.trip_passengerqty = 5 trip2.trip_vehicle = vehicle2 trip2.trip_tripstatus = tripStatus with self.assertRaises(Exception) as context: trip2.Save() self.assertEqual('Driver is assigned to another trip', context.exception.args[0])
def test_passenger_has_no_enough_credits_to_pay_trip(self): usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr.Save() savedUsr = ServiceUser().RetrieveAll().first() usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.tripstatus_description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.trip_date = date_with_timezone trip.trip_amount = 400 trip.trip_driver = savedUsr trip.trip_from = 'ORIGEN' trip.trip_to = 'DESTINO' trip.trip_passengerqty = 5 trip.trip_vehicle = vehicle trip.trip_tripstatus = tripStatus savedTrip = trip.Save() usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 50 usr = usr.Save() with self.assertRaises(Exception) as context: savedTrip.AddPassengerToTrip(usr) self.assertEqual('Not enough credits to pay for this trip', context.exception.args[0])
def test_trip_has_no_available_space(self): usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr.Save() savedUsr = ServiceUser().RetrieveAll().first() usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.tripstatus_description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.trip_date = date_with_timezone trip.trip_amount = 200 trip.trip_driver = savedUsr trip.trip_from = 'ORIGEN' trip.trip_to = 'DESTINO' trip.trip_passengerqty = 5 trip.trip_vehicle = vehicle trip.trip_tripstatus = tripStatus savedTrip = trip.Save() usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr1 = usr.Save() usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr2 = usr.Save() usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr3 = usr.Save() usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr4 = usr.Save() usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr5 = usr.Save() usr = AppUser() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr6 = usr.Save() savedTrip.AddPassengerToTrip(usr1) savedTrip.AddPassengerToTrip(usr2) savedTrip.AddPassengerToTrip(usr3) savedTrip.AddPassengerToTrip(usr4) savedTrip.AddPassengerToTrip(usr5) with self.assertRaises(Exception) as context: savedTrip.AddPassengerToTrip(usr6) self.assertEqual('Max Occupancy reached', context.exception.args[0])
def test_create(self): usr = User() usr.username = '******' usr.password = '******' usr.credits = 400 usr.save() savedUsr = User.objects.get(id=1) usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.date = date_with_timezone trip.amount = 1000 trip.driver = savedUsr trip.fromPlace = 'ORIGEN' trip.toPlace = 'DESTINO' trip.passengerqty = 5 trip.vehicle = vehicle trip.status = tripStatus savedTrip = trip.Save() self.assertIsNotNone(savedTrip)
def test_qualification_has_a_future_date(self): usr1 = User() usr1.username = '******' usr1.password = '******' usr1.save() appuser1 = AppUser() appuser1.id = User.objects.get(id=1).id appuser1.credits = 1000 appuser1.save() savedUsr = User.objects.get(id=1) usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() + timedelta(days=1) settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.date = date_with_timezone trip.amount = 200 trip.driver = savedUsr trip.fromPlace = 'ORIGEN' trip.toPlace = 'DESTINO' trip.passengerqty = 5 trip.vehicle = vehicle trip.status = tripStatus savedTrip = trip.Save() usr = User() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' #usr.credits = 400 psngr = usr.save() appuser1 = AppUser() appuser1.id = User.objects.get(id=2).id appuser1.credits = 1000 appuser1.save() savedTrip = savedTrip.AddPassengerToTrip(User.objects.get(id=2)) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) qual = Qualification() qual.setQualificationDate(date_with_timezone) qual.setQualificationTrip(savedTrip) qual.setQualificationUser(savedUsr) qual.setQualificationGivenBy(User.objects.get(id=2)) qual.setQualificationValue(5) with self.assertRaises(Exception) as context: qual.Save() self.assertEqual('Incorrect Trip Date', context.exception.args[0])
def test_create(self): usr1 = User() usr1.username = '******' usr1.password = '******' usr1.save() appuser1 = AppUser() appuser1.id = User.objects.get(id=1).id appuser1.credits = 1000 appuser1.save() savedUsr = User.objects.get(id=1) usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.date = date_with_timezone trip.amount = 200 trip.driver = savedUsr trip.fromPlace = 'ORIGEN' trip.toPlace = 'DESTINO' trip.passengerqty = 5 trip.vehicle = vehicle trip.status = tripStatus savedTrip = trip.Save() usr1 = User() usr1.username = '******' usr1.password = '******' usr1.save() appuser2 = AppUser() appuser2.id = User.objects.get(id=2).id appuser2.credits = 1000 appuser2.save() savedTrip = savedTrip.AddPassengerToTrip(User.objects.get(id=2)) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) qual = Qualification() qual.setQualificationDate(date_with_timezone) qual.setQualificationTrip(savedTrip) qual.setQualificationUser(savedUsr) qual.setQualificationGivenBy(User.objects.get(id=2)) qual.setQualificationValue(5) savedQual = qual.Save() self.assertIsNotNone(savedQual)
def test_vehicle_has_another_active_trip(self): '''USUARIO 1''' usr1 = User() usr1.username = '******' usr1.password = '******' usr1.save() appuser1 = AppUser() appuser1.id = User.objects.get(id=1).id appuser1.credits = 1000 appuser1.save() '''USUARIO 2''' usr2 = User() usr2.username = '******' usr2.password = '******' usr2.save() appuser2 = AppUser() appuser2.id = User.objects.get(id=2).id appuser2.credits = 1000 appuser2.save() '''CREATE 1 VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set([usr1]) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP 1''' trip1 = Trip() trip1.date = date_with_timezone trip1.amount = 1000 trip1.driver = usr1 trip1.fromPlace = 'ORIGEN' trip1.toPlace = 'DESTINO' trip1.passengerqty = 5 trip1.vehicle = vehicle trip1.status = tripStatus trip1 = trip1.Save() '''CREATE TRIP 2''' trip2 = Trip() trip2.date = date_with_timezone trip2.amount = 1000 trip2.driver = usr2 trip2.fromPlace = 'ORIGEN' trip2.toPlace = 'DESTINO' trip2.passengerqty = 5 trip2.vehicle = vehicle trip2.status = tripStatus with self.assertRaises(Exception) as context: trip2 = trip2.Save() self.assertEqual('Vehicle is assigned to another trip', context.exception.args[0])
def test_driver_has_another_active_trip(self): usr1 = User() usr1.username = '******' usr1.password = '******' usr1.save() appuser1 = AppUser() appuser1.id = User.objects.get(id=1).id appuser1.credits = 1000 appuser1.save() savedUsr = User.objects.get(id=1) usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle2 = Vehicle() vehicle2.model = 'FORD FOCUS' vehicle2.licenseplate = 'ABC124' vehicle2.passengerqty = 5 vehicle2 = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.date = date_with_timezone trip.amount = 1000 trip.driver = savedUsr trip.fromPlace = 'ORIGEN' trip.toPlace = 'DESTINO' trip.passengerqty = 5 trip.vehicle = vehicle trip.status = tripStatus trip.Save() '''CREATE TRIP''' trip2 = Trip() trip2.date = date_with_timezone trip2.amount = 1000 trip2.driver = savedUsr trip2.fromPlace = 'ORIGEN' trip2.toPlace = 'DESTINO' trip2.passengerqty = 5 trip2.vehicle = vehicle2 trip2.status = tripStatus with self.assertRaises(Exception) as context: trip2.Save() self.assertEqual('Driver is assigned to another trip', context.exception.args[0])
def test_passenger_has_no_enough_credits_to_pay_trip(self): usr1 = User() usr1.username = '******' usr1.password = '******' usr1.save() appuser1 = AppUser() appuser1.id = User.objects.get(id=1).id appuser1.credits = 1000 appuser1.save() savedUsr = User.objects.get(id=1) usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.date = date_with_timezone trip.amount = 400 trip.driver = savedUsr trip.fromPlace = 'ORIGEN' trip.toPlace = 'DESTINO' trip.passengerqty = 5 trip.vehicle = vehicle trip.status = tripStatus savedTrip = trip.Save() usr2 = User() usr2.username = '******' usr2.password = '******' usr2.save() appuser2 = AppUser() appuser2.id = User.objects.get(id=2).id appuser2.credits = 100 appuser2.save() with self.assertRaises(Exception) as context: savedTrip.AddPassengerToTrip(usr2) self.assertEqual('Not enough credits to pay for this trip', context.exception.args[0])
def test_trip_has_no_available_space(self): usr = User() #usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr.save() savedUsr = User.objects.get(id=1) usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.date = date_with_timezone trip.amount = 200 trip.driver = savedUsr trip.fromPlace = 'ORIGEN' trip.toPlace = 'DESTINO' trip.passengerqty = 2 trip.vehicle = vehicle trip.status = tripStatus savedTrip = trip.Save() usr = User() #usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr1 = usr.save() appuser1 = AppUser() appuser1.id = User.objects.get(id=2).id appuser1.credits = 1000 appuser1.save() usr = User() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr2 = usr.save() appuser2 = AppUser() appuser2.id = User.objects.get(id=3).id appuser2.credits = 1000 appuser2.save() usr = User() #usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr.credits = 400 usr3 = usr.save() appuser3 = AppUser() appuser3.id = User.objects.get(id=4).id appuser3.credits = 1000 appuser3.save() savedTrip.AddPassengerToTrip(User.objects.get(id=2)) savedTrip.AddPassengerToTrip(User.objects.get(id=3)) with self.assertRaises(Exception) as context: savedTrip.AddPassengerToTrip(User.objects.get(id=4)) self.assertEqual('Max Occupancy reached', context.exception.args[0])
def test_trip_has_more_passengers_than_vehicle(self): usr = User() usr.username = '******' usr.password = '******' usr.credits = 400 usr.save() savedUsr = User.objects.get(id=1) usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.date = date_with_timezone trip.amount = 100 trip.driver = savedUsr trip.fromPlace = 'ORIGEN' trip.toPlace = 'DESTINO' trip.passengerqty = 6 trip.vehicle = vehicle trip.status = tripStatus with self.assertRaises(Exception) as context: trip.Save() self.assertEqual('Too many passengers for the selected vehicle', context.exception.args[0])
def test_validate_get_reputation_result(self): usr1 = AppUser() usr1.fullname = 'TEST NOMBRE COMPLETO' usr1.username = '******' usr1.password = '******' usr1.credits = 400 usr2 = AppUser() usr2.fullname = 'TEST NOMBRE COMPLETO' usr2.username = '******' usr2.password = '******' usr2.credits = 400 usr3 = AppUser() usr3.fullname = 'TEST NOMBRE COMPLETO' usr3.username = '******' usr3.password = '******' usr3.credits = 400 usr1 = usr1.Save() usr2 = usr2.Save() usr3 = usr3.Save() usrCol = [usr1] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.tripstatus_description = "ACTIVE" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.trip_date = date_with_timezone trip.trip_amount = 1000 trip.trip_driver = usr1 trip.trip_from = 'ORIGEN' trip.trip_to = 'DESTINO' trip.trip_passengerqty = 5 trip.trip_vehicle = vehicle trip.trip_tripstatus = tripStatus trip = trip.Save() tripStatus2 = TripStatus() tripStatus2.tripstatus_description = "CLOSED" tripStatus2 = tripStatus2.Save() trip = trip.CloseTrip() '''CREATE TRIP''' trip2 = Trip() trip2.trip_date = date_with_timezone trip2.trip_amount = 1000 trip2.trip_driver = usr1 trip2.trip_from = 'ORIGEN' trip2.trip_to = 'DESTINO' trip2.trip_passengerqty = 5 trip2.trip_vehicle = vehicle trip2.trip_tripstatus = tripStatus2 trip2 = trip2.Save() qual = Qualification() qual.qualification_date = date_with_timezone qual.qualification_givenby = usr2 qual.qualification_user = usr1 qual.qualification_trip = trip qual.qualification_value = 5 qual = qual.Save() qual = Qualification() qual.qualification_date = date_with_timezone qual.qualification_givenby = usr3 qual.qualification_user = usr1 qual.qualification_trip = trip2 qual.qualification_value = 4 qual = qual.Save() reputation = usr1.GetReputation() '''qualUser = ServiceUser.GetReputationByUser(self, savedUsr)''' self.assertEqual(reputation, Decimal('4.5'))
def test_qualification_is_given_by_same_user(self): usr1 = User() usr1.username = '******' usr1.password = '******' usr1.save() appuser1 = AppUser() appuser1.id = User.objects.get(id=1).id appuser1.credits = 1000 appuser1.save() savedUsr = User.objects.get(id=1) usrCol = [savedUsr] '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() + timedelta(days=1) settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.description = "ACTIVO" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.date = date_with_timezone trip.amount = 200 trip.driver = savedUsr trip.fromPlace = 'ORIGEN' trip.toPlace = 'DESTINO' trip.passengerqty = 5 trip.vehicle = vehicle trip.status = tripStatus savedTrip = trip.Save() usr2 = User() usr2.username = '******' usr2.password = '******' usr2.save() appuser2 = AppUser() appuser2.id = User.objects.get(id=2).id appuser2.credits = 1000 appuser2.save() savedUsr = User.objects.get(id=2) usrCol = [savedUsr] savedTrip = savedTrip.AddPassengerToTrip(User.objects.get(id=2)) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) qual = Qualification() qual.setQualificationDate(date_with_timezone) qual.setQualificationTrip(savedTrip) qual.setQualificationUser(savedUsr) qual.setQualificationGivenBy(savedUsr) qual.setQualificationValue(5) with self.assertRaises(Exception) as context: qual.Save() self.assertEqual('User giving and receiving feedback is the same', context.exception.args[0])
def test_get_reputation(self): usr = User() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr = usr.save() savedUsr = User.objects.get(id=1) usrCol = [savedUsr] usr1 = AppUser() usr1.id = savedUsr.id usr1.credits = 2000 usr1.save() usr = User() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr = usr.save() savedUsr = User.objects.get(id=2) usr2 = AppUser() usr2.id = savedUsr.id usr2.credits = 2000 usr2.save() usr = User() usr.fullname = 'TEST NOMBRE COMPLETO' usr.username = '******' usr.password = '******' usr = usr.save() savedUsr = User.objects.get(id=3) usr3 = AppUser() usr3.id = savedUsr.id usr3.credits = 2000 usr3.save() '''CREATE VEHICLE''' vehicle = Vehicle() vehicle.model = 'FORD FOCUS' vehicle.licenseplate = 'ABC123' vehicle.passengerqty = 5 vehicle = vehicle.Save() vehicle.drivers.set(usrCol) date = datetime.datetime.now() settings.TIME_ZONE # 'UTC' date_with_timezone = make_aware(date) '''CREATE TRIP STATUS''' tripStatus = TripStatus() tripStatus.description = "ACTIVE" tripStatus = tripStatus.Save() '''CREATE TRIP''' trip = Trip() trip.date = date_with_timezone trip.amount = 1000 trip.driver = User.objects.get(id=1) trip.fromPlace = 'ORIGEN' trip.toPlace = 'DESTINO' trip.passengerqty = 5 trip.vehicle = vehicle trip.status = tripStatus trip = trip.Save() trip.AddPassengerToTrip(User.objects.get(id=2)) trip.AddPassengerToTrip(User.objects.get(id=3)) tripStatus = TripStatus() tripStatus.description = "CLOSED" tripStatus = tripStatus.Save() trip.CloseTrip() qual = Qualification() qual.date = date_with_timezone qual.givenby = User.objects.get(id=2) qual.user = User.objects.get(id=1) qual.trip = trip qual.givenvalue = 5 qual = qual.save() qual = Qualification() qual.date = date_with_timezone qual.givenby = User.objects.get(id=3) qual.user = User.objects.get(id=1) qual.trip = trip qual.givenvalue = 4 qual = qual.save() reputation = AppUser.objects.get(id=1).GetReputation() '''qualUser = ServiceUser.GetReputationByUser(self, savedUsr)''' self.assertEqual(reputation, Decimal('4.5'))