tests.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from datetime import datetime, timedelta, date
  2. from django.test import TestCase
  3. from django.utils import timezone
  4. from coin.members.models import Member
  5. from .models import Item, ItemType, Loan
  6. def localize(naive_dt):
  7. if not timezone.is_naive(naive_dt):
  8. raise ValueError('Expecting a naive datetime')
  9. else:
  10. return timezone.make_aware(naive_dt, timezone.get_current_timezone())
  11. class HardwareLoaningTestCase(TestCase):
  12. def setUp(self):
  13. self.member = Member.objects.create(
  14. first_name='John',
  15. last_name='Doe',
  16. username='jdoe')
  17. self.item_type = ItemType.objects.create(name='Foos')
  18. self.item = Item.objects.create(
  19. type=self.item_type,
  20. designation='Bar Wheel',
  21. buy_date=date(2012,12,5))
  22. def test_running_(self):
  23. loan_start_date = localize(datetime(2011,1,14,12,0,0))
  24. loan = Loan.objects.create(
  25. item=self.item, user=self.member,
  26. loan_date=loan_start_date)
  27. self.assertEqual(Loan.objects.running().count(), 1)
  28. self.assertEqual(Loan.objects.finished().count(), 0)
  29. loan.item.give_back()
  30. self.assertEqual(Loan.objects.running().count(), 0)
  31. self.assertEqual(Loan.objects.finished().count(), 1)