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_more_passengers_than_vehicle(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 = 1000 trip.trip_driver = savedUsr trip.trip_from = 'ORIGEN' trip.trip_to = 'DESTINO' trip.trip_passengerqty = 6 trip.trip_vehicle = vehicle trip.trip_tripstatus = tripStatus with self.assertRaises(Exception) as context: trip.Save() self.assertEqual('Too many passengers for the selected vehicle', 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 = 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 savedTrip = trip.Save() self.assertIsNotNone(savedTrip)
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): 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_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_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])