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()
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 get_queryset(self, request): qs = super().get_queryset(request) if request.user.is_superuser: return qs return qs.filter(Item.filter_by_user(request.user)).distinct()
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()
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()
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()
def test_str(self): item = Item(name='My item') self.assertEqual(item.__str__(), 'My item')