37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from django.test import TestCase
|
|
|
|
from .models import Wishlist, Wish, WishPart
|
|
|
|
|
|
class TestWishModel(TestCase):
|
|
def test_percentage_of_completion(self):
|
|
"""
|
|
Vérifie que le pourcentage de complétion d'un souhait
|
|
est correctement calculé.
|
|
"""
|
|
wishlist = Wishlist(name='Fake WishList',
|
|
description='This is a faked wishlist')
|
|
wishlist.save()
|
|
|
|
wish = Wish(wishlist=wishlist,
|
|
name='Fake Wish',
|
|
description='This is a faked wish',
|
|
number_of_parts=4)
|
|
wish.save()
|
|
|
|
part1 = WishPart(wish=wish, comment='part1')
|
|
part1.save()
|
|
self.assertEqual(25, wish.percentage_of_completion)
|
|
|
|
part2 = WishPart(wish=wish, comment='part2')
|
|
part2.save()
|
|
self.assertEqual(50, wish.percentage_of_completion)
|
|
|
|
part3 = WishPart(wish=wish, comment='part3')
|
|
part3.save()
|
|
self.assertEqual(75, wish.percentage_of_completion)
|
|
|
|
part4 = WishPart(wish=wish, comment='part4')
|
|
part4.save()
|
|
self.assertEqual(100, wish.percentage_of_completion)
|