Beispiel #1
0
    def test_were_drivers_added_successfully_to_vehicle(self):

        vehicle = Vehicle()
        vehicle.model = 'FORD FOCUS'
        vehicle.licenseplate = 'ABC123'
        vehicle.passengerqty = 5
        
        vehicle = vehicle.Save()
        
        savedVehicle = ServiceVehicle().RetrieveById(vehicle.id)
        
        usr = AppUser()
        usr.fullname = 'TEST NOMBRE COMPLETO1'
        usr.username = '******'
        usr.password = '******'
        usr.credits = 400
         
        usr = usr.Save()
        savedUsr1 = ServiceUser().RetrieveById(usr.id)

        usr = AppUser()
        usr.fullname = 'TEST NOMBRE COMPLETO2'
        usr.username = '******'
        usr.password = '******'
        usr.credits = 400
         
        usr = usr.Save()
        savedUsr2 = ServiceUser().RetrieveById(usr.id)
         
        usrCol = [savedUsr1, savedUsr2]

        savedVehicle.AddDriversToVehicle(usrCol)

        self.assertEqual(vehicle.drivers.count(), 2)  
Beispiel #2
0
    def test_add_driver_to_vehicle(self):

        vehicle = Vehicle()
        vehicle.model = 'FORD FOCUS'
        vehicle.licenseplate = 'ABC123'
        vehicle.passengerqty = 5

        vehicle = vehicle.Save()

        savedVehicle = Vehicle.objects.get(id=1)

        usr = User()
        usr.fullname = 'TEST NOMBRE COMPLETO1'
        usr.username = '******'
        usr.password = '******'
        #usr.credits = 400

        usr = usr.save()
        savedUsr1 = User.objects.get(id=1)

        usrCol = [savedUsr1]

        savedVehicle.AddDriversToVehicle(usrCol)

        self.assertEqual(vehicle.drivers.count(), 1)
Beispiel #3
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]) 
Beispiel #4
0
    def test_was_created_successfully(self):

        vehicle = Vehicle()
        vehicle.model = 'FORD FOCUS'
        vehicle.licenseplate = 'ABC123'
        vehicle.passengerqty = 5
        
        vehicle = vehicle.Save()
        
        savedVehicle = ServiceVehicle().RetrieveById(vehicle.id)

        self.assertIsNotNone(savedVehicle)
Beispiel #5
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)
Beispiel #6
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 newvehicle(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 = NewVehicleForm(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()
            vehicle.model = form.cleaned_data['model']
            vehicle.licenseplate = form.cleaned_data['licenseplate']
            vehicle.passengerqty = form.cleaned_data['passengerqty']

            vehicle.Save()
            vehicle.addDriver(User.objects.get(id=user_id))
            # 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 = NewVehicleForm()

    return render(request, 'newvehicle.html', {'form': form})
Beispiel #8
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])
Beispiel #9
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)
Beispiel #10
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'))
Beispiel #11
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'))
Beispiel #12
0
    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])                       
Beispiel #13
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]) 
Beispiel #14
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]) 
Beispiel #15
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])
Beispiel #16
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])
Beispiel #17
0
    def test_create_two_vehicles_with_same_licenseplate(self):
        
        vehicle = Vehicle()
        vehicle.model = 'FORD FOCUS'
        vehicle.licenseplate = 'ABC123'
        vehicle.passengerqty = 5
        
        vehicle = vehicle.Save()
        
        vehicle2 = Vehicle()
        vehicle2.model = 'FORD FOCUS'
        vehicle2.licenseplate = 'ABC123'
        vehicle2.passengerqty = 5
         
        with self.assertRaises(Exception) as context:
            vehicle2 = vehicle2.Save()

        self.assertEqual('UNIQUE constraint failed: ViajeroFrecuente_vehicle.licenseplate', context.exception.args[0]) 
Beispiel #18
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])
Beispiel #19
0
    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])
Beispiel #20
0
    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])
Beispiel #21
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)
Beispiel #22
0
    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])