示例#1
0
 def test_clean__different_depots(self):
     itemRental = ItemRental(rental=Rental(depot=self.depotA,
                                           user=self.user_member),
                             item=Item(quantity=42, depot=self.depotB),
                             quantity=12)
     with self.assertRaises(ValidationError):
         itemRental.clean()
示例#2
0
 def test_clean__greater_amount(self):
     itemRental = ItemRental(rental=Rental(depot=self.depotA,
                                           user=self.user_member),
                             item=Item(quantity=42),
                             quantity=56)
     with self.assertRaises(ValidationError):
         itemRental.clean()
 def create_rental(self, user, data):
     keys = ('firstname', 'lastname', 'depot_id', 'email', 'purpose',
             'start_date', 'return_date')
     rental = Rental(user=user, **{key: data.get(key) for key in keys})
     rental.full_clean()
     rental.save()
     # Refresh Rental object to fix issue with depot_id
     rental.refresh_from_db()
     return rental
示例#4
0
 def test_clean__not_public_member(self):
     itemRental = ItemRental(rental=Rental(depot=self.depotA,
                                           user=self.user_member),
                             item=Item(visibility=Item.VISIBILITY_INTERNAL,
                                       quantity=42,
                                       depot=self.depotA),
                             quantity=12)
     itemRental.clean()
示例#5
0
 def test_clean__valid_data(self):
     itemRental = ItemRental(rental=Rental(depot=self.depotA,
                                           user=self.user_member),
                             item=Item(visibility=Item.VISIBILITY_PUBLIC,
                                       quantity=42,
                                       depot=self.depotA),
                             quantity=12)
     itemRental.clean()
示例#6
0
 def test_clean__not_public_not_member(self):
     itemRental = ItemRental(rental=Rental(depot=self.depotA,
                                           user=self.user_not_member),
                             item=Item(visibility=Item.VISIBILITY_INTERNAL,
                                       quantity=42,
                                       depot=self.depotA),
                             quantity=12)
     with self.assertRaises(ValidationError):
         itemRental.clean()
示例#7
0
 def create_rental(self,
                   start_delta,
                   return_delta,
                   active=True,
                   state=Rental.STATE_PENDING):
     return Rental(depot=Depot(active=active),
                   start_date=datetime.now() + timedelta(days=start_delta),
                   return_date=datetime.now() +
                   timedelta(days=return_delta),
                   state=state)
示例#8
0
    def setUp(self):
        self.day = date.today()
        self.current_month = self.day.month
        self.current_year = self.day.year
        self.user1 = User(username='******',
                          email='jacob@…',
                          password='******')
        self.user2 = User(username='******',
                          email='anto@…',
                          password='******')
        self.user3 = User(username='******',
                          email='roro@…',
                          password='******')
        User.objects.bulk_create([self.user1, self.user2, self.user3])

        self.admin = Administrator.objects.create(
            user=self.user3, address='13 rue de soulino, 75019 Paris')

        self.property_test = Property.objects.create(
            name='Propriété Renaud',
            address='16 rue de pikouli, 75019 Paris',
            number_of_bedroom=3,
            superficy=80,
            administrator=self.admin,
        )

        self.bedroom1 = Bedroom(
            name='Chambre 1',
            occupency=True,
            superficy=10,
            property=self.property_test,
        )
        self.bedroom2 = Bedroom(
            name='Chambre 2',
            occupency=True,
            superficy=10,
            property=self.property_test,
        )
        Bedroom.objects.bulk_create([self.bedroom1, self.bedroom2])

        self.occupant1 = Occupant(
            user=self.user1,
            is_active=True,
            date_of_entry=self.day,
            date_of_leaving=self.day,
            last_update=self.day,
            creation_date=self.day,
            deposit=300,
            suivi='blabla',
        )
        self.occupant2 = Occupant(
            user=self.user2,
            is_active=True,
            date_of_entry=self.day,
            date_of_leaving=self.day,
            last_update=self.day,
            creation_date=self.day,
            deposit=300,
            suivi='blablatest',
        )
        Occupant.objects.bulk_create([self.occupant1, self.occupant2])

        self.rental1 = Rental(
            occupant=self.occupant1,
            bedroom=self.bedroom1,
            rent_amount=230,
            charges=0,
            property=self.property_test,
            archived=False,
        )
        self.rental2 = Rental(
            occupant=self.occupant2,
            bedroom=self.bedroom2,
            rent_amount=230,
            charges=0,
            property=self.property_test,
            archived=False,
        )
        Rental.objects.bulk_create([self.rental1, self.rental2])

        self.record1 = Echeance(echeance='{}-{}.pdf'.format(
            self.day, self.user1),
                                monthly_rent_paid=False,
                                date_of_issue=self.day,
                                rental=self.rental1)
        self.record2 = Echeance(echeance='{}-{}.pdf'.format(
            self.day, self.user2),
                                monthly_rent_paid=True,
                                date_of_issue=self.day,
                                rental=self.rental2)
        Echeance.objects.bulk_create([
            self.record1,
            self.record2,
        ])
示例#9
0
 def test_str(self):
     rental = Rental(firstname='Fitness', lastname='Flow')
     self.assertEqual(rental.__str__(), 'Rental by Fitness Flow')